cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Himashi
Regular Visitor

Call a Teams Chatbot via a Power Automate Flow

Hi.

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?

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @Himashi,

 

First of all great question, very interesting scenario 🙂

 

You could use the Graph API and the Reply to a message in a channel method. In that request you can reply with an at-mention to the bot and add a topic trigger text.

 

Below is a short example.

 

1. Add a When a new channel message is added trigger action

 

whenanewchannelmessageisadded02.png

 

2. Add a Send an HTTP request action (Office 365 Groups Connector)

 

Use the following URI & the POST method

https://graph.microsoft.com/v1.0/teams/@{triggerOutputs()?['body/channelIdentity']['teamId']}/channels/@{triggerOutputs()?['body/channelIdentity']['channelId']}/messages/@{triggerOutputs()?['body/id']}/replies

 

Use the json below for the body.

Replace the variables with your values for the topic trigger phrase, bot name & bot app id.

{
    "body": {
        "contentType": "html",
        "content": "<div><div><at id=\"0\">@{variables('BotName')}</at> @{variables('PVATopicTrigger')}</div></div>"
    },
    "mentions": [
        {
            "id": 0,
            "mentionText": "@{variables('BotName')}",
            "mentioned": {
                "device": null,
                "user": null,
                "conversation": null,
                "tag": null,
                "application": {
                    "id": "@{variables('BotAppId')}",
                    "displayName": "@{variables('BotName')}",
                    "applicationIdentityType": "bot"
                }
            }
        }
    ]
}

 

atmentionbotviagraphapi.png

 

Btw, I have also written a blog about this approach with a bit more details:

https://www.expiscornovus.com/2022/06/10/mention-a-bot-with-a-flow/

 

View solution in original post

2 REPLIES 2
Expiscornovus
Super User
Super User

Hi @Himashi,

 

First of all great question, very interesting scenario 🙂

 

You could use the Graph API and the Reply to a message in a channel method. In that request you can reply with an at-mention to the bot and add a topic trigger text.

 

Below is a short example.

 

1. Add a When a new channel message is added trigger action

 

whenanewchannelmessageisadded02.png

 

2. Add a Send an HTTP request action (Office 365 Groups Connector)

 

Use the following URI & the POST method

https://graph.microsoft.com/v1.0/teams/@{triggerOutputs()?['body/channelIdentity']['teamId']}/channels/@{triggerOutputs()?['body/channelIdentity']['channelId']}/messages/@{triggerOutputs()?['body/id']}/replies

 

Use the json below for the body.

Replace the variables with your values for the topic trigger phrase, bot name & bot app id.

{
    "body": {
        "contentType": "html",
        "content": "<div><div><at id=\"0\">@{variables('BotName')}</at> @{variables('PVATopicTrigger')}</div></div>"
    },
    "mentions": [
        {
            "id": 0,
            "mentionText": "@{variables('BotName')}",
            "mentioned": {
                "device": null,
                "user": null,
                "conversation": null,
                "tag": null,
                "application": {
                    "id": "@{variables('BotAppId')}",
                    "displayName": "@{variables('BotName')}",
                    "applicationIdentityType": "bot"
                }
            }
        }
    ]
}

 

atmentionbotviagraphapi.png

 

Btw, I have also written a blog about this approach with a bit more details:

https://www.expiscornovus.com/2022/06/10/mention-a-bot-with-a-flow/

 

@Expiscornovus Great and detailed solution. Thank you very much! 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Canadian Cloud 2022 768x460.png

Register for a free PVA chatbot creation workshop.

Learn how to respond rapidly to your customers and employees at scale, using intelligent conversational chatbots.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (4,070)