如何在一定条件下在botbuilder-v3上从QnAMakerDialog(常见问题解答类型聊天机器人)调用Formflow对话框或普通对话框

时间:2019-01-08 11:13:51

标签: c# azure botframework qnamaker formflow

我的情况如下。

我是Bot-framework的新手,他制作了一个聊天机器人,可通过KB服务与QnA-Maker类型进行通信,并根据返回的特定答案,尝试通过FormFlow调用或启动引导式对话。我正在使用SDK-V3(C#.net)和QnAMakerDialog。

在特定条件下,是否可以在botbuilder-v3上从QnAMakerDialog调用Formflow对话框?

谢谢

1 个答案:

答案 0 :(得分:0)

第一件事:如果您现在就开始使用,则不应该使用SDK-V3:请使用v4,该版本通常可以使用几个月。 v3将来不会发展(除了一些补丁程序)。

然后,使用QnA Maker来查看v4的示例,这里为:https://github.com/Microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/11.qnamaker/QnAMaker/QnABot.cs

在此示例中,您可以看到可以在QnABot.cs中实现逻辑:

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    // Handle Message activity type, which is the main activity type for shown within a conversational interface
    // Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
    // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
    if (turnContext.Activity.Type == ActivityTypes.Message)
    {
        // Check QnA Maker model
        var response = await _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);
        if (response != null && response.Length > 0)
        {
            // PUT YOUR LOGIC HERE
            //await turnContext.SendActivityAsync(response[0].Answer, cancellationToken: cancellationToken);
        }
        else
        {
            var msg = @"No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs. 
                To see QnA Maker in action, ask the bot questions like 'Why won't it turn on?' or 'I need help'.";

            await turnContext.SendActivityAsync(msg, cancellationToken: cancellationToken);
        }
    }
    else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
    {
        if (turnContext.Activity.MembersAdded != null)
        {
            // Send a welcome message to the user and tell them what actions they may perform to use this bot
            await SendWelcomeMessageAsync(turnContext, cancellationToken);
        }
    }
    else
    {
        await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected", cancellationToken: cancellationToken);
    }
}