【发布时间】:2020-01-07 18:25:19
【问题描述】:
我有一个 Bot Framework V3 机器人代码库,该代码库在六个左右不同的客户 Teams 租户中运行,并且在我们的内部 Teams 租户中运行没有问题。
在一个特定的客户租户中,当我调用 ConnectorClient.Conversations.CreateConversationAsync() 时,尝试向团队频道创建主动消息失败并出现 ConversationNotFound 404 错误。
我创建对话并在频道中发布活动的代码如下所示:
var teamsChannelId = "19:deadbeef1234@thread.skype"; // insert the real channel ID obtained from lookups against Graph API...
var botCredentials = new MicrosoftAppCredentials(/* Bot ID & password */);
MicrosoftAppCredentials.TrustServiceUrl("https://smba.trafficmanager.net/amer/", DateTime.MaxValue);
using (var connectorClient = new ConnectorClient(new Uri("https://smba.trafficmanager.net/amer/"), botCredentials)) {
var botId = new ChannelAccount("28:" + botCredentials.MicrosoftAppId);
var msg = Activity.CreateMessageActivity();
msg.From = botId;
var card = MakeCard(); // builds an AdaptiveCard...
msg.Attachments.Add(new Attachment(AdaptiveCard.ContentType, content: card));
var parameters = new ConversationParameters() {
Bot = botId,
ChannelData = new TeamsChannelData() {
Channel = new ChannelInfo(teamsChannelId)
},
Activity = (Activity)msg
};
// This throws an Microsoft.Bot.Connector.ErrorResponseException with the code "ConversationNotFound"
ConversationResourceResponse convoResponse = await connectorClient .Conversations.CreateConversationAsync(parameters);
}
正如我最初提到的,这段代码可能并不完美,但它可以在许多不同的 Teams 和 Azure 环境中运行,但在这个特定环境中失败了。来自 Bot Framework 的 HTTP 响应如下所示:
"Response": {
"StatusCode": 404,
"ReasonPhrase": "Not Found",
"Content": "{\"error\":{\"code\":\"ConversationNotFound\",\"message\":\"Conversation not found.\"}}",
"Headers": {
"Date": [
"Wed, 04 Sep 2019 14:43:24 GMT"
],
"Server": [
"Microsoft-HTTPAPI/2.0"
],
"Content-Length": [
"77"
],
"Content-Type": [
"application/json; charset=utf-8"
]
}
堆栈跟踪:
Microsoft.Bot.Connector.ErrorResponseException: Operation returned an invalid status code 'NotFound'
at Microsoft.Bot.Connector.Conversations.<CreateConversationWithHttpMessagesAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.ConversationsExtensions.<CreateConversationAsync>d__3.MoveNext()
- 机器人能够处理传入的 1-1 聊天对话,而不会出现通过网络聊天、直线和团队连接器的问题,因此我认为机器人凭据或机器人注册配置没有任何问题。
- 该机器人已作为 Microsoft Teams 的应用添加、上传到租户并添加到相应的团队。
- 我已经探索了 Azure 中 Bot Framework 注册区域可能会导致问题的可能性,但我已经在我们端重现了客户端的配置,但无法重现问题。
非常欢迎任何建议。
【问题讨论】:
-
请不要硬编码
serviceURL值。当用户向您的机器人发送消息时,传入请求包含一个带有serviceUrl属性的 Activity 对象,该属性指定您的机器人应向其发送响应的端点。请使用特定租户的服务 URL,然后重试。 -
我没有有效的传入响应 - 这是一条主动消息,它通过与来自用户的任何传入请求不同的渠道发送。是否有一个列表记录了可用的服务 URL 是什么以及它们应该对应什么?这是令人沮丧的,因为所有的地狱都试图在 Bot Framework 的快乐路径之外做任何适度的事情,因为记录的太少,而被混淆的太多。
-
你能用我的回答来解决这个问题吗?如果是这样,请“接受”并投票,以便其他人可以快速找到答案,我可以从我的支持跟踪器中清除它。如果没有,请告诉我我还能提供哪些帮助!
标签: botframework microsoft-teams