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/

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


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/

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


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

Helpful resources

Announcements
Power Virtual Agents News & Announcements

Power Virtual Agents News & Announcements

Keep up to date with current events and community announcements in the Power Virtual Agents community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Virtual Agents Community Blog

Power Virtual Agents Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (4,324)