csp-adapter-slack 0.1.0__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.
@@ -0,0 +1,3 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from .adapter import *
@@ -0,0 +1,357 @@
1
+ import threading
2
+ from logging import getLogger
3
+ from queue import Queue
4
+ from ssl import SSLContext
5
+ from threading import Thread
6
+ from time import sleep
7
+ from typing import Dict, List, Optional, TypeVar
8
+
9
+ import csp
10
+ from csp.impl.adaptermanager import AdapterManagerImpl
11
+ from csp.impl.outputadapter import OutputAdapter
12
+ from csp.impl.pushadapter import PushInputAdapter
13
+ from csp.impl.struct import Struct
14
+ from csp.impl.types.tstype import ts
15
+ from csp.impl.wiring import py_output_adapter_def, py_push_adapter_def
16
+
17
+ from slack_sdk.errors import SlackApiError
18
+ from slack_sdk.socket_mode import SocketModeClient
19
+ from slack_sdk.socket_mode.request import SocketModeRequest
20
+ from slack_sdk.socket_mode.response import SocketModeResponse
21
+ from slack_sdk.web import WebClient
22
+
23
+ T = TypeVar("T")
24
+ log = getLogger(__file__)
25
+
26
+
27
+ __all__ = ("SlackMessage", "mention_user", "SlackAdapterManager", "SlackInputAdapterImpl", "SlackOutputAdapterImpl")
28
+
29
+
30
+ class SlackMessage(Struct):
31
+ user: str
32
+ user_email: str # email of the author
33
+ user_id: str # user id of the author
34
+ tags: List[str] # list of mentions
35
+
36
+ channel: str # name of channel
37
+ channel_id: str # id of channel
38
+ channel_type: str # type of channel, in "message", "public" (app_mention), "private" (app_mention)
39
+
40
+ msg: str # parsed text payload
41
+ reaction: str # emoji reacts
42
+ thread: str # thread id, if in thread
43
+ payload: dict # raw message payload
44
+
45
+
46
+ def mention_user(userid: str) -> str:
47
+ """Convenience method, more difficult to do in symphony but we want slack to be symmetric"""
48
+ return f"<@{userid}>"
49
+
50
+
51
+ class SlackAdapterManager(AdapterManagerImpl):
52
+ def __init__(self, app_token: str, bot_token: str, ssl: Optional[SSLContext] = None):
53
+ if not app_token.startswith("xapp-") or not bot_token.startswith("xoxb-"):
54
+ raise RuntimeError("Slack app token or bot token looks malformed")
55
+
56
+ self._slack_client = SocketModeClient(
57
+ app_token=app_token,
58
+ web_client=WebClient(token=bot_token, ssl=ssl),
59
+ )
60
+ self._slack_client.socket_mode_request_listeners.append(self._process_slack_message)
61
+
62
+ # down stream edges
63
+ self._subscribers = []
64
+ self._publishers = []
65
+
66
+ # message queues
67
+ self._inqueue: Queue[SlackMessage] = Queue()
68
+ self._outqueue: Queue[SlackMessage] = Queue()
69
+
70
+ # handler thread
71
+ self._running: bool = False
72
+ self._thread: Thread = None
73
+
74
+ # lookups for mentions and redirection
75
+ self._room_id_to_room_name: Dict[str, str] = {}
76
+ self._room_id_to_room_type: Dict[str, str] = {}
77
+ self._room_name_to_room_id: Dict[str, str] = {}
78
+ self._user_id_to_user_name: Dict[str, str] = {}
79
+ self._user_id_to_user_email: Dict[str, str] = {}
80
+ self._user_name_to_user_id: Dict[str, str] = {}
81
+ self._user_email_to_user_id: Dict[str, str] = {}
82
+
83
+ def subscribe(self):
84
+ return _slack_input_adapter(self, push_mode=csp.PushMode.NON_COLLAPSING)
85
+
86
+ def publish(self, msg: ts[SlackMessage]):
87
+ return _slack_output_adapter(self, msg)
88
+
89
+ def _create(self, engine, memo):
90
+ # We'll avoid having a second class and make our AdapterManager and AdapterManagerImpl the same
91
+ super().__init__(engine)
92
+ return self
93
+
94
+ def start(self, starttime, endtime):
95
+ self._running = True
96
+ self._thread = threading.Thread(target=self._run, daemon=True)
97
+ self._thread.start()
98
+
99
+ def stop(self):
100
+ if self._running:
101
+ self._running = False
102
+ self._slack_client.close()
103
+ self._thread.join()
104
+
105
+ def register_subscriber(self, adapter):
106
+ if adapter not in self._subscribers:
107
+ self._subscribers.append(adapter)
108
+
109
+ def register_publisher(self, adapter):
110
+ if adapter not in self._publishers:
111
+ self._publishers.append(adapter)
112
+
113
+ def _get_user_from_id(self, user_id):
114
+ # try to pull from cache
115
+ name = self._user_id_to_user_name.get(user_id, None)
116
+ email = self._user_id_to_user_email.get(user_id, None)
117
+
118
+ # if none, refresh data via web client
119
+ if name is None or email is None:
120
+ ret = self._slack_client.web_client.users_info(user=user_id)
121
+ if ret.status_code == 200:
122
+ # TODO OAuth scopes required
123
+ name = ret.data["user"]["profile"].get("real_name_normalized", ret.data["user"]["name"])
124
+ email = ret.data["user"]["profile"]["email"]
125
+ self._user_id_to_user_name[user_id] = name
126
+ self._user_name_to_user_id[name] = user_id # TODO is this 1-1 in slack?
127
+ self._user_id_to_user_email[user_id] = email
128
+ self._user_email_to_user_id[email] = user_id
129
+ return name, email
130
+
131
+ def _get_user_from_name(self, user_name):
132
+ # try to pull from cache
133
+ user_id = self._user_name_to_user_id.get(user_name, None)
134
+
135
+ # if none, refresh data via web client
136
+ if user_id is None:
137
+ # unfortunately the reverse lookup is not super nice...
138
+ # we need to pull all users and build the reverse mapping
139
+ ret = self._slack_client.web_client.users_list()
140
+ if ret.status_code == 200:
141
+ # TODO OAuth scopes required
142
+ for user in ret.data["members"]:
143
+ name = user["profile"].get("real_name_normalized", user["name"])
144
+ user_id = user["profile"]["id"]
145
+ email = user["profile"]["email"]
146
+ self._user_id_to_user_name[user_id] = name
147
+ self._user_name_to_user_id[name] = user_id # TODO is this 1-1 in slack?
148
+ self._user_id_to_user_email[user_id] = email
149
+ self._user_email_to_user_id[email] = user_id
150
+ return self._user_name_to_user_id.get(user_name, None)
151
+ return user_id
152
+
153
+ def _channel_data_to_channel_kind(self, data) -> str:
154
+ if data.get("is_im", False):
155
+ return "message"
156
+ if data.get("is_private", False):
157
+ return "private"
158
+ return "public"
159
+
160
+ def _get_channel_from_id(self, channel_id):
161
+ # try to pull from cache
162
+ name = self._room_id_to_room_name.get(channel_id, None)
163
+ kind = self._room_id_to_room_type.get(channel_id, None)
164
+
165
+ # if none, refresh data via web client
166
+ if name is None:
167
+ ret = self._slack_client.web_client.conversations_info(channel=channel_id)
168
+ if ret.status_code == 200:
169
+ # TODO OAuth scopes required
170
+ kind = self._channel_data_to_channel_kind(ret.data["channel"])
171
+ if kind == "message":
172
+ # TODO use same behavior as symphony adapter
173
+ name = "DM"
174
+ else:
175
+ name = ret.data["channel"]["name"]
176
+
177
+ self._room_id_to_room_name[channel_id] = name
178
+ self._room_name_to_room_id[name] = channel_id
179
+ self._room_id_to_room_type[channel_id] = kind
180
+ return name, kind
181
+
182
+ def _get_channel_from_name(self, channel_name):
183
+ # try to pull from cache
184
+ channel_id = self._room_name_to_room_id.get(channel_name, None)
185
+
186
+ # if none, refresh data via web client
187
+ if channel_id is None:
188
+ # unfortunately the reverse lookup is not super nice...
189
+ # we need to pull all channels and build the reverse mapping
190
+ ret = self._slack_client.web_client.conversations_list()
191
+ if ret.status_code == 200:
192
+ # TODO OAuth scopes required
193
+ for channel in ret.data["channels"]:
194
+ name = channel["name"]
195
+ channel_id = channel["id"]
196
+ kind = self._channel_data_to_channel_kind(channel)
197
+ self._room_id_to_room_name[channel_id] = name
198
+ self._room_name_to_room_id[name] = channel_id
199
+ self._room_id_to_room_type[channel_id] = kind
200
+ return self._room_name_to_room_id.get(channel_name, None)
201
+ return channel_id
202
+
203
+ def _get_tags_from_message(self, blocks, authorizations=None) -> List[str]:
204
+ """extract tags from message, potentially excluding the bot's own @"""
205
+ authorizations = authorizations or []
206
+ if len(authorizations) > 0:
207
+ bot_id = authorizations[0]["user_id"] # TODO more than one?
208
+ else:
209
+ bot_id = ""
210
+
211
+ tags = []
212
+ to_search = blocks.copy()
213
+
214
+ while to_search:
215
+ element = to_search.pop()
216
+ # add subsections
217
+ if element.get("elements", []):
218
+ to_search.extend(element.get("elements"))
219
+
220
+ if element.get("type", "") == "user":
221
+ tag_id = element.get("user_id")
222
+ if tag_id != bot_id:
223
+ # TODO tag with id or with name?
224
+ name, _ = self._get_user_from_id(tag_id)
225
+ if name:
226
+ tags.append(name)
227
+ return tags
228
+
229
+ def _process_slack_message(self, client: SocketModeClient, req: SocketModeRequest):
230
+ log.info(req.payload)
231
+ if req.type == "events_api":
232
+ # Acknowledge the request anyway
233
+ response = SocketModeResponse(envelope_id=req.envelope_id)
234
+ client.send_socket_mode_response(response)
235
+
236
+ if req.payload["event"]["type"] in ("message", "app_mention") and req.payload["event"].get("subtype") is None:
237
+ user, user_email = self._get_user_from_id(req.payload["event"]["user"])
238
+ channel, channel_type = self._get_channel_from_id(req.payload["event"]["channel"])
239
+ tags = self._get_tags_from_message(req.payload["event"]["blocks"], req.payload["authorizations"])
240
+ slack_msg = SlackMessage(
241
+ user=user or "",
242
+ user_email=user_email or "",
243
+ user_id=req.payload["event"]["user"],
244
+ tags=tags,
245
+ channel=channel or "",
246
+ channel_id=req.payload["event"]["channel"],
247
+ channel_type=channel_type or "",
248
+ msg=req.payload["event"]["text"],
249
+ reaction="",
250
+ thread=req.payload["event"]["ts"],
251
+ payload=req.payload.copy(),
252
+ )
253
+ self._inqueue.put(slack_msg)
254
+
255
+ def _run(self):
256
+ self._slack_client.connect()
257
+
258
+ while self._running:
259
+ # drain outbound
260
+ while not self._outqueue.empty():
261
+ # pull SlackMessage from queue
262
+ slack_msg = self._outqueue.get()
263
+
264
+ # refactor into slack command
265
+ # grab channel or DM
266
+ if hasattr(slack_msg, "channel_id") and slack_msg.channel_id:
267
+ channel_id = slack_msg.channel_id
268
+ elif hasattr(slack_msg, "channel") and slack_msg.channel:
269
+ # TODO DM
270
+ channel_id = self._get_channel_from_name(slack_msg.channel)
271
+
272
+ # pull text or reaction
273
+ if hasattr(slack_msg, "reaction") and slack_msg.reaction and hasattr(slack_msg, "thread") and slack_msg.thread:
274
+ # TODO
275
+ self._slack_client.web_client.reactions_add(
276
+ channel=channel_id,
277
+ name=slack_msg.reaction,
278
+ timestamp=slack_msg.thread,
279
+ )
280
+ elif hasattr(slack_msg, "msg") and slack_msg.msg:
281
+ try:
282
+ # send text to channel
283
+ self._slack_client.web_client.chat_postMessage(
284
+ channel=channel_id,
285
+ text=getattr(slack_msg, "msg", ""),
286
+ )
287
+ except SlackApiError:
288
+ # TODO
289
+ ...
290
+ else:
291
+ # cannot send empty message, log an error
292
+ log.error(f"Received malformed SlackMessage instance: {slack_msg}")
293
+
294
+ if not self._inqueue.empty():
295
+ # pull all SlackMessages from queue
296
+ # do as burst to match SymphonyAdapter
297
+ slack_msgs = []
298
+ while not self._inqueue.empty():
299
+ slack_msgs.append(self._inqueue.get())
300
+
301
+ # push to all the subscribers
302
+ for adapter in self._subscribers:
303
+ adapter.push_tick(slack_msgs)
304
+
305
+ # do short sleep
306
+ sleep(0.1)
307
+
308
+ # liveness check
309
+ if not self._thread.is_alive():
310
+ self._running = False
311
+ self._thread.join()
312
+
313
+ # shut down socket client
314
+ try:
315
+ # TODO which one?
316
+ self._slack_client.close()
317
+ # self._slack_client.disconnect()
318
+ except AttributeError:
319
+ # TODO bug in slack sdk causes an exception to be thrown
320
+ # File "slack_sdk/socket_mode/builtin/connection.py", line 191, in disconnect
321
+ # self.sock.close()
322
+ # ^^^^^^^^^^^^^^^
323
+ # AttributeError: 'NoneType' object has no attribute 'close'
324
+ ...
325
+
326
+ def _on_tick(self, value):
327
+ self._outqueue.put(value)
328
+
329
+
330
+ class SlackInputAdapterImpl(PushInputAdapter):
331
+ def __init__(self, manager):
332
+ manager.register_subscriber(self)
333
+ super().__init__()
334
+
335
+
336
+ class SlackOutputAdapterImpl(OutputAdapter):
337
+ def __init__(self, manager):
338
+ manager.register_publisher(self)
339
+ self._manager = manager
340
+ super().__init__()
341
+
342
+ def on_tick(self, time, value):
343
+ self._manager._on_tick(value)
344
+
345
+
346
+ _slack_input_adapter = py_push_adapter_def(
347
+ name="SlackInputAdapter",
348
+ adapterimpl=SlackInputAdapterImpl,
349
+ out_type=ts[[SlackMessage]],
350
+ manager_type=SlackAdapterManager,
351
+ )
352
+ _slack_output_adapter = py_output_adapter_def(
353
+ name="SlackOutputAdapter",
354
+ adapterimpl=SlackOutputAdapterImpl,
355
+ manager_type=SlackAdapterManager,
356
+ input=ts[SlackMessage],
357
+ )
@@ -0,0 +1,209 @@
1
+ import pytest
2
+ from datetime import timedelta
3
+ from ssl import create_default_context
4
+ from unittest.mock import MagicMock, call, patch
5
+
6
+ import csp
7
+ from csp import ts
8
+ from csp_adapter_slack import SlackAdapterManager, SlackMessage, mention_user
9
+
10
+
11
+ @csp.node
12
+ def hello(msg: ts[SlackMessage]) -> ts[SlackMessage]:
13
+ if csp.ticked(msg):
14
+ text = f"Hello <@{msg.user_id}>!"
15
+ return SlackMessage(
16
+ channel="a new channel",
17
+ # reply in thread
18
+ thread=msg.thread,
19
+ msg=text,
20
+ )
21
+
22
+
23
+ @csp.node
24
+ def react(msg: ts[SlackMessage]) -> ts[SlackMessage]:
25
+ if csp.ticked(msg):
26
+ return SlackMessage(
27
+ channel=msg.channel,
28
+ channel_id=msg.channel_id,
29
+ thread=msg.thread,
30
+ reaction="eyes",
31
+ )
32
+
33
+
34
+ @csp.node
35
+ def send_fake_message(clientmock: MagicMock, requestmock: MagicMock, am: SlackAdapterManager) -> ts[bool]:
36
+ with csp.alarms():
37
+ a_send = csp.alarm(bool)
38
+ with csp.start():
39
+ csp.schedule_alarm(a_send, timedelta(seconds=1), True)
40
+ if csp.ticked(a_send):
41
+ if a_send:
42
+ am._process_slack_message(clientmock, requestmock)
43
+ csp.schedule_alarm(a_send, timedelta(seconds=1), False)
44
+ else:
45
+ return True
46
+
47
+
48
+ PUBLIC_CHANNEL_MENTION_PAYLOAD = {
49
+ "token": "ABCD",
50
+ "team_id": "EFGH",
51
+ "api_app_id": "HIJK",
52
+ "event": {
53
+ "client_msg_id": "1234-5678",
54
+ "type": "app_mention",
55
+ "text": "<@BOTID> <@USERID> <@USERID2>",
56
+ "user": "USERID",
57
+ "ts": "1.2",
58
+ "blocks": [
59
+ {
60
+ "type": "rich_text",
61
+ "block_id": "tx381",
62
+ "elements": [
63
+ {
64
+ "type": "rich_text_section",
65
+ "elements": [
66
+ {"type": "user", "user_id": "BOTID"},
67
+ {"type": "text", "text": " "},
68
+ {"type": "user", "user_id": "USERID"},
69
+ {"type": "text", "text": " "},
70
+ {"type": "user", "user_id": "USERID2"},
71
+ ],
72
+ }
73
+ ],
74
+ }
75
+ ],
76
+ "team": "ABCD",
77
+ "channel": "EFGH",
78
+ "event_ts": "1.2",
79
+ },
80
+ "type": "event_callback",
81
+ "event_id": "ABCD",
82
+ "event_time": 1707423091,
83
+ "authorizations": [{"enterprise_id": None, "team_id": "ABCD", "user_id": "BOTID", "is_bot": True, "is_enterprise_install": False}],
84
+ "is_ext_shared_channel": False,
85
+ "event_context": "SOMELONGCONTEXT",
86
+ }
87
+ DIRECT_MESSAGE_PAYLOAD = {
88
+ "token": "ABCD",
89
+ "team_id": "EFGH",
90
+ "context_team_id": "ABCD",
91
+ "context_enterprise_id": None,
92
+ "api_app_id": "HIJK",
93
+ "event": {
94
+ "client_msg_id": "1234-5678",
95
+ "type": "message",
96
+ "text": "test",
97
+ "user": "USERID",
98
+ "ts": "2.1",
99
+ "blocks": [
100
+ {
101
+ "type": "rich_text",
102
+ "block_id": "gB9fq",
103
+ "elements": [{"type": "rich_text_section", "elements": [{"type": "text", "text": "test"}]}],
104
+ }
105
+ ],
106
+ "team": "ABCD",
107
+ "channel": "EFGH",
108
+ "event_ts": "2.1",
109
+ "channel_type": "im",
110
+ },
111
+ "type": "event_callback",
112
+ "event_id": "ABCD",
113
+ "event_time": 1707423220,
114
+ "authorizations": [{"enterprise_id": None, "team_id": "ABCD", "user_id": "BOTID", "is_bot": True, "is_enterprise_install": False}],
115
+ "is_ext_shared_channel": False,
116
+ "event_context": "SOMELONGCONTEXT",
117
+ }
118
+
119
+
120
+ class TestSlack:
121
+ def test_slack_tokens(self):
122
+ with pytest.raises(RuntimeError):
123
+ SlackAdapterManager("abc", "def")
124
+
125
+ @pytest.mark.parametrize("payload", (PUBLIC_CHANNEL_MENTION_PAYLOAD, DIRECT_MESSAGE_PAYLOAD))
126
+ def test_slack(self, payload):
127
+ with patch("csp_adapter_slack.adapter.SocketModeClient") as clientmock:
128
+ # mock out the event from the slack sdk
129
+ reqmock = MagicMock()
130
+ reqmock.type = "events_api"
131
+ reqmock.payload = payload
132
+
133
+ # mock out the user/room lookup responses
134
+ mock_user_response = MagicMock(name="users_info_mock")
135
+ mock_user_response.status_code = 200
136
+ mock_user_response.data = {"user": {"profile": {"real_name_normalized": "johndoe", "email": "johndoe@some.email"}, "name": "blerg"}}
137
+ clientmock.return_value.web_client.users_info.return_value = mock_user_response
138
+ mock_room_response = MagicMock(name="conversations_info_mock")
139
+ mock_room_response.status_code = 200
140
+ mock_room_response.data = {"channel": {"is_im": False, "is_private": True, "name": "a private channel"}}
141
+ clientmock.return_value.web_client.conversations_info.return_value = mock_room_response
142
+ mock_list_response = MagicMock(name="conversations_list_mock")
143
+ mock_list_response.status_code = 200
144
+ mock_list_response.data = {
145
+ "channels": [
146
+ {"name": "a private channel", "id": "EFGH"},
147
+ {"name": "a new channel", "id": "new_channel"},
148
+ ]
149
+ }
150
+ clientmock.return_value.web_client.conversations_list.return_value = mock_list_response
151
+
152
+ def graph():
153
+ am = SlackAdapterManager("xapp-1-dummy", "xoxb-dummy", ssl=create_default_context())
154
+
155
+ # send a fake slack message to the app
156
+ stop = send_fake_message(clientmock, reqmock, am)
157
+
158
+ # send a response
159
+ resp = hello(csp.unroll(am.subscribe()))
160
+ am.publish(resp)
161
+
162
+ # do a react
163
+ rct = react(csp.unroll(am.subscribe()))
164
+ am.publish(rct)
165
+
166
+ csp.add_graph_output("response", resp)
167
+ csp.add_graph_output("react", rct)
168
+
169
+ # stop after first messages
170
+ done_flag = (csp.count(stop) + csp.count(resp) + csp.count(rct)) == 3
171
+ csp.stop_engine(done_flag)
172
+
173
+ # run the graph
174
+ resp = csp.run(graph, realtime=True)
175
+
176
+ # check outputs
177
+ if payload == PUBLIC_CHANNEL_MENTION_PAYLOAD:
178
+ assert resp["react"]
179
+ assert resp["response"]
180
+
181
+ assert resp["react"][0][1] == SlackMessage(channel="a private channel", channel_id="EFGH", reaction="eyes", thread="1.2")
182
+ assert resp["response"][0][1] == SlackMessage(channel="a new channel", msg="Hello <@USERID>!", thread="1.2")
183
+ else:
184
+ assert resp["react"]
185
+ assert resp["response"]
186
+
187
+ assert resp["react"][0][1] == SlackMessage(channel="a private channel", channel_id="EFGH", reaction="eyes", thread="2.1")
188
+ assert resp["response"][0][1] == SlackMessage(channel="a new channel", msg="Hello <@USERID>!", thread="2.1")
189
+
190
+ # check all inbound mocks got called
191
+ if payload == PUBLIC_CHANNEL_MENTION_PAYLOAD:
192
+ assert clientmock.return_value.web_client.users_info.call_count == 2
193
+ else:
194
+ assert clientmock.return_value.web_client.users_info.call_count == 1
195
+ assert clientmock.return_value.web_client.conversations_info.call_count == 1
196
+
197
+ # check all outbound mocks got called
198
+ assert clientmock.return_value.web_client.reactions_add.call_count == 1
199
+ assert clientmock.return_value.web_client.chat_postMessage.call_count == 1
200
+
201
+ if payload == PUBLIC_CHANNEL_MENTION_PAYLOAD:
202
+ assert clientmock.return_value.web_client.reactions_add.call_args_list == [call(channel="EFGH", name="eyes", timestamp="1.2")]
203
+ assert clientmock.return_value.web_client.chat_postMessage.call_args_list == [call(channel="new_channel", text="Hello <@USERID>!")]
204
+ else:
205
+ assert clientmock.return_value.web_client.reactions_add.call_args_list == [call(channel="EFGH", name="eyes", timestamp="2.1")]
206
+ assert clientmock.return_value.web_client.chat_postMessage.call_args_list == [call(channel="new_channel", text="Hello <@USERID>!")]
207
+
208
+ def test_mention_user(self):
209
+ assert mention_user("ABCD") == "<@ABCD>"
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.3
2
+ Name: csp_adapter_slack
3
+ Version: 0.1.0
4
+ Summary: A csp adapter for slack
5
+ Project-URL: Repository, https://github.com/point72/csp-adapter-slack
6
+ Project-URL: Homepage, https://github.com/point72/csp-adapter-slack
7
+ Author-email: the csp authors <CSPOpenSource@point72.com>
8
+ License: Apache License
9
+ Version 2.0, January 2004
10
+ http://www.apache.org/licenses/
11
+
12
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
+
14
+ 1. Definitions.
15
+
16
+ "License" shall mean the terms and conditions for use, reproduction,
17
+ and distribution as defined by Sections 1 through 9 of this document.
18
+
19
+ "Licensor" shall mean the copyright owner or entity authorized by
20
+ the copyright owner that is granting the License.
21
+
22
+ "Legal Entity" shall mean the union of the acting entity and all
23
+ other entities that control, are controlled by, or are under common
24
+ control with that entity. For the purposes of this definition,
25
+ "control" means (i) the power, direct or indirect, to cause the
26
+ direction or management of such entity, whether by contract or
27
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
28
+ outstanding shares, or (iii) beneficial ownership of such entity.
29
+
30
+ "You" (or "Your") shall mean an individual or Legal Entity
31
+ exercising permissions granted by this License.
32
+
33
+ "Source" form shall mean the preferred form for making modifications,
34
+ including but not limited to software source code, documentation
35
+ source, and configuration files.
36
+
37
+ "Object" form shall mean any form resulting from mechanical
38
+ transformation or translation of a Source form, including but
39
+ not limited to compiled object code, generated documentation,
40
+ and conversions to other media types.
41
+
42
+ "Work" shall mean the work of authorship, whether in Source or
43
+ Object form, made available under the License, as indicated by a
44
+ copyright notice that is included in or attached to the work
45
+ (an example is provided in the Appendix below).
46
+
47
+ "Derivative Works" shall mean any work, whether in Source or Object
48
+ form, that is based on (or derived from) the Work and for which the
49
+ editorial revisions, annotations, elaborations, or other modifications
50
+ represent, as a whole, an original work of authorship. For the purposes
51
+ of this License, Derivative Works shall not include works that remain
52
+ separable from, or merely link (or bind by name) to the interfaces of,
53
+ the Work and Derivative Works thereof.
54
+
55
+ "Contribution" shall mean any work of authorship, including
56
+ the original version of the Work and any modifications or additions
57
+ to that Work or Derivative Works thereof, that is intentionally
58
+ submitted to Licensor for inclusion in the Work by the copyright owner
59
+ or by an individual or Legal Entity authorized to submit on behalf of
60
+ the copyright owner. For the purposes of this definition, "submitted"
61
+ means any form of electronic, verbal, or written communication sent
62
+ to the Licensor or its representatives, including but not limited to
63
+ communication on electronic mailing lists, source code control systems,
64
+ and issue tracking systems that are managed by, or on behalf of, the
65
+ Licensor for the purpose of discussing and improving the Work, but
66
+ excluding communication that is conspicuously marked or otherwise
67
+ designated in writing by the copyright owner as "Not a Contribution."
68
+
69
+ "Contributor" shall mean Licensor and any individual or Legal Entity
70
+ on behalf of whom a Contribution has been received by Licensor and
71
+ subsequently incorporated within the Work.
72
+
73
+ 2. Grant of Copyright License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ copyright license to reproduce, prepare Derivative Works of,
77
+ publicly display, publicly perform, sublicense, and distribute the
78
+ Work and such Derivative Works in Source or Object form.
79
+
80
+ 3. Grant of Patent License. Subject to the terms and conditions of
81
+ this License, each Contributor hereby grants to You a perpetual,
82
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
+ (except as stated in this section) patent license to make, have made,
84
+ use, offer to sell, sell, import, and otherwise transfer the Work,
85
+ where such license applies only to those patent claims licensable
86
+ by such Contributor that are necessarily infringed by their
87
+ Contribution(s) alone or by combination of their Contribution(s)
88
+ with the Work to which such Contribution(s) was submitted. If You
89
+ institute patent litigation against any entity (including a
90
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
91
+ or a Contribution incorporated within the Work constitutes direct
92
+ or contributory patent infringement, then any patent licenses
93
+ granted to You under this License for that Work shall terminate
94
+ as of the date such litigation is filed.
95
+
96
+ 4. Redistribution. You may reproduce and distribute copies of the
97
+ Work or Derivative Works thereof in any medium, with or without
98
+ modifications, and in Source or Object form, provided that You
99
+ meet the following conditions:
100
+
101
+ (a) You must give any other recipients of the Work or
102
+ Derivative Works a copy of this License; and
103
+
104
+ (b) You must cause any modified files to carry prominent notices
105
+ stating that You changed the files; and
106
+
107
+ (c) You must retain, in the Source form of any Derivative Works
108
+ that You distribute, all copyright, patent, trademark, and
109
+ attribution notices from the Source form of the Work,
110
+ excluding those notices that do not pertain to any part of
111
+ the Derivative Works; and
112
+
113
+ (d) If the Work includes a "NOTICE" text file as part of its
114
+ distribution, then any Derivative Works that You distribute must
115
+ include a readable copy of the attribution notices contained
116
+ within such NOTICE file, excluding those notices that do not
117
+ pertain to any part of the Derivative Works, in at least one
118
+ of the following places: within a NOTICE text file distributed
119
+ as part of the Derivative Works; within the Source form or
120
+ documentation, if provided along with the Derivative Works; or,
121
+ within a display generated by the Derivative Works, if and
122
+ wherever such third-party notices normally appear. The contents
123
+ of the NOTICE file are for informational purposes only and
124
+ do not modify the License. You may add Your own attribution
125
+ notices within Derivative Works that You distribute, alongside
126
+ or as an addendum to the NOTICE text from the Work, provided
127
+ that such additional attribution notices cannot be construed
128
+ as modifying the License.
129
+
130
+ You may add Your own copyright statement to Your modifications and
131
+ may provide additional or different license terms and conditions
132
+ for use, reproduction, or distribution of Your modifications, or
133
+ for any such Derivative Works as a whole, provided Your use,
134
+ reproduction, and distribution of the Work otherwise complies with
135
+ the conditions stated in this License.
136
+
137
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
138
+ any Contribution intentionally submitted for inclusion in the Work
139
+ by You to the Licensor shall be under the terms and conditions of
140
+ this License, without any additional terms or conditions.
141
+ Notwithstanding the above, nothing herein shall supersede or modify
142
+ the terms of any separate license agreement you may have executed
143
+ with Licensor regarding such Contributions.
144
+
145
+ 6. Trademarks. This License does not grant permission to use the trade
146
+ names, trademarks, service marks, or product names of the Licensor,
147
+ except as required for reasonable and customary use in describing the
148
+ origin of the Work and reproducing the content of the NOTICE file.
149
+
150
+ 7. Disclaimer of Warranty. Unless required by applicable law or
151
+ agreed to in writing, Licensor provides the Work (and each
152
+ Contributor provides its Contributions) on an "AS IS" BASIS,
153
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154
+ implied, including, without limitation, any warranties or conditions
155
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
156
+ PARTICULAR PURPOSE. You are solely responsible for determining the
157
+ appropriateness of using or redistributing the Work and assume any
158
+ risks associated with Your exercise of permissions under this License.
159
+
160
+ 8. Limitation of Liability. In no event and under no legal theory,
161
+ whether in tort (including negligence), contract, or otherwise,
162
+ unless required by applicable law (such as deliberate and grossly
163
+ negligent acts) or agreed to in writing, shall any Contributor be
164
+ liable to You for damages, including any direct, indirect, special,
165
+ incidental, or consequential damages of any character arising as a
166
+ result of this License or out of the use or inability to use the
167
+ Work (including but not limited to damages for loss of goodwill,
168
+ work stoppage, computer failure or malfunction, or any and all
169
+ other commercial damages or losses), even if such Contributor
170
+ has been advised of the possibility of such damages.
171
+
172
+ 9. Accepting Warranty or Additional Liability. While redistributing
173
+ the Work or Derivative Works thereof, You may choose to offer,
174
+ and charge a fee for, acceptance of support, warranty, indemnity,
175
+ or other liability obligations and/or rights consistent with this
176
+ License. However, in accepting such obligations, You may act only
177
+ on Your own behalf and on Your sole responsibility, not on behalf
178
+ of any other Contributor, and only if You agree to indemnify,
179
+ defend, and hold each Contributor harmless for any liability
180
+ incurred by, or claims asserted against, such Contributor by reason
181
+ of your accepting any such warranty or additional liability.
182
+
183
+ END OF TERMS AND CONDITIONS
184
+
185
+ APPENDIX: How to apply the Apache License to your work.
186
+
187
+ To apply the Apache License to your work, attach the following
188
+ boilerplate notice, with the fields enclosed by brackets "[]"
189
+ replaced with your own identifying information. (Don't include
190
+ the brackets!) The text should be enclosed in the appropriate
191
+ comment syntax for the file format. We also recommend that a
192
+ file or class name and description of purpose be included on the
193
+ same "printed page" as the copyright notice for easier
194
+ identification within third-party archives.
195
+
196
+ Copyright 2024 Point72, L..P.
197
+
198
+ Licensed under the Apache License, Version 2.0 (the "License");
199
+ you may not use this file except in compliance with the License.
200
+ You may obtain a copy of the License at
201
+
202
+ http://www.apache.org/licenses/LICENSE-2.0
203
+
204
+ Unless required by applicable law or agreed to in writing, software
205
+ distributed under the License is distributed on an "AS IS" BASIS,
206
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
+ See the License for the specific language governing permissions and
208
+ limitations under the License.
209
+ License-File: LICENSE
210
+ Keywords: chat,chatbot,csp,slack,stream-processing
211
+ Classifier: Development Status :: 4 - Beta
212
+ Classifier: Framework :: Jupyter
213
+ Classifier: License :: OSI Approved :: Apache Software License
214
+ Classifier: Programming Language :: Python
215
+ Classifier: Programming Language :: Python :: 3
216
+ Classifier: Programming Language :: Python :: 3.8
217
+ Classifier: Programming Language :: Python :: 3.9
218
+ Classifier: Programming Language :: Python :: 3.10
219
+ Classifier: Programming Language :: Python :: 3.11
220
+ Classifier: Programming Language :: Python :: 3.12
221
+ Requires-Python: >=3.8
222
+ Requires-Dist: csp
223
+ Requires-Dist: slack-sdk>=3
224
+ Provides-Extra: develop
225
+ Requires-Dist: bump2version>=1.0.0; extra == 'develop'
226
+ Requires-Dist: check-manifest; extra == 'develop'
227
+ Requires-Dist: codespell<2.3,>=2.2.6; extra == 'develop'
228
+ Requires-Dist: hatchling; extra == 'develop'
229
+ Requires-Dist: mdformat<0.8,>=0.7.17; extra == 'develop'
230
+ Requires-Dist: pytest; extra == 'develop'
231
+ Requires-Dist: pytest-cov; extra == 'develop'
232
+ Requires-Dist: ruff<0.6,>=0.5; extra == 'develop'
233
+ Requires-Dist: twine<5.2,>=5; extra == 'develop'
234
+ Provides-Extra: test
235
+ Requires-Dist: pytest; extra == 'test'
236
+ Requires-Dist: pytest-cov; extra == 'test'
237
+ Description-Content-Type: text/markdown
238
+
239
+ # csp slack adapter
240
+
241
+ A [csp](https://github.com/point72/csp) adapter for [slack](https://slack.com)
242
+
243
+ [![Build Status](https://github.com/point72/csp-adapter-slack/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/point72/csp-adapter-slack/actions?query=workflow%3A%22Build+Status%22)
244
+ [![GitHub issues](https://img.shields.io/github/issues/point72/csp-adapter-slack.svg)](https://github.com/point72/csp-adapter-slack/issues)
245
+ [![PyPI](https://img.shields.io/pypi/l/csp-adapter-slack.svg)](https://pypi.python.org/pypi/csp-adapter-slack)
246
+ [![PyPI](https://img.shields.io/pypi/v/csp-adapter-slack.svg)](https://pypi.python.org/pypi/csp-adapter-slack)
247
+
248
+ ## Features
249
+
250
+ [More information is available in our wiki](https://github.com/Point72/csp-adapter-slack/wiki)
251
+
252
+ ## Installation
253
+
254
+ Install with `pip`:
255
+
256
+ ```bash
257
+ pip install csp csp-adapter-slack
258
+ ```
259
+
260
+ Install with `conda`
261
+
262
+ ```bash
263
+ conda install csp csp-adapter-slack -c conda-forge
264
+ ```
265
+
266
+ ## License
267
+
268
+ This software is licensed under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,7 @@
1
+ csp_adapter_slack/__init__.py,sha256=2O1xwdScxbSSHEY9JjQUXRz7UP9Vo7wJMWEdqbFdmBY,46
2
+ csp_adapter_slack/adapter.py,sha256=5koeoqvWE0Fx7gUV-s4YiSc99x9gPJX4Xvo-L4IN6vA,14160
3
+ csp_adapter_slack/tests/test_adapter.py,sha256=ZfzDQD_qfELKTp6eMS9GuZ19_5yUrIItqv_xENgoD8A,8284
4
+ csp_adapter_slack-0.1.0.dist-info/METADATA,sha256=O-kA3q_0UiQwIZjCsanCOqsB27UVlkWtr2Hex4kXQyM,15549
5
+ csp_adapter_slack-0.1.0.dist-info/WHEEL,sha256=as-1oFTWSeWBgyzh0O_qF439xqBe6AbBgt4MfYe5zwY,87
6
+ csp_adapter_slack-0.1.0.dist-info/licenses/LICENSE,sha256=Dz904Ba4BFTsnLKU2nrCbcc8nqE1hZvaVDl_oOPueDE,11344
7
+ csp_adapter_slack-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.22.5
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 Point72, L..P.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.