我有一个机器人可以移交给人类操作员。
运营商加入后,我在“ OnEventActivityAsync”事件中收到一个事件。
那时,我想向客户端发送一条消息,告知他们已与操作员连接。
如何更改turnContext / Activity将消息发送给客户端?
不完全确定要发布的代码部分。 (由于公司政策而无法发布整个项目)
protected override async Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
if (turnContext.Activity.Name == "webchat/agentJoin")
{
_logger.LogInformation("webchat/agentJoin");
//Database stuff here
await turnContext.SendActivityAsync(MessageFactory.Text("Connected to customer"), cancellationToken);
//How do I send a message to the client here? turnContext sends the message to the agent, not client
}
}
答案 0 :(得分:0)
请参阅以下GitHub链接实验中的协议定义:
https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/handoff-library
工厂方法
SDK将包括以下工厂方法,以帮助创建指定的事件:
C#:
namespace Microsoft.Bot.Builder
{
public static class EventFactory
{
public static IEventActivity CreateHandoffInitiation(
ITurnContext turnContext,
object handoffContext,
Transcript transcript);
public static IEventActivity CreateHandoffResponse(
ConversationAccount Conversation,
string code);
public static IEventActivity CreateHandoffCompleted(
ConversationAccount Conversation,
string code,
Transcript transcript);
}
}
协议代码定义如下:
namespace Microsoft.Bot.Schema
{
public static class HandoffCodes
{
public const string Accepted = "accepted";
public const string Failed = "failed";
public const string TimedOut = "timedOut";
public const string EndOfConversation = "endOfConversation";
public const string TransferBack = "transferBack";
}
}
答案 1 :(得分:0)
由于Mick的建议,我又对主动消息进行了研究。 我之前已经看过它,但是由于“未经授权”的错误而从未使它起作用。 现在我注意到有针对该特定问题的修复程序。
该代码基于MS文档,用于发送主动通知: Send proactive Notifications
所以我要做的是:
turnContext.Adapter.ContinueConversationAsync(_appId, conversationReference, BotCallback, default(CancellationToken));
private async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken)
{
// If you encounter permission-related errors when sending this message, see
// https://aka.ms/BotTrustServiceUrl
await turnContext.SendActivityAsync("You're now connected to: Ted");
}