0
votes

I'm trying to send a message to MS Teams using Graph API. I'm passing access token (AAD token) with it but still, it's giving me below error. I have given all the required permissions in Azure API permissions. error:

{
  "error": {
    "code": "UnknownError",
    "message": "",
    "innerError": {
      "request-id": "53a5aaff-3d39-42ce-bdc6-74d02a756be2",
      "date": "2019-12-23T06:42:27"
    }
  }
}

API: https://graph.microsoft.com/beta/teams/{group-id-for-Teams}/channels/{channel-id}/messages/{message-id}/replies

2
What is the request header and body for both getting access token and POST graph.microsoft.com/beta/teams{group-id-for-teams}/channels/{channel-id}/messages/{message-id}/replies? And what permission did you add in Azure AD app. Please share more details. It is best to provide a screenshot of the permissions that have been assigned. You can firstly test this API in Microsoft Graph Explorer to determine if the problem lies in the access token. - Allen Wu
I see you added the botframework tag. Any reason you're using the Graph API instead of the bot? If you're trying to send a message as the bot, you'll still need the bot installed to the channel you want to send to. - mdrichardson
Bot will be installed to the channel where i'll be sending the message. I have used graph api as my solution from where i'm sending message is not in teams environment rather its a stand alone azure function. - Mayuresh Jaiswal

2 Answers

1
votes

Oh, if this is from a bot (not clear from the original question, but clarified in your later comment) then you don't need to use the Graph API at all - there's another way to send the message using the Bot Framework tools instead. You can do this either from within your bot, or from a different application altogether. I've got a few bots where the user schedules something, like when they want a message sent, where the bot saves it to a database and I have another application (mostly I use Azure Functions right now) to send the item on that schedule.

There are some important pieces of information you need to store though, which you can get any time the users sends your bot a message - it's the information you need to store so that you know how to connect directly to that user and that conversation. It's called Pro-active Messaging, and to see how to do this, see the answer I posted at Programmtically sending a message to a bot in Microsoft Teams

If you DON'T have any conversation history with the user ever (as in they have never spoken with your bot before, and you're trying to send the first message) then it gets more complicated... Let me know if that's the case though.

0
votes

Sending message to a channel using graph api is a protected api and it needs access permission from Microsoft. Access can be requested from Microsoft access reuqest form. Once access is given from Microsoft add graph api in api permissions of your web app, and bingo you can get the response.