如何在Microsoft Bot Framework中给出延迟的响应 [英] How do I give a delayed response in Microsoft Bot Framework

查看:93
本文介绍了如何在Microsoft Bot Framework中给出延迟的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Bot Framework FormFlow来吸引用户填写表单.完成此操作后,Dialog结束,并执行为ResumeWith参数指定的方法(在本例中为quoteComplete):

I am using Microsoft Bot Framework FormFlow to get a user to complete a form. Having completed it that Dialog ends and the method specified for the ResumeWith parameter (in this case quoteComplete) is executed:

var quoteForm = new FormDialog<Quote>(new Quote(), 
    quoteFormBuilder.BuildForm, FormOptions.PromptInStart);

context.Call<Quote>(quoteForm, quoteComplete);

quoteComplete中,我希望机器人告诉用户它正在获取报价,这可能需要几秒钟.然后执行一个异步调用来执行报价,然后返回它,我希望机器人显示另一条带有报价值的消息:

In quoteComplete I want the bot to tell the user that it is getting a quote and that it may takes a few seconds. An async call to perform the quote is then done and on it's return I want the bot to show another message with the value of the quote:

await context.PostAsync("I will now calculate your quote. I won't be long...");
context.Wait(MessageReceived);

//Simulate getting the quote
Task.Delay(5000).ContinueWith(t =>
{
    context.PostAsync("Your quote is £133.54");
});

我还尝试了将文档放在Delay().ContinueWith中来发送多份答复的文档中的以下建议:

I also tried following advice in the documentation for sending multiple replies by putting this in the Delay().ContinueWith:

var message = context.MakeMessage();
message.Text = "Your quote is for £133.54";
var connector = new ConnectorClient();
connector.Messages.SendMessage(message);

但是我得到一个Access Denied错误.

推荐答案

尝试通过以下方式实例化客户端

Try instantiating the client in the following way

using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
     var client = scope.Resolve<IConnectorClient>();
     client.Messages.SendMessage(message);
}

这篇关于如何在Microsoft Bot Framework中给出延迟的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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