How to send a chat message using BOT

Guilherme Brilhante Guimarães 61 Reputation points
2021-09-06T15:10:50.347+00:00

I have an APP with a BOT in Teams, I want to send a request that allows the BOT to send a card to the user. My intention is not to use them as proactive messages, I'm just trying to send them through Microsoft Graph.

I can send a card between users using the method:
To create the CHAT and get the ID: https://graph.microsoft.com/v1.0/chats
To send the CARD to another user: POST /chats/{chat-id}/messages

I want to send a card from a BOT to the user, I tried using the same method as above, I passed the APPID and the user ID to create the chat, however it returns 403, but it doesn't specify the permission:

{
"chatType": "oneOnOne",
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": [
"owner"
],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('APPID')"
},
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": [
"owner"
],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('USER-ID')"
}
]
]

Does anyone know how to make the BOT send the CARD to a user on Teams?

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
745 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,059 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,569 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,841 questions
{count} votes

Accepted answer
  1. Ramjot Singh 861 Reputation points Microsoft Employee
    2021-09-07T05:57:09.593+00:00

    Graph and Bot are two unique ways to send messages to users. Graph at the moment only supports sending message in delegated (on behalf of user), while Bots only can send on their self (effectively application permissions).

    However from the call it looks like you are trying to create a chat between a user and a bot. Refer to https://learn.microsoft.com/en-us/microsoftteams/platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages on how to create a chat between a user and a bot.

    One the conversation is created (your bot will get a conversation event) refer to https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-conversations

    0 comments No comments

0 additional answers

Sort by: Most helpful