在Waterfallstep对话框中等待Even类型的Activity(机器人框架4.0) [英] Wait for Even type Activity in a waterfallstep dialog (bot framework 4.0)

查看:50
本文介绍了在Waterfallstep对话框中等待Even类型的Activity(机器人框架4.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在瀑布步骤对话框中等待并接收事件类型的活动.我使用Directline 3.0,并在对话框流程中将事件从漫游器发送到客户端.之后,我想将一个事件从客户端发送到机器人,作为对先前发送的答复.如果我使用提示await dc.Prompt("waitEvent",activity),其中waitEvent是文本提示,并且我回答一条消息,则可以正常工作,但我想通过事件来回答事件.我当时以为我可以编写自定义提示,但找不到文档,显然可以管理对话流程,但是我更愿意在可能的地方使用对话框

It's possible to wait and receive an Event type activity in a waterfall step dialog. I use directline 3.0 and inside a dialog flow I send an event from the bot to the client. After i would like to send an event from the client to the bot as an answer to previous send. If i use prompt await dc.Prompt("waitEvent",activity) where waitEvent is a textprompt and i answer with a message it works fine but I would like to answer to an event with an event. I was thinking that i could write a custom prompt but i didn't find documentation and obviously I could manage the conversation flow but I prefer use Dialogs where possible

推荐答案

您可以使用

You can use the ActivityPrompt abstract class to build an "EventActivityPrompt" class.

尚无此用法的BotFramework示例,但有

There aren't any BotFramework samples of this usage yet, but there are new tests written by the BotFramework team that you can use as an example.

要创建自己的EventActivityPrompt,只需像下面这样实现ActivityPrompt:

To create your own EventActivityPrompt, you just need to implement the ActivityPrompt like so:

public class EventActivityPrompt : ActivityPrompt
{
    public EventActivityPrompt(string dialogId, PromptValidator<Activity> validator)
        : base(dialogId, validator)
    {
    }
}

ActivityPrompt和其他提示(除其 abstract 状态之外)的核心区别在于,为了验证用户输入,ActivityPrompts需要 PromptValidator< Activity> .

The core difference between an ActivityPrompt and other Prompts (besides its abstract status) is that ActivityPrompts require a PromptValidator<Activity>, in order to validate the user input.

下一步是创建验证器.这是示例:

The next step is to create your validator. Here is the example:

async Task<bool> _validator(PromptValidatorContext<Activity> promptContext, CancellationToken cancellationToken)
    {
        var activity = promptContext.Recognized.Value;
        if (activity.Type == ActivityTypes.Event)
        {
            if ((int)activity.Value == 2)
            {
                promptContext.Recognized.Value = MessageFactory.Text(activity.Value.ToString());
                return true;
            }
        }
        else
        {
            await promptContext.Context.SendActivityAsync("Please send an 'event'-type Activity with a value of 2.");
        }
        return false;
    }

这篇关于在Waterfallstep对话框中等待Even类型的Activity(机器人框架4.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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