Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save KyMidd/8fe9b87dfe4c0af6321a39fe8e90b31f to your computer and use it in GitHub Desktop.
# Function to build the content of a conversation
def build_conversation_content(payload, token):
# Initialize unsupported file type found canary var
unsupported_file_type_found = False
# Initialize the content array
content = []
# Identify the user's ID
user_id = payload["user"]
# Find the user's information
user_info = requests.get(
f"https://slack.com/api/users.info?user={user_id}",
headers={"Authorization": "Bearer " + token},
)
# Identify the user's real name
user_info_json = user_info.json()
user_real_name = user_info_json["user"]["real_name"]
# TODO: Add support for pronouns, if returned in user payload. For now, everyone is nonbinary
# If text is not empty, and text length is greater than 0, append to content array
if "text" in payload and len(payload["text"]) > 1:
# If debug variable is set to true, print the text found in the payload
if os.environ.get("VERA_DEBUG", "False") == "True":
print("🚀 Text found in payload: " + payload["text"])
content.append(
{
"type": "text",
# Combine the user's name with the text to help the model understand who is speaking
"text": f"{user_real_name} says: {payload['text']}",
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment