为没有团队的Microsoft团队发起与Bot Framework的主动对话-上下文可能吗? [英] Initiate Proactive Conversation with Bot Framework for Microsoft Teams without Teams-Context possible?

查看:20
本文介绍了为没有团队的Microsoft团队发起与Bot Framework的主动对话-上下文可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上是在尝试创建与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("any-user-upn@domain.com", "Name of User");
var bot = new ChannelAccount("bot-upn@campana-schott.com", "Name of bot");

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

ConversationResourceResponse response = await connector.Conversations.CreateConversationAsync(cpMessage);
在发起会话后,我可以向用户发送消息,工作正常。但是对于微软团队,我有两个问题: 1.哪个serviceURL是正确的?我发现了几个提示,包括以"https://smba.trafficmanager.net…"开头的URL但是他们都不管用,我总是收到一个例外的"坏请求"。

第二个问题:我是否需要团队上下文(团队ID)才能实际发布消息,或者(就像我的Skype示例中那样)是否可以只发起与用户的聊天?

编辑:我尝试添加channelData(Team SChannelId)并使用服务URL"https://smba.trafficmanager.net/emea-client-ss.msg"-然后得到响应代码"禁止"。 这就引出了一个问题:在没有任何团队上下文(只是聊天)的情况下,在团队中发起对话真的是可能的吗?

提前感谢, 马丁

推荐答案

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

以下代码可供MS团队主动编写(Bot Services 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。我的第一个误解是,微软团队的渠道账户ID也适用于电子邮件-事实并非如此。MS团队的ChannelAccount是隐晦的,而且是特定于渠道的。

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

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

这篇关于为没有团队的Microsoft团队发起与Bot Framework的主动对话-上下文可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆