Azure 对bot中断的支持

Azure 对bot中断的支持,azure,botframework,Azure,Botframework,您知道是否有实现全局消息处理程序的方法可以支持stop、bye、cancel、exit等命令吗?我正在尝试实现类似的东西 我已经构建了一个虚拟助手,它有两个 当用户使用某项技能进行多回合对话时,用户应该能够通过stop、bye、cancel、exit等命令退出技能 我发现v4很旧,但什么都没有。检查这里提供的文档,它们解释了如何处理SDK v4的用户中断 下面是如何在虚拟助手中配置此功能的示例 在您的main对话框中.cs 为您的OnContinueDialogAsync添加以下内容:请记住,您

您知道是否有实现全局消息处理程序的方法可以支持stop、bye、cancel、exit等命令吗?我正在尝试实现类似的东西

我已经构建了一个虚拟助手,它有两个 当用户使用某项技能进行多回合对话时,用户应该能够通过stop、bye、cancel、exit等命令退出技能


我发现v4很旧,但什么都没有。

检查这里提供的文档,它们解释了如何处理SDK v4的用户中断

下面是如何在虚拟助手中配置此功能的示例

在您的main对话框中.cs

为您的OnContinueDialogAsync添加以下内容:请记住,您可以根据需要更改和编辑此内容。继续之前,请确保检查OnInterruptDialogAsync结果(本例中的状态)

  protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
    {
        var status = await OnInterruptDialogAsync(innerDc, cancellationToken).ConfigureAwait(false);

        if (status == InterruptionAction.Resume)
        {
            // Resume the waiting dialog after interruption
            await innerDc.RepromptDialogAsync().ConfigureAwait(false);
            return EndOfTurn;
        }
        else if (status == InterruptionAction.Waiting)
        {
            // Stack is already waiting for a response, shelve inner stack
            return EndOfTurn;
        }
        else
        {
            var activity = innerDc.Context.Activity;

            if (activity.IsStartActivity())
            {
                await OnStartAsync(innerDc).ConfigureAwait(false);
            }

            switch (activity.Type)
            {
                case ActivityTypes.Message:
                    {
                        // Note: This check is a workaround for adaptive card buttons that should map to an event (i.e. startOnboarding button in intro card)
                        if (activity.Value != null)
                        {
                            await OnEventAsync(innerDc).ConfigureAwait(false);
                        }
                        else
                        {
                            var result = await innerDc.ContinueDialogAsync().ConfigureAwait(false);

                            switch (result.Status)
                            {
                                case DialogTurnStatus.Empty:
                                    {
                                        await RouteAsync(innerDc).ConfigureAwait(false);
                                        break;
                                    }

                                case DialogTurnStatus.Complete:
                                    {
                                        // End active dialog
                                        await innerDc.EndDialogAsync().ConfigureAwait(false);
                                        break;
                                    }

                                default:
                                    {
                                        break;
                                    }
                            }
                        }

                        // If the active dialog was ended on this turn (either on single-turn dialog, or on continueDialogAsync) run CompleteAsync method.
                        if (innerDc.ActiveDialog == null)
                        {
                            await CompleteAsync(innerDc).ConfigureAwait(false);
                        }

                        break;
                    }

                case ActivityTypes.Event:
                    {
                        //do something for event activity
                        break;
                    }

                case ActivityTypes.Invoke:
                    {
                        // Used by Teams for Authentication scenarios.

                        break;
                    }

                default:
                    {
                        await OnSystemMessageAsync(innerDc).ConfigureAwait(false);
                        break;
                    }
            }

            return EndOfTurn;
        }
    }
受保护的覆盖异步任务OnContinueDialogAsync(DialogContext innerDc,CancellationToken CancellationToken=default(CancellationToken))
{
var status=await OnInterruptDialogAsync(innerDc,cancellationToken);
如果(状态==中断操作.恢复)
{
//中断后恢复等待对话框
wait innerDc.RepromptDialogAsync().ConfigureWait(false);
回报内翻;
}
else if(状态==中断操作.等待)
{
//堆栈已在等待响应,搁置内部堆栈
回报内翻;
}
其他的
{
var activity=innerDc.Context.activity;
if(activity.IsStartActivity())
{
等待OnStartAsync(innerDc).ConfigureAwait(false);
}
开关(activity.Type)
{
案例活动类型。消息:
{
//注意:此检查是应映射到事件的自适应卡按钮(即介绍卡中的startOnboarding按钮)的解决方法
if(activity.Value!=null)
{
await-OnEventAsync(innerDc).ConfigureAwait(false);
}
其他的
{
var result=await innerDc.ContinueDialogAsync().ConfigureAwait(false);
开关(结果状态)
{
案例对话框状态。空:
{
等待RouteAsync(innerDc)。配置等待(false);
打破
}
案例状态。完成:
{
//结束活动对话框
等待innerDc.EndDialogAsync().ConfigureAwait(false);
打破
}
违约:
{
打破
}
}
}
//如果活动对话框在此回合结束(在单回合对话框或continueDialogAsync上),请运行CompleteAync方法。
如果(innerDc.ActiveDialog==null)
{
等待完成同步(innerDc)。配置等待(false);
}
打破
}
案例活动类型。事件:
{
//为活动做点什么
打破
}
案例活动类型。调用:
{
//由团队用于身份验证场景。
打破
}
违约:
{
等待OnSystemMessageAsync(innerDc)。配置等待(false);
打破
}
}
回报内翻;
}
}
并覆盖OnInterruptDialogAsync,如下例所示: 此示例包括LUIS,但您可以在OnInterruptDialogAsync

   protected override async Task<InterruptionAction> OnInterruptDialogAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
    {
        var result = InterruptionAction.NoAction;

        if (dc.Context.Activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(dc.Context.Activity.Text))
        {
            // get current activity locale
            var localeConfig = _services.GetCognitiveModels();

            // check general luis intent
            localeConfig.LuisServices.TryGetValue("General", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Skill configuration.");
            }
            else
            {
                var luisResult = await luisService.RecognizeAsync<GeneralLuis>(dc.Context, cancellationToken);
                var topIntent = luisResult.TopIntent();

                if (topIntent.score > 0.5)
                {
                    switch (topIntent.intent)
                    {
                        case GeneralLuis.Intent.Cancel:
                            {
                                result = await OnCancel(dc);
                                break;
                            }

                        case GeneralLuis.Intent.Help:
                            {
                                result = await OnHelp(dc);
                                break;
                            }

                        case GeneralLuis.Intent.Logout:
                            {
                                result = await OnLogout(dc);
                                break;
                            }
                    }
                }
            }
        }

        return result;
    }
InterruptDialogAsync(DialogContext dc,CancellationToken CancellationToken=default(CancellationToken))上受保护的重写异步任务
{
var结果=中断作用。无作用;
if(dc.Context.Activity.Type==ActivityTypes.Message&&!string.IsNullOrEmpty(dc.Context.Activity.Text))
{
//获取当前活动区域设置
var localeConfig=_services.GetCognitiveModels();
//检查路易斯的总体意图
localeConfig.LuisServices.TryGetValue(“常规”,out-var-luisService);
if(luisService==null)
{
抛出新异常(“在您的技能配置中找不到指定的LUIS模型”);
}
其他的
{
var luisResult=await luisService.RecognizeAsync(dc.Context,cancellationToken);
var topIntent=luisResult.topIntent();
如果(topIntent.score>0.5)
{
开关(topIntent.intent)
{
案例generaluis.Intent.Cancel:
{
结果=等待一次取消(dc);
打破
}
案例generaluis.Intent.Help:
{
结果=awai