From 1c62497484f459c877d09db13b2f66e2b01c2ff2 Mon Sep 17 00:00:00 2001 From: Cyrus Mobini Date: Thu, 17 Oct 2024 10:53:31 -0400 Subject: [PATCH 1/3] Passing slacks ts and thread_ts as is, and useing reply_to_thread and thread_id for cm logic --- .../components/slack_input.py | 28 +++++++++++++++---- .../components/slack_output.py | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/solace_ai_connector_slack/components/slack_input.py b/src/solace_ai_connector_slack/components/slack_input.py index 493db7a..3b22753 100644 --- a/src/solace_ai_connector_slack/components/slack_input.py +++ b/src/solace_ai_connector_slack/components/slack_input.py @@ -267,8 +267,21 @@ def handle_event(self, event): except Exception as e: log.error("Error getting team domain: %s", e) - user_email = self.get_user_email(event["user"]) + user_email = self.get_user_email(event.get("user")) (text, mention_emails) = self.process_text_for_mentions(event["text"]) + + # Determine the thread_ts to put in the message + if event.get("channel_type") == "im" and event.get("subtype", event.get("type")) == "app_mention": + ts = event.get("ts") + else: + ts = None + + reply_to = event.get("thread_ts") or ts + if reply_to: + thread_id = f"{event.get("channel")}_{reply_to}" + else: + thread_id = event.get("channel") + payload = { "text": text, "files": files, @@ -278,33 +291,38 @@ def handle_event(self, event): "mentions": mention_emails, "type": event.get("type"), "client_msg_id": event.get("client_msg_id"), - "ts": event.get("thread_ts"), + "ts": ts, "channel": event.get("channel"), "channel_name": event.get("channel_name", ""), "subtype": event.get("subtype"), - "event_ts": event.get("event_ts"), + "thread_ts": event.get("thread_ts"), "channel_type": event.get("channel_type"), "user_id": event.get("user"), + "thread_id": thread_id, + "reply_to_thread": reply_to, } user_properties = { "user_email": user_email, "team_id": event.get("team"), "type": event.get("type"), "client_msg_id": event.get("client_msg_id"), - "ts": event.get("thread_ts"), + "ts": ts, + "thread_ts": event.get("thread_ts"), "channel": event.get("channel"), "subtype": event.get("subtype"), "event_ts": event.get("event_ts"), "channel_type": event.get("channel_type"), "user_id": event.get("user"), "input_type": "slack", + "thread_id": thread_id, + "reply_to_thread": reply_to, } if self.acknowledgement_message and event.get("channel_type") == "im": ack_msg_ts = self.app.client.chat_postMessage( channel=event["channel"], text=self.acknowledgement_message, - thread_ts=event.get("thread_ts"), + thread_ts=reply_to, ).get("ts") user_properties["ack_msg_ts"] = ack_msg_ts diff --git a/src/solace_ai_connector_slack/components/slack_output.py b/src/solace_ai_connector_slack/components/slack_output.py index a6db93c..6a97e87 100644 --- a/src/solace_ai_connector_slack/components/slack_output.py +++ b/src/solace_ai_connector_slack/components/slack_output.py @@ -153,7 +153,7 @@ def send_message(self, message): messages = message.get_data("previous:text") stream = message.get_data("previous:stream") files = message.get_data("previous:files") or [] - thread_ts = message.get_data("previous:ts") + thread_ts = message.get_data("previous:reply_to_thread") or message.get_data("previous:thread_ts") ack_msg_ts = message.get_data("previous:ack_msg_ts") first_streamed_chunk = message.get_data("previous:first_streamed_chunk") last_streamed_chunk = message.get_data("previous:last_streamed_chunk") From 23b24e0bd7d8802482602eb3cfbab436e759f2d3 Mon Sep 17 00:00:00 2001 From: Cyrus Mobini Date: Thu, 17 Oct 2024 10:53:31 -0400 Subject: [PATCH 2/3] Passing slacks ts and thread_ts as is, and useing reply_to_thread and thread_id for cm logic --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 00c70e8..79c46df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,8 +20,7 @@ classifiers = [ dependencies = [ "PyYAML>=6.0.1", "slack_bolt>=1.18.1", - "solace_ai_connector>=0.1.3", - "prettytable>=3.10.0", + "solace_ai_connector>=0.1.1", ] [project.urls] From dadf4dbaa334c0f1ff42c5d5ec1b880748018ab7 Mon Sep 17 00:00:00 2001 From: Cyrus Mobini Date: Thu, 17 Oct 2024 11:52:17 -0400 Subject: [PATCH 3/3] minor update --- pyproject.toml | 3 ++- .../components/slack_input.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 79c46df..00c70e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ classifiers = [ dependencies = [ "PyYAML>=6.0.1", "slack_bolt>=1.18.1", - "solace_ai_connector>=0.1.1", + "solace_ai_connector>=0.1.3", + "prettytable>=3.10.0", ] [project.urls] diff --git a/src/solace_ai_connector_slack/components/slack_input.py b/src/solace_ai_connector_slack/components/slack_input.py index 3b22753..ede292c 100644 --- a/src/solace_ai_connector_slack/components/slack_input.py +++ b/src/solace_ai_connector_slack/components/slack_input.py @@ -270,13 +270,15 @@ def handle_event(self, event): user_email = self.get_user_email(event.get("user")) (text, mention_emails) = self.process_text_for_mentions(event["text"]) - # Determine the thread_ts to put in the message + # Determine the reply_to thread to put in the message if event.get("channel_type") == "im" and event.get("subtype", event.get("type")) == "app_mention": - ts = event.get("ts") + # First message uses ts, subsequent messages use thread_ts + reply_to = event.get("thread_ts") or event.get("ts") else: - ts = None + # First message uses ts, subsequent messages use thread_ts + # thread_ts is null in direct messages + reply_to = event.get("thread_ts") - reply_to = event.get("thread_ts") or ts if reply_to: thread_id = f"{event.get("channel")}_{reply_to}" else: @@ -291,10 +293,11 @@ def handle_event(self, event): "mentions": mention_emails, "type": event.get("type"), "client_msg_id": event.get("client_msg_id"), - "ts": ts, + "ts": event.get("ts"), "channel": event.get("channel"), "channel_name": event.get("channel_name", ""), "subtype": event.get("subtype"), + "event_ts": event.get("event_ts"), "thread_ts": event.get("thread_ts"), "channel_type": event.get("channel_type"), "user_id": event.get("user"), @@ -306,7 +309,7 @@ def handle_event(self, event): "team_id": event.get("team"), "type": event.get("type"), "client_msg_id": event.get("client_msg_id"), - "ts": ts, + "ts": event.get("ts"), "thread_ts": event.get("thread_ts"), "channel": event.get("channel"), "subtype": event.get("subtype"),