azure - 在没有 Teams-Context 的情况下可以与 Microsoft Teams 的 Bot Framework 发起主动对话吗?

标签 azure botframework

我基本上是在尝试与 Microsoft Bot Framework 创建主动对话。我使用以下代码成功地为 Skype for BUsiness 做到了这一点:

string serviceUrl = "https://api.skypeforbusiness.com/platformservice/botframework";
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);

var connector = new ConnectorClient(new Uri(serviceUrl), "{app-id}", "{app-password}");

var user = new ChannelAccount("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31505f481c444254431c44415f71555e5c50585f1f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>", "Name of User");
var bot = new ChannelAccount("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b6bba0f9a1a4ba94b7b5b9a4b5bab5f9a7b7bcbba0a0fab7bbb9" rel="noreferrer noopener nofollow">[email protected]</a>", "Name of bot");

ConversationParameters cpMessage = new ConversationParameters(true, bot, new List<ChannelAccount> { user }, "Topic of the conversation");

ConversationResourceResponse response = await connector.Conversations.CreateConversationAsync(cpMessage);

启动对话后,我可以向用户发送消息,效果很好。但对于 MS Teams,我有两个问题: 1. 哪个 serviceURL 是正确的?我发现了一些提示,包括以“https://smba.trafficmanager.net …”开头的网址,但它们都不起作用,我总是收到异常“错误请求”。

第二个问题:我是否需要 Teams 上下文(Teams ID)来实际发布消息,或者是否可以(如我使用 Skype 的示例)发起与用户的聊天?

编辑:我尝试添加channelData (teamsChannelId) 并使用服务URL“https://smba.trafficmanager.net/emea-client-ss.msg ” - 然后我得到响应代码“Forbidden”。 这让我想到了一个问题:是否真的可以在没有任何团队上下文(只是聊天)的情况下向团队发起对话?

提前致谢, 马丁

最佳答案

所以,我想我自己找到了答案:

以下代码适用于 MS Teams 主动编写(机器人服务 v3):

string serviceUrl = "https://smba.trafficmanager.net/emea/";
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);

var connector = new ConnectorClient(new Uri(serviceUrl), botAppId, appSecret);
var teamsBotAccount = new ChannelAccount("28:<BOT-APP-ID>", "Smart Office Bot");
var teamsUserAccount = new ChannelAccount("29:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_x", "Martin");

ConversationResourceResponse response = connector.Conversations.CreateOrGetDirectConversation(teamsBotAccount, teamsUserAccount, "9e73e135-fe7a-447f-baba-b0312d3aa55d");

关键点是要发送消息的用户的 ChannelAccount ID。我的第一个误解是,MS Teams 的 channel 帐户 ID 也适用于电子邮件 - 事实并非如此。 MS Teams 的 channel 帐户是神秘的,而且是特定于 channel 的。

这意味着:消息接收者的 ChannelAccount 中使用的用户 ID 仅存在于 Channel Context 中。对于直接 1:1 聊天,我的用户在每次聊天中似乎都有不同的 ID。

我的结论:问题不在于 Bot Framework,而在于 MS Teams,它根本不支持从自动化组件发起聊天。正如我通过其他类似线程得出的结论,故意不支持它以防止垃圾邮件(不幸的是,它非常不一致 - 这显然不适用于 Skype for Business)。

关于azure - 在没有 Teams-Context 的情况下可以与 Microsoft Teams 的 Bot Framework 发起主动对话吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54341199/

相关文章:

rest - 通过 RESTful API 将新的/更新的应用程序版本部署到 Azure Batch 服务?

azure - 对象合并失败

azure - 使用 Azure Web 功能接收 Twilio SMS 消息

azure - 我应该在 Azure 文件存储中存储哪些文件?

c# - 机器人框架 V4 : Reset Bot in Messenger

c# - 使用 Entity Framework 6 中的环境变量在暂存/生产数据库之间切换

c# - 直接 channel 机器人发布问题(机器人框架 V4)

node.js - 等待 Microsoft Bot Framework 中的事件

azure - 如何在 Microsoft Azure Bot 框架中查看错过的用户话语