有没有办法在对话更新中放入即时选择并告诉您选择会做什么?

时间:2019-04-16 13:39:20

标签: c# botframework bots

我们目前正在使用主动聊天机器人,我们希望通过欢迎文本和及时的选择来欢迎用户。我可以做出提示选择以进行对话更新,但是不确定respone = yes时该怎么做。

我已经尝试过放入“主”对话框,但是您无法进行对话更新。使用瀑布法。

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    //original
    if (turnContext == null)
    {
        throw new ArgumentNullException(nameof(turnContext));
    }

    //Welcome user when they join the conversation
    if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
    {
        if (turnContext.Activity.MembersAdded != null)
        {
            foreach (var member in turnContext.Activity.MembersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    await turnContext.SendActivityAsync($"Ah yes, {WelcomeText}", cancellationToken: cancellationToken);
                    var dialogContext = await dialogs.CreateContextAsync(turnContext, cancellationToken);
                    await dialogContext.PromptAsync("choicePrompt",
                        new PromptOptions
                        {
                            Prompt = dialogContext.Context.Activity.CreateReply(" Your task:  + taskName +  failed because of the following error message: it wasn't able to Auto Login to the runner."),
                            Choices = new[] { new Choice { Value = "Rerun your Task" }, new Choice { Value = "No" } }.ToList()
                        }
                    );
                }
            }
        }
    }
}

我希望输出为“选择”,然后重新运行任务,否。如果他们拒绝,请结束对话。

1 个答案:

答案 0 :(得分:0)

您不应将constructionUpdate用作问候用户的一种方式。如该blog中所述,当漫游器和用户都加入对话时,会触发sessionUpdate。但是,在生产环境中,并非总是同时发生。结果是对话框堆栈没有完全构建,因此,不能总是有权访问发送问候语所需的详细信息(例如,用户名)。最终结果是糟糕的用户体验。

我不知道您使用的是哪个平台/频道,但所引用的博客建议在网络聊天环境中使用反向频道来监视和触发事件,以在用户加入对话后发送欢迎消息。如果这是用于网络聊天,请记住该博客有些过时了。它说明了如何使用BotChat(v3网络聊天方法)。 v4方法使用增强的WebChat,它提供了更多功能。

您可以尝试使用中间件选项,以查看是否有另一个适合您的选项。我找不到合适的那个。话虽这么说,Bot Framework SDK是开源的,只要您找到了它,它总是欢迎用户生成解决方案。