Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created August 4, 2025 01:02
Show Gist options
  • Select an option

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

Select an option

Save KyMidd/0a04bb892666ea060d9eb16e7c2e5cdc to your computer and use it in GitHub Desktop.
def build_conversation_turn(content, message, headers):
# Get sender name
try:
sender_name = message["from"]["user"]["displayName"]
sender_role = "user"
except:
sender_role = "assistant"
# Get text
content_text = message.get("body", {}).get("content", "").strip()
# Clean text, Teams adds a lot of extra html like this: "text": "Kyler Middleton says: <p>Hey Vera, what's up today?&nbsp;</p>"
content_text = re.sub(r"<[^>]+>", "", content_text)
content_text = content_text.replace("&nbsp;", " ")
# Set the content block
if sender_role == "user":
content = [
{
"text": f"{sender_name} says: {content_text}",
}
]
else:
content = [
{
"text": f"{content_text}",
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment