问题描述
使用 https://portal.azure.com
,我设法创建了 QnA Bot
.
我还设法从 Bot Framework Emulator
向bot的 MS Teams
和 Test Web Chat
发送了一条消息.(尽管到目前为止,它是非常静态的,并且是手动完成的)
I also managed to send a message from the Bot Framework Emulator
to MS Teams
and the Test Web Chat
of the bot. (Though it is very static and manually done as of now)
我从 https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
获得了我的 Token
.使用该 Token
,我可以将消息发送到 https://smba.trafficmanager.net/emea/v3/conversations/ConversationID/activities
(这是 Teams
),然后我可以向 https://webchat.botframework.com/v3/conversations/ConversationID/activities
(这是 Test Web Chat
)发送一条消息
I get my Token
from https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
. With that Token
I can send a message to https://smba.trafficmanager.net/emea/v3/conversations/ConversationID/activities
(which is Teams
) and I can send a message to https://webchat.botframework.com/v3/conversations/ConversationID/activities
(which is the Test Web Chat
).
有点题外话:由于我是Azure的新手,所以我想知道到目前为止所做的一切是否正确或完全错误?
Little bit offtopic: Since I'm new to Azure I wonder if everything done so far is fine or completly false?
反正...
到目前为止,我的目标是在 Test Web Chat
中编写消息时,该消息也应最终出现在 MS Teams
中.然后,我要从 Teams
回答诸如 @Bot这是我的答案
之类的消息.然后,团队答案"也应该以 Test Web Chat
结尾.(因此,基本上 Team
和 Web Chat
之间的通信)
My goal so far is that when writing a message in the Test Web Chat
the message should also end up in MS Teams
. Then from Teams
I want to answer to the message like @Bot This is my Answer
. This Answer in Teams should then also end up in the Test Web Chat
. (So basically communication between Teams
and Web Chat
)
什么是最好的方法?
我当时在考虑Azure中的后端,但是我不知道可以使用什么以及是否可以使用.
I was thinking of a backend in Azure but I don't know what would be possible to use and if it's even possible.
我的想法是:
已发送消息网络聊天
.在代码中,我会将 Web聊天会话
信息上载到 Azure
.同样在团队中,现在有与 Web Chat
中编写的消息相同的消息.还需要立即上传 Teams
中的会话ID,并且需要更新 Web Chat
发送到的会话ID(这是必需的,因此不会向其发送垃圾邮件一个会话中 Teams
中新的线程/消息,并且此 Web Chat
会话中的所有消息现在都在一个线程中.)现在在会话中进行回答通过
我会编写并发送答案.在发送答案之前,我需要来自 Team
进行网络聊天 Web Chat
的对话ID.因此Bot会从 Azure
下载信息,以便它知道将答案发送到何处.
A message is sent Web Chat
. In Code I would upload the Web Chat Conversation
Information to Azure
. Also in Teams there is now the same message that was written in Web Chat
. The Conversation ID in Teams
also needs to be uploaded now and the Conversation ID the Web Chat
is sending to needs to be updated (this would be needed so there is no spamming of new threads/messages in Teams
from one Conversation and all the messages from this Web Chat
Conversation are now in one thread.) Now to answer in the Conversation of the Web Chat
via Teams
I would write and send the answer. Before the sending of the answer happens I would need the Conversation ID from the Web Chat
. So the Bot would download the information from Azure
so it knows where it has to sent the answer to.
这是一个很好的方法,还是您知道更好的方法?另外,我可以使用Azure中的哪些资源来实现这一目标?
Is this a good apporach or do you know better ones? Also what ressources in Azure could I use to achieve this?
推荐答案
听起来您正在考虑正确的方法.基本上,您希望将两个对话参考(一个在团队中,另一个在网络聊天中)配对在一起,然后在两者之间转发消息.
It sounds like you are thinking about this the right way. Basically you want to pair two conversation references - one in Teams and the other in Web Chat - together and then forward the messages between the two.
BotFramework SDK v4(C#)
我建议创建两个函数- AddConversationReferenceAsync
和 GetConversationReferenceAsync
.在这些功能中,您应该管理如何存储,连接和检索对话引用.您可以检查频道ID- activity.ChannelId
-确定要如何处理引用.然后,您可以在 OnMessageActivityAsync
中添加和检索相应的会话引用,以将主动消息发送到其他通道.
I would recommend creating two functions - AddConversationReferenceAsync
and GetConversationReferenceAsync
. In those functions, you should manage how you store, connect, and retrieve conversation references. You can check the channel Id - activity.ChannelId
- to determine how you want to handle the reference. Then in OnMessageActivityAsync
you can add and retrieve the corresponding conversation references to send a proactive message to the other channel.
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
AddConversationReferenceAsync(turnContext.Activity as Activity);
var conversationReference = GetConversationReferenceAsync(turnContext.Activity as Activity);
if (conversationReference != null) {
await turnContext.Adapter.ContinueConversationAsync(_appId, conversationReference, (ITurnContext context, CancellationToken cancellationToken) => {
await context.SendActivityAsync(turnContext.Activity);
}, cancellationToken);
} else {
await turnContext.SendActivityAsync("You are not connected to anyone at the moment");
}
}
屏幕截图
我建议您查看BotBuilder 主动消息示例,并 @tompaana 构建了湖南交接机器人示例,该示例将Teams和Slack中的对话联系起来,可能会有所帮助.
I would recommend looking at the BotBuilder Proactive Messaging sample, and @tompaana built a Hunan Handoff Bot sample that connects conversations in Teams and Slack that might be helpful.
希望这会有所帮助!
这篇关于团队之间的通讯和通过Bot进行的网络聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!