如何使用Graph API在MS团队中发布消息

问题描述 投票:0回答:1

我正在尝试使用以下代码使用Graph API向MS团队发送消息。

 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();

此代码不会在MS Team中发送消息,而是在电子邮件中发送该消息。

我正在关注文档https://docs.microsoft.com/en-us/graph/api/message-send?view=graph-rest-1.0并且正在使用Graph Explorer发送消息但不能正常工作。

发布:https://graph.microsoft.com/v1.0/users/fe0bb333-3335-4c49-a3eb-25af61fed1db/messages/22229b36-a7cb-4a33-a9f9-dd75742bf067/send

请求机构

{“身体”:“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"
        }
    }
}
c# microsoft-graph microsoft-teams
1个回答
0
投票

今天,图中Microsoft团队的API仅支持向频道发送消息,而不是向用户发送消息(私人聊天)。正如您所看到的here,只列出了渠道运营。

© www.soinside.com 2019 - 2024. All rights reserved.