🔥Building a Teams Bot with AI Capabilities - Part 5 - GenAI Integration with Teams🔥
aka, what are all these GUIDs and why don't these APIs exist?
This blog series focuses on presenting complex DevOps projects as simple and approachable via plain language and lots of pictures. You can do it!
These articles are supported by readers, please consider subscribing to support me writing more of these articles <3 :)
This article is part of a series of articles, because 1 article would be absolutely massive.
Part 3: Delegated Permissions and Making Lambda Stateful for Oauth2
Part 4: Building the Receiver lambda to store tokens and state
Part 5 (this article): Finding messages, reading conversations in Teams
Hey all!
In the last article, we covered how the Receiver lambda gets an OAuth2 token that’s compatible with the GraphAPI, and how we encrypt and store that token so that our Worker lambda can utilize it to DO STUFF - like have AI conversations and post responses from our models back to the Teams platform.
Assuming that’s all working, each time our Worker is triggered now, we’re going to get a valid OAuth2 token, and some conversation information (someone tagged the bot, or messaged it directly), and it’s now our Worker lambda’s job to do the AI magic. There’s a few parts of AI magic we’ll cover.
Extract the message context - is this a DM or tag in a Teams.. Team (We know naming stuff is hard $msft)
Read the previous messages if applicable
In a DM context, there’s no good way yet to differentiate different conversations, so we just respond directly to each question - there’s no follow-up/thread model. When Teams supports this (is that coming?) we could extend the bot to cover that model.
In a Teams Team context, read messages back. We have to limit this to some length, and not read ALL the messages if there’s hundreds. So we limit to like 20 messages.
Download any attachments to any message we read
This is hilariously very different on context because of how Teams doesn’t REALLY exist. If you share an attachment in a DM, it’s stored in your OneDrive. If you share an attachment in a Teams Team, it’s usually stored in that Team’s SharePoint storage. The names are sometimes transformed to be SharePoint/OneDrive compatible, which makes my pull my hair out. We’ll cover this really well lower on.
Read the user data of any post author
To detect pronouns, nicknames, etc.
Get an AI response
We’ve covered this well in previous articles (here’s the SlackBot articles), so we won’t cover this here
Post a response
Send our response back, properly formatted for Teams.
When it all works, it looks like this:
If you don’t want to walk through all this, the code we’re going to be talking about is here:
Keep reading with a 7-day free trial
Subscribe to Let's Do DevOps to keep reading this post and get 7 days of free access to the full post archives.