将代码从Bot Framework V3迁移到V4 [英] Migrating the code from Bot Framework V3 to V4

查看:91
本文介绍了将代码从Bot Framework V3迁移到V4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将对话框从V3迁移到V4时,我还有更多问题.下面是我们的代码. 在v3中,我们使用

I have more question while migrating the dialog from V3 to V4. below is our code. In v3, we were using

Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync(conversationContext.CurrentActivity, new RootDialog());

public class RootDialog : IDialog {
    public RootDialog()
    {
      .....
    }

    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(this.MessageReceivedAsync);
    }

    public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
    }

在MessageReceivedAsync中,我们使用了context.Wait(),context.Done()和context.PostAsync(). 您能推荐如何在V4中更换吗? V4中对Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync的警告是什么?

In the MessageReceivedAsync, we used the context.Wait(), context.Done() and context.PostAsync(). Can you recommend how to replace in the V4? And what's the alertnative for Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync in V4?

推荐答案

这些API均已消失.以下是在V4中替换它们的说明:

These APIs are all gone. Here are the explanations of their replacements in V4:

此方法用于告诉对话框系统当新活动到来且现在消失时,下一步要在类上调用的方法.相反,您现在是Dialog的子类,并为各种生命周期事件重写了几种方法:

This method was used to tell the dialog system what method to invoke next on your class when a new activity arrived and is now gone. Instead you now subclass Dialog and override several methods for various lifecycle events:

  • BeginDialogAsync-在第一次由机器人代码将对话框推入堆栈或在DialogContext上的另一个对话框调用BeginDialogAsync时调用.
  • ContinueDialogAsync-当有新活动进入并且机器人在DialogContext上调用ContinueDialog时调用.
  • ResumeDialogAsync-在堆栈上的另一个对话框完成并且以前在堆栈上的对话框现在位于堆栈顶部时调用.
  • RepromptDialogAsync-在显式请求重新提示用户时调用.基本上,这是一种告诉对话框什么都没有改变的方法,但是它应该通过发送上次发送的活动从再次中断的地方重新开始.
  • EndDialogAsync-在对话框指示其已完成并从堆栈中弹出时调用.
  • BeginDialogAsync - called when the dialog is first pushed on the stack by bot code or another dialog calling BeginDialogAsync on the DialogContext.
  • ContinueDialogAsync - called when a new activity comes in and the bot calls ContinueDialog on the DialogContext.
  • ResumeDialogAsync - called when another dialog on the stack has completed and a dialog that was previously on the stack is now at the top of the stack.
  • RepromptDialogAsync - called when an explicit request has been made to reprompt the user. This is basically a way to tell the dialog that nothing has changed, but that it should pick up from where it left off again by sending whatever activity it last sent.
  • EndDialogAsync - called when the dialog has indicated its done and is being popped off the stack.

这是报告对话框状态的一种方式,但是现在可以通过上述大多数生命周期方法返回DialogTurnResult来实现.其中一个属性名为Status,其类型为DialogTurnStatus,其值指示对话框的当前状态.例如:

This was one of the way you reported the status of your dialog, but this is now accomplished by returning a DialogTurnResult from most of the aforementioned lifecycle methods. One of the properties is named Status and is of type DialogTurnStatus which has values that indicate the current state of the dialog. For example:

  • Waiting-对话框发送了一些活动,正在等待更多输入,应保留在堆栈的顶部.
  • Complete-对话框已完成工作,应结束并从堆栈中弹出.返回此状态时,调用者还可以调查通过DialogTurnResult::Result属性传递回的对话框的输出(如果有).
  • Cancelled-对话框在其工作过程中被取消.
  • Waiting - the dialog sent some activities and is awaiting more input and should remain at the top of the stack.
  • Complete - the dialog has completed it's work and should be ended and popped off the stack. When this state is returned, callers can also investigate the output of the dialog (if it has one) which is passed back via the DialogTurnResult::Result property.
  • Cancelled - the dialog was cancelled part of the way through its work.

这些都用于回复用户.现在都可以通过在ITurnContext上调用SendActivityAsync来替换,这可以通过DialogContext实例的Context属性访问,该属性作为参数传递到上述大多数生命周期方法中.注意:几个生命周期方法实际上实际上直接接收到ITurnContext参数,然后您就可以使用它.

These were both used to respond back to the user. Both are now replaced by calling SendActivityAsync on the ITurnContext that is accessible via the Context property of the DialogContext instance that is passed into most of the aforementioned lifecycle methods as a parameter. NOTE: a couple of the lifecycle methods actually receive an ITurnContext parameter directly and then you just use that.

这篇关于将代码从Bot Framework V3迁移到V4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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