slack-message-api-local 0.0.3b4912__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- slack_message_api_local/__init__.py +0 -0
- slack_message_api_local/src/__init__.py +3 -0
- slack_message_api_local/src/slack_message_api_client.py +40 -0
- slack_message_api_local/src/version.py +1 -0
- slack_message_api_local/tests/__init__.py +0 -0
- slack_message_api_local/tests/conftest.py +5 -0
- slack_message_api_local/tests/unit/__init__.py +0 -0
- slack_message_api_local/tests/unit/slack_message_api_client_unit_test.py +99 -0
- slack_message_api_local-0.0.3b4912.dist-info/METADATA +26 -0
- slack_message_api_local-0.0.3b4912.dist-info/RECORD +12 -0
- slack_message_api_local-0.0.3b4912.dist-info/WHEEL +5 -0
- slack_message_api_local-0.0.3b4912.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Slack messages through slack-remote, with the interface of instagram-message-api-local's InstagramMessageApiClient
|
|
2
|
+
(send_direct_message), so a caller can send through either one."""
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
from slack_remote.src.slack_remote import SlackRemote
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SlackMessageApiClient:
|
|
9
|
+
def __init__(self, slack_remote: Optional[SlackRemote] = None) -> None:
|
|
10
|
+
"""Without slack_remote, SlackRemote reads the bot token from SLACK_BOT_TOKEN."""
|
|
11
|
+
self.slack_remote = slack_remote or SlackRemote()
|
|
12
|
+
|
|
13
|
+
def send_direct_message(self, *, recipient_id: str, text: str) -> Optional[str]:
|
|
14
|
+
"""recipient_id is a Slack user id (a direct message) or a channel id; returns the ts of the message."""
|
|
15
|
+
if not recipient_id:
|
|
16
|
+
raise ValueError("recipient_id is required")
|
|
17
|
+
if not text:
|
|
18
|
+
raise ValueError("text is required")
|
|
19
|
+
response_json = self.slack_remote.post_message(recipient_id, text)
|
|
20
|
+
message_ts: Optional[str] = response_json.get("ts")
|
|
21
|
+
return message_ts
|
|
22
|
+
|
|
23
|
+
def send_direct_message_to_email(self, *, email: str, text: str) -> Optional[str]:
|
|
24
|
+
user_id = self.slack_remote.get_user_id(email)
|
|
25
|
+
message_ts = self.send_direct_message(recipient_id=user_id, text=text)
|
|
26
|
+
return message_ts
|
|
27
|
+
|
|
28
|
+
def reply_in_thread(self, *, channel_id: str, thread_ts: str, text: str) -> Optional[str]:
|
|
29
|
+
if not thread_ts:
|
|
30
|
+
raise ValueError("thread_ts is required")
|
|
31
|
+
if not channel_id or not text:
|
|
32
|
+
raise ValueError("channel_id and text are required")
|
|
33
|
+
response_json = self.slack_remote.post_message(channel_id, text, thread_ts=thread_ts)
|
|
34
|
+
message_ts: Optional[str] = response_json.get("ts")
|
|
35
|
+
return message_ts
|
|
36
|
+
|
|
37
|
+
def get_thread_replies(self, *, channel_id: str, thread_ts: str) -> list[dict[str, Any]]:
|
|
38
|
+
"""Only the replies, without the message that started the thread."""
|
|
39
|
+
thread_replies = self.slack_remote.get_thread_replies(channel_id, thread_ts)
|
|
40
|
+
return thread_replies
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PACKAGE_VERSION = "0.0.0"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from slack_message_api_local.src.slack_message_api_client import SlackMessageApiClient
|
|
6
|
+
|
|
7
|
+
CHANNEL_ID = "C-REQUESTS"
|
|
8
|
+
USER_ID = "U-TAL"
|
|
9
|
+
EMAIL = "tal@circlez.ai"
|
|
10
|
+
MESSAGE_TS = "1795515694.662549"
|
|
11
|
+
TEXT = "Merged"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FakeSlackRemote:
|
|
15
|
+
"""The slack-remote calls of the client; posted keeps every chat.postMessage."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, thread_replies: Optional[list[dict[str, Any]]] = None) -> None:
|
|
18
|
+
self.posted: list[dict[str, Any]] = []
|
|
19
|
+
self._thread_replies = thread_replies or []
|
|
20
|
+
|
|
21
|
+
def post_message(self, channel: str, text: str, thread_ts: Optional[str] = None) -> dict[str, Any]:
|
|
22
|
+
self.posted.append({"channel": channel, "text": text, "thread_ts": thread_ts})
|
|
23
|
+
response_json = {"ok": True, "channel": channel, "ts": MESSAGE_TS}
|
|
24
|
+
return response_json
|
|
25
|
+
|
|
26
|
+
def get_user_id(self, email: str) -> str:
|
|
27
|
+
user_id = USER_ID if email == EMAIL else ""
|
|
28
|
+
return user_id
|
|
29
|
+
|
|
30
|
+
def get_thread_replies(self, channel: str, thread_ts: str) -> list[dict[str, Any]]:
|
|
31
|
+
thread_replies = self._thread_replies if (channel, thread_ts) == (CHANNEL_ID, MESSAGE_TS) else []
|
|
32
|
+
return thread_replies
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def create_client(fake_slack_remote: FakeSlackRemote) -> SlackMessageApiClient:
|
|
36
|
+
slack_message_api_client = SlackMessageApiClient(slack_remote=fake_slack_remote) # type: ignore[arg-type]
|
|
37
|
+
return slack_message_api_client
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_send_direct_message_posts_to_the_recipient_and_returns_the_message_ts():
|
|
41
|
+
fake_slack_remote = FakeSlackRemote()
|
|
42
|
+
|
|
43
|
+
message_ts = create_client(fake_slack_remote).send_direct_message(recipient_id=USER_ID, text=TEXT)
|
|
44
|
+
|
|
45
|
+
assert message_ts == MESSAGE_TS
|
|
46
|
+
assert fake_slack_remote.posted == [{"channel": USER_ID, "text": TEXT, "thread_ts": None}]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@pytest.mark.parametrize("recipient_id, text", [("", TEXT), (USER_ID, "")])
|
|
50
|
+
def test_send_direct_message_needs_a_recipient_and_a_text(recipient_id, text):
|
|
51
|
+
fake_slack_remote = FakeSlackRemote()
|
|
52
|
+
|
|
53
|
+
with pytest.raises(ValueError):
|
|
54
|
+
create_client(fake_slack_remote).send_direct_message(recipient_id=recipient_id, text=text)
|
|
55
|
+
|
|
56
|
+
assert fake_slack_remote.posted == []
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_send_direct_message_to_email_finds_the_slack_user():
|
|
60
|
+
fake_slack_remote = FakeSlackRemote()
|
|
61
|
+
|
|
62
|
+
message_ts = create_client(fake_slack_remote).send_direct_message_to_email(email=EMAIL, text=TEXT)
|
|
63
|
+
|
|
64
|
+
assert message_ts == MESSAGE_TS
|
|
65
|
+
assert fake_slack_remote.posted == [{"channel": USER_ID, "text": TEXT, "thread_ts": None}]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_reply_in_thread_posts_under_the_thread():
|
|
69
|
+
fake_slack_remote = FakeSlackRemote()
|
|
70
|
+
|
|
71
|
+
message_ts = create_client(fake_slack_remote).reply_in_thread(channel_id=CHANNEL_ID, thread_ts=MESSAGE_TS,
|
|
72
|
+
text=TEXT)
|
|
73
|
+
|
|
74
|
+
assert message_ts == MESSAGE_TS
|
|
75
|
+
assert fake_slack_remote.posted == [{"channel": CHANNEL_ID, "text": TEXT, "thread_ts": MESSAGE_TS}]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@pytest.mark.parametrize("channel_id, thread_ts, text", [(CHANNEL_ID, "", TEXT), ("", MESSAGE_TS, TEXT),
|
|
79
|
+
(CHANNEL_ID, MESSAGE_TS, "")])
|
|
80
|
+
def test_reply_in_thread_needs_a_channel_a_thread_and_a_text(channel_id, thread_ts, text):
|
|
81
|
+
with pytest.raises(ValueError):
|
|
82
|
+
create_client(FakeSlackRemote()).reply_in_thread(channel_id=channel_id, thread_ts=thread_ts, text=text)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_get_thread_replies_returns_the_replies_of_the_thread():
|
|
86
|
+
thread_replies = [{"ts": "2.2", "text": TEXT}]
|
|
87
|
+
|
|
88
|
+
replies = create_client(FakeSlackRemote(thread_replies)).get_thread_replies(channel_id=CHANNEL_ID,
|
|
89
|
+
thread_ts=MESSAGE_TS)
|
|
90
|
+
|
|
91
|
+
assert replies == thread_replies
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_the_default_slack_remote_reads_the_bot_token(monkeypatch):
|
|
95
|
+
monkeypatch.setenv("SLACK_BOT_TOKEN", "xoxb-test")
|
|
96
|
+
|
|
97
|
+
slack_message_api_client = SlackMessageApiClient()
|
|
98
|
+
|
|
99
|
+
assert slack_message_api_client.slack_remote.bot_token == "xoxb-test"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slack-message-api-local
|
|
3
|
+
Version: 0.0.3b4912
|
|
4
|
+
Summary: PyPI slack-message-api-local Python Package owned by Circlez.ai
|
|
5
|
+
Home-page: https://github.com/circles-zone/slack-message-api-local-python-package
|
|
6
|
+
Author: Circles
|
|
7
|
+
Author-email: info@circlez.ai
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: python-sdk-remote
|
|
13
|
+
Requires-Dist: slack-remote>=0.0.3
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: license
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
PyPI slack-message-api-local Python Package owned by Circlez.ai
|
|
25
|
+
JIRA Work Item: https://circles-zone.atlassian.net/browse/BU-4912
|
|
26
|
+
GHA: https://github.com/circles-zone/slack-message-api-local-python-package/actions
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
slack_message_api_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
slack_message_api_local/src/__init__.py,sha256=4BJSEX2Dt3OIzfHTbxmtlmN9LqysoBVpz7BVDD9ROHA,97
|
|
3
|
+
slack_message_api_local/src/slack_message_api_client.py,sha256=f_AM7pGdG7rkvxH-qoXccRxUd-ybhTXWuCj6kejBIS0,2039
|
|
4
|
+
slack_message_api_local/src/version.py,sha256=jYksq9tCM_NF91tQsU1-nxs4ZKEhsRoxKQFHNGc4Te8,26
|
|
5
|
+
slack_message_api_local/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
slack_message_api_local/tests/conftest.py,sha256=GSrW0p0v5F1QVWA88uJ7L1hVsQMUcsFtXh97vDzJFqc,178
|
|
7
|
+
slack_message_api_local/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
slack_message_api_local/tests/unit/slack_message_api_client_unit_test.py,sha256=-F2PTBiJZ-p0knq3zgUiuMGlqap0y_caAVot6sHaWyg,3982
|
|
9
|
+
slack_message_api_local-0.0.3b4912.dist-info/METADATA,sha256=gQ6mFKOl_idgUivPlUZxuwDubhQtEMeZEhM25ekO8NA,893
|
|
10
|
+
slack_message_api_local-0.0.3b4912.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
11
|
+
slack_message_api_local-0.0.3b4912.dist-info/top_level.txt,sha256=3WAiDf8q87tcrzfTmrzAySKaFQtUnO9HZlXf8kOnVwk,24
|
|
12
|
+
slack_message_api_local-0.0.3b4912.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
slack_message_api_local
|