Reputation: 482
I am trying to send messages to MS Teams using Graph API using the following code.
List<Recipient> recipients = new List<Recipient>();
recipients.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = "[email protected]"
}
});
// Create the message.
Message msg = new Message
{
Body = new ItemBody
{
Content = "Test message3",
ContentType = BodyType.Text,
},
ToRecipients = recipients
};
_graphServiceClient.Users["fe0bb333-3334c49-a3eb-25af61fed1db"].SendMail(msg, true).Request().PostAsync().Wait();
This code does not send message in MS Team but instead send that message in email.
I am following the documentation https://learn.microsoft.com/en-us/graph/api/message-send?view=graph-rest-1.0 and was tyring Graph Explorer to send message but not working.
Request Body
{ "Body": "Hello World" }
But, I get following error from Graph Explorer:
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "9cddabed-f886-4c89-be8b-7b5735ad957f",
"date": "2019-04-21T05:37:11"
}
}
}
Upvotes: 3
Views: 29241
Reputation: 51
The Teams API allows creating new chats, as well as sending messages to existing ones.
Send messages to existing chats
List chats to retrieve the ID of an existing chat
Other options
If you're agnostic to how you send messages to users, you may be interested in sending proactive messages and proactive messaging for bots.
Upvotes: 5