Getting Started
In Part 1 I explained how we were going to use Teams and Power Automate to generate a contextually aware chatbot for your team. We’re going to use Teams channel communication to simplify how we “window” communication.
That gives us a few nice things out of the box:
- A list of messages that we can easily iterate over
- Multi-user communication
- A clear “beginning” and “end” to a conversation
So I pulled in the “When a new channel message is added” trigger:
To avoid flooding the channel with chatbot responses, I added a condition to only trigger if the message subject is “Chat Bot”:
Next thing I do is loop until a boolean variable named isComplete
is true. This will be set to true when the chatbot response is “done”. This also allows us to exit the loop in case of an error. So if you’re paying attention, you might notice the first downside of this method: we’re going to be “polling” Teams for new messages. There’s a few downsides to this: 1. we’re going to be utilizing a lot of Flow runs (you probably won’t max out) and 2. there’s going to be a delay. Ideally I’d like for this to be a webhook, but I we’ll save that for another day.
So there’s a lot to unpack here, and our first real detour. So one big downside of the Teams Power Automate connector is that it doesn’t support querying replies natively. Luckily the Microsoft Graph does have that functionality. And the HTTP with Azure AD
connector makes this super simple. Basically, if the user running the flow has access to that information, you can access replies.
So the basic flow is as follows:
- Get the replies to the message
- Parse the JSON response from the graph
- Initialize the array to store the entire conversation (including the original prompt and initialization message)
- Iterate over the replies and add them to the array
- Set the
isComplete
variable to true if the last message is “done” - Clear the array
- Wait a bit so we don’t overwhelm the loop
- Do it all again
Recap
So we now have the basic structure of the flow, triggering off the original message, looping through the replies, and storing the conversation. In the next part we’ll actually be generating the chatbot response.