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.

Inspiration

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.

Graph API

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.

botmention_response_graphexplorer

That resulted in the body below which I used with a Reply to a message in a channel method from the Graph API.

Flow setup

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.

at-mentionabotfromflow

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.

whenanewchannelmessageisadded

a. Select your team and your channel.

b. Add the trigger condition expression from the code snippet below in the settings.

ChannelMessageContentTriggerCondition

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.

threevariables

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.

atmentionbotviagraphapi

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.

Happy testing!

You may also like...

3 Responses

  1. Jarrad says:

    Great post, really clear.
    That said I’m stuck,
    Power automate wont let me add a trigger “when a new channel message is added” since the trigger is already coming from the Power Virtual Agent topic 🙁
    Is there special variables to get the TeamID, ChannelID and id of the trigger from power virtual agent?

  2. Josh says:

    Hi Dennis. I’ve been trying to replicate this great solution but somehow http post is not working and I am getting this error message. I’ve tested it on graph explorer and it works but does not when ran through powerautomate.

    URI path is not a valid Graph endpoint, path is neither absolute nor relative or resource/object is not supported for this connector.

    Is this solution working?

  3. Dennis says:

    Hi Josh,

    The concept should still work. However, you would need to replace the Send an HTTP request action.

    The Send an HTTP request action (of the Office 365 Groups connector) has changed since the time I have written this blog (more than 1 year ago).

    Unfortunately, the Send an HTTP request action is now limited to only the groups resource.

    In this example we are not using that type of resource, we are using the teams resource, that’s why you are getting that error.

    You can replace this action by a HTTP action (of the HTTP connector) instead. That action is however part of a premium connector. It would also require additional setup to handle the authentication. You would also need to register an app in Entra Id for the Oath authentication for example.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.