Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save KyMidd/d52a307c00317ff6aca8af164c4abbf4 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):
....
if "thread_ts" in body["event"]:
....
# Iterate through every message in the thread
for message in messages["messages"]:
# Build the content array
thread_conversation_content, unsupported_file_type_found = (
build_conversation_content(message, token)
)
if os.environ.get("VERA_DEBUG", "False") == "True":
print("๐Ÿš€ Thread conversation content:", thread_conversation_content)
# Check if the thread conversation content is empty. This happens when a user sends an unsupported doc type only, with no message
if thread_conversation_content != []:
# Conversation content is not empty, append to conversation
# Check if message came from the bot
# We're assuming the bot only generates text content, which is true of Claude v3.5 Sonnet v2
if "bot_id" in message:
conversation.append(
{
"role": "assistant",
"content": [
{
"type": "text",
"text": message["text"],
}
],
}
)
# If not, the message came from a user
else:
conversation.append(
{"role": "user", "content": thread_conversation_content}
)
if os.environ.get("VERA_DEBUG", "False") == "True":
print(
"๐Ÿš€ State of conversation after threaded message append:",
conversation,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment