带有几个机器人的Bot Framework对话框

时间:2017-07-01 19:49:33

标签: c# botframework

使用Bot Framework,我试图让2个机器人进行通信。这是我的情景。我有两个机器人:

  • Bot A:插入LUIS的通用机器人
  • Bot B:基于LUIS意图的专业机器人

用户可以与每个机器人交谈。

这就是我想要做的: 在Bot A的对话框中,Bot A调用LUIS,获取意图,然后调用通过REST公开的Bot B的业务方法。

Bot A

切入点:

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        if (activity.Type == ActivityTypes.Message)
        {
            await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
        }
        else
        {
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

RootDialog:

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);

        return Task.CompletedTask;
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;

        var intents = await GetIntents(activity); // get the intents from LUIS

        var result = await GetBusinessOperation(activity, intents); // call a WebAPI which call method PerformResponse from Bot B according to the LUIS intent

        await context.PostAsync(result); // return our reply to the user

        context.Wait(MessageReceivedAsync);
    }
}

Bot B

在Bot B中,我想创建一个与用户交互的新对话框。 Bot B通过REST API从Bot A获得Activity对象。

 [Authorize]
    public async override Task<HttpResponseMessage> PostPerformResponse([FromBody]Model model)
    {
        Activity activity = model.Activity;

        MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);

        await Conversation.SendAsync(activity, () => new BusinessDialog()); // This creates a new dialog but it will not be linked to the dialog created in Bot A. This results in an error 412 when the framework try to do SetBotData() at the end of dialog in Bot A

        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

根据我的理解,创建一个我需要调用的新对话框:

context.Call(new BusinessDialog(), this.CallbackMethod);

context.Forward(new BusinessDialog(), this.CallbackMethod, activity, CancellationToken.None);

问题是IDialogContext context对象不可序列化,无法通过REST调用从Bot A发送到Bot B.

在Bot B中,我可以创建一个初始对话框,就像我在Bot A中所做的那样。它运行正常,但是当框架自动调用方法setBotData()时,我在Bot A的对话框结束时出现错误412。我相信这是因为Bot B中的对话框不是使用context.Call()context.Forward()创建的。

您是否有任何想法如何访问Bot B中的IDialogContext context或有关管理机器人之间对话的任何想法?

此致

0 个答案:

没有答案