【发布时间】:2021-09-03 11:17:01
【问题描述】:
我们有一些代码在过去 10 个月(自开发以来)一直在工作,今天下午才停止工作。这是一个 WebAPI 代码,用于发送提及机器人和用户的频道消息,现在返回“错误请求。发送了无效的请求正文。”
如果未提供“提及”属性,则调用有效,并且消息在没有@提及的情况下发送。所以,我想知道这个 API 是否发生了重大变化,现在期待“提及”属性采用不同的格式。
按照the Microsoft Graph documentation中的示例代码进行复制非常简单。
我在这里发帖是希望一些开发人员发现一些明显的东西,或者知道使用 API 的另一种方式,它可能会停止抱怨,因为微软需要永远回复。
以下是我们拥有的可以引导我发现问题的代码:
private async Task SendMentionToTheBotAsync(GraphServiceClient onBehalfOfClient, string userName, string teamId, string channelId)
{
var supportAgentUser = await onBehalfOfClient.Me.Request().GetAsync();
var chatMessage = new ChatMessage
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = $"<at id=\"0\">{Configuration["BotName"]}</at>: This is the start of the conversation between {userName} and <at id=\"1\">{supportAgentUser.DisplayName}</at>."
},
Mentions = new List<ChatMessageMention>
{
new ChatMessageMention
{
Id = 0,
MentionText = Configuration["BotName"],
Mentioned = new IdentitySet
{
Application = new Identity
{
DisplayName = Configuration["BotName"],
Id = Configuration["BotAppId"],
AdditionalData = new Dictionary<string,object>
{
{
"applicationIdentityType", "bot"
}
}
}
}
},
new ChatMessageMention
{
Id = 1,
MentionText = supportAgentUser.DisplayName,
Mentioned = new IdentitySet
{
User = new Identity
{
DisplayName = supportAgentUser.DisplayName,
Id = supportAgentUser.Id,
AdditionalData = new Dictionary<string,object>
{
{
"userIdentityType", "aadUser"
}
}
}
}
}
}
};
await onBehalfOfClient.Teams[teamId].Channels[channelId].Messages
.Request()
.AddAsync(chatMessage);
}
【问题讨论】:
-
如果你想让 webapi 方面的专家来看看这个,你应该更加小心你的标签。添加相关的webapi标签,去掉graph标签。
标签: asp.net-web-api graph send channel mention