slack-message-api-local 0.0.3b4912__tar.gz

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.
@@ -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,38 @@
1
+ # General
2
+
3
+ Unlike the README.md in the root directory, this is a README.md of this specific repo/package<br>
4
+
5
+ TODO Please update this README.md of this specific repo/package and not the README.md in the root directory based on the python-package-template repo<br>
6
+
7
+ ## TODOs
8
+
9
+ TODO: If the content was generated using AI, update Slack with "is_ai_informed": "true"<br>
10
+
11
+ ## Direct messages
12
+
13
+ Python callers can use `SlackMessageApiClient` (the same `send_direct_message` as `InstagramMessageApiClient` of
14
+ instagram-message-api-local):
15
+
16
+ ```python
17
+ from slack_message_api_local.src.slack_message_api_client import SlackMessageApiClient
18
+
19
+ slack_message_api_client = SlackMessageApiClient()
20
+ message_ts = slack_message_api_client.send_direct_message(recipient_id="U012AB3CD", text="Hello")
21
+ slack_message_api_client.reply_in_thread(channel_id="C012AB3CD", thread_ts=message_ts, text="A reply")
22
+ ```
23
+
24
+ It sends through slack-remote, which reads the bot token from `SLACK_BOT_TOKEN`.
25
+
26
+ ## Versions
27
+
28
+ [pub] 0.0.1 Initial version (change the directories, files, setup.py, .github/workflows/*.yml)<br>
29
+
30
+ ## Installing instructions
31
+
32
+ It's advised to use venv<br>
33
+ If you have Windows, it's also advised to use Windows Subsystem for Linux<br>
34
+
35
+ ## Install dependencies
36
+
37
+ Run ./download-beta-sdk.sh from the bash terminal<br>
38
+ Run pip install -r requirements.txt from the bash terminal<br>
@@ -0,0 +1,30 @@
1
+ # This file should be in the future instead of setup.py
2
+ # https://python-poetry.org/docs/pyproject
3
+ # https://stackoverflow.com/questions/78048223/adding-folder-with-data-with-pyproject-toml
4
+ # https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license
5
+
6
+ # This file is mandatory for the `poetry version patch`
7
+
8
+ # It seems we need to copy this file also to serverless-com repo, as required by dialog-workflow-python-package
9
+
10
+ [build-system]
11
+ requires = ["setuptools>=61.0"]
12
+ build-backend = "setuptools.build_meta"
13
+
14
+ [tool.pytest.ini_options]
15
+ pythonpath = ["."]
16
+
17
+ [tool.poetry]
18
+ # TODO: Please update the name, similar to storage-local (suffix -local)
19
+ name = "<project-name>"
20
+ # I believe we are still using the version from setup.py and not from here until Potery will work
21
+ version = "0.0.3b4912" # https://pypi.org/project/<project-name> i.e. https://pypi.org/project/storage-local/
22
+ description = "<project-name> Python Package"
23
+ readme = "README.md"
24
+ authors = [
25
+ "Circlez.ai <info@circlez.ai>",
26
+ ]
27
+
28
+ [tool.poetry.dev-dependencies]
29
+ pytest = "^8.0"
30
+ pytest-cov = "^5.0"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,75 @@
1
+ # serverless.com repo "python -m build" works without setup.py
2
+ # Should update package_dir if not using our recommended directory structure
3
+
4
+ import setuptools
5
+
6
+ # TODO: Change the PACKAGE_NAME to the package's name - Either xxx-local or
7
+ # xxx-remote (without the -python-package suffix). Only lowercase, no
8
+ # underlines.
9
+ # Used by pypa/gh-action-pypi-publish
10
+ # Package Name should be identical to the inner directory name
11
+ # Changing the package name here, will cause a change in the package directory
12
+ # name as well
13
+ # PACKAGE_NAME should be singular if handling only one instance
14
+ # PACKAGE_NAME should not include the word "main"
15
+
16
+ # e.g.: queue-local, without python-package suffix
17
+ PACKAGE_NAME = "slack-message-api-local"
18
+
19
+ package_dir = PACKAGE_NAME.replace("-", "_")
20
+ # If we need backward-compatible:
21
+ # old_package_dir = "old_package_name"
22
+
23
+ PACKAGE_DESCRIPTION = f"PyPI {PACKAGE_NAME} Python Package owned by Circlez.ai"
24
+
25
+ setuptools.setup(
26
+ license='MIT',
27
+ name=PACKAGE_NAME,
28
+ # Increase this number every time you make a change you
29
+ # want to publish. After 0.0.9 switch to 0.0.10 and not 0.1.0
30
+ # version can't be 0.0.
31
+ # If you find yourself increasing the version in more than one patch number (it might indicate there are multiple branches which you should submit their PRs before your PR) # noqa: E501
32
+ # TODO add the Jira Work Item (Jira Issue) number after the version i.e., 0.0.1b2432
33
+ version="0.0.3b4912", # https://pypi.org/project/slack-message-api-local/
34
+ author="Circles",
35
+ author_email="info@circlez.ai",
36
+ description=f"{PACKAGE_DESCRIPTION}",
37
+ # long_description=f"{description}",
38
+ long_description=f"{PACKAGE_DESCRIPTION}\n"
39
+ "JIRA Work Item: https://circles-zone.atlassian.net/browse/BU-4912\n"
40
+ "GHA: https://github.com/circles-zone/slack-message-api-local-python-package/actions",
41
+
42
+ long_description_content_type='text/markdown',
43
+ url=f"https://github.com/circles-zone/{PACKAGE_NAME}-python-package",
44
+ # packages=[package_dir],
45
+ # packages=[package_dir, old_package_dir],
46
+ packages=setuptools.find_packages(),
47
+
48
+ # I'm not sure we need package_dir
49
+ # package_dir={package_dir: f'{package_dir}/src'},
50
+ # TODO Unfortunately in event-main-local-restapi there are no
51
+ # repo-directory and no package directory (flat directory structure)
52
+ # package_dir={package_dir: f'src'},
53
+
54
+ # package_dir={package_dir: f'{package_dir}/src',
55
+ # old_package_dir: f'{package_dir}/src'},
56
+ package_data={package_dir: ['*.py']},
57
+ classifiers=[
58
+ "Programming Language :: Python :: 3",
59
+ # https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license
60
+ # TODO Fix all repos, especially the Python templates
61
+ #
62
+ "Operating System :: OS Independent",
63
+ ],
64
+ # Do not add packages needed only for tests i.e. packages for get_test_xxx(
65
+ # TODO: Update which packages to include with this package in production
66
+ # (dependencies) - Not for development/testing
67
+ install_requires=[
68
+ 'python-sdk-remote',
69
+ # TODO: In -local package please uncomment the bellow line. In -remote packages please delete this line. # noqa E501
70
+ # 'smart-datastore-local',
71
+ # 'logzio-python-handler>=4.1.2', # https://pypi.org/project/logzio-python-handler/
72
+ 'slack-remote>=0.0.3',
73
+ ]
74
+ )
75
+
@@ -0,0 +1,3 @@
1
+ from .slack_message_api_client import SlackMessageApiClient
2
+
3
+ __all__ = ["SlackMessageApiClient"]
@@ -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"
@@ -0,0 +1,5 @@
1
+ """Shared test configuration.
2
+
3
+ The API client tests are intentionally offline and need no database.
4
+ Database integration tests should opt in to their own fixture explicitly.
5
+ """
@@ -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,16 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ slack_message_api_local/__init__.py
5
+ slack_message_api_local.egg-info/PKG-INFO
6
+ slack_message_api_local.egg-info/SOURCES.txt
7
+ slack_message_api_local.egg-info/dependency_links.txt
8
+ slack_message_api_local.egg-info/requires.txt
9
+ slack_message_api_local.egg-info/top_level.txt
10
+ slack_message_api_local/src/__init__.py
11
+ slack_message_api_local/src/slack_message_api_client.py
12
+ slack_message_api_local/src/version.py
13
+ slack_message_api_local/tests/__init__.py
14
+ slack_message_api_local/tests/conftest.py
15
+ slack_message_api_local/tests/unit/__init__.py
16
+ slack_message_api_local/tests/unit/slack_message_api_client_unit_test.py
@@ -0,0 +1,2 @@
1
+ python-sdk-remote
2
+ slack-remote>=0.0.3