Mention a Bot with a flow
Yet another at-mention article. In the past I created blogs about mentioning a team, a channel and a tag in Microsoft Teams. This time I am going to show you how to at-mention a bot from a Power Automate flow.
— Dennis (@expiscornovus) June 9, 2022
This question from Himashi:
I created a chatbot using Power Virtual Agents and added it to a Teams channel. When someone posts a message on the Teams channel, I want to reply to that message using Power Automate. This Power Automate message should be able to @mention and call the chatbot. Is there a way to accomplish this?
Power Users Community thread: Call a Teams Chatbot via a Power Automate Flow.
In case you missed it, I have some other articles where I at-mentioned a tag, channel & team from Power Automate flows. All of these automations used the Graph API. So, it made sense to use it again for this scenario 🙂
With the help of the Graph Explorer I figured out which properties are needed in the json. I managed to retrieve one of my earlier channel posts which at-mentioned a bot. This gave me some pointers for the properties required for the json.
That resulted in the body below which I used with a Reply to a message in a channel method from the Graph API.
Before you start: this article assumes you have already created and published a Power Virtual Agent with a scope of personal and team. For this article you only need to know the topic trigger phrase, bot name and the bot app id.
In this example we are responding to messages in one specific channel which use the #FAQ keyword. That triggers a flow which at-mentions an FAQ Bot with a topic trigger phrase. That bot will respond to that trigger phrase.
1. When a new channel message is added trigger action (Microsoft Teams Connector).
This action uses a trigger condition to prevent the flow from being triggered for every single message. In this setup it checks if ‘#FAQ’ is part of the message.
a. Select your team and your channel.
b. Add the trigger condition expression from the code snippet below in the settings.
2. Add three initialize variable actions (optional).
These are used for the Topic trigger text (PVATopicTrigger), the bot name (BotName) and the app id of the bot (AppId). These variables are optional because you can also add the values directly in the next action.
a. Select String as type for all of them.
3. Add a Send an HTTP request action (Office 365 Groups Connector).
This action uses the Graph API to reply to the original message. The reply at-mentions the FAQ Bot with a topic trigger phrase to get the conversation started.
a. Use the following URI:
b. Select the POST method.
c. Use the code snippet below for the Body field.
That is it for the setup of this example.