我正在尝试通过以下代码使用Graph API向MS Teams发送消息。
List<Recipient> recipients = new List<Recipient>();
recipients.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = "user1@abctest.onmicrosoft.com"
}
});
// 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();
此代码不会在MS Team中发送消息,而是通过电子邮件发送该消息。
我正在遵循https://docs.microsoft.com/en-us/graph/api/message-send?view=graph-rest-1.0文档,并尝试使用Graph Explorer发送消息但不起作用。
请求正文
{ “正文”:“ Hello World” }
但是,我从Graph Explorer中收到以下错误:
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "9cddabed-f886-4c89-be8b-7b5735ad957f",
"date": "2019-04-21T05:37:11"
}
}
}
答案 0 :(得分:1)
截至2020年10月的更新
Teams API现在支持使用send ChatMessage.
直接向用户发送消息但是,您无法创建新的聊天,只能在现有的聊天中创建新消息:
此API无法创建新的聊天;您必须先使用list chats方法来检索现有聊天的ID,然后再创建聊天消息。
如果您不知道如何向用户发送消息,则可能对sending proactive messages和proactive messaging using a bot in Microsoft Teams.感兴趣
答案 1 :(得分:0)
如今,图表中Microsoft Teams的API仅支持将消息发送到通道,而不是发送给用户(私人聊天)。如您所见,here仅列出了通道操作。