Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created December 27, 2024 19:42
Show Gist options
  • Select an option

  • Save KyMidd/d8f73cc55839d99a19a7bb5a83b274ff to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/d8f73cc55839d99a19a7bb5a83b274ff to your computer and use it in GitHub Desktop.
# Common function to handle both DMs and app mentions
def handle_message_event(client, body, say, bedrock_client, app, token):
user_id = body["event"]["user"]
event = body["event"]
# Determine the thread timestamp
thread_ts = body["event"].get("thread_ts", body["event"]["ts"])
# Initialize conversation context
conversation = []
# Check to see if we're in a thread
# If yes, read previous messages in the thread, append to conversation context for AI response
if "thread_ts" in body["event"]:
# Get the messages in the thread
thread_ts = body["event"]["thread_ts"]
messages = app.client.conversations_replies(
channel=body["event"]["channel"], ts=thread_ts
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment