Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of thread_ts and reply_to_thread in Slack messages #5

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/solace_ai_connector_slack/components/slack_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/solace_ai_connector_slack/components/slack_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading