如何在Microsoft Bot Frame框架开发的聊天Bot中直接获得响应初始对话框

问题描述

我现在正在开发聊天机器人,该机器人可以回答客户提出的问题。我想删除第一条通讯行“输入一些单词以回答问题”。但是,我找不到路。

初始化通信。

if (member.Id != turnContext.Activity.Recipient.Id)
{
    var reply = MessageFactory.Text("質問を続けるには何か入力してください。");
    await turnContext.SendActivityAsync(reply,cancellationToken);
}

问客户一个问题。

private async Task<DialogTurnResult> InputQuestionAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
    {
        _logger.Log@R_935_4045@ion("MainDialog.InputQuestionAsync");
        var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("ご質問を話し言葉で入力して下さい。") };
        return await stepContext.PromptAsync(nameof(TextPrompt),promptOptions,cancellationToken);
    }

回答问题。

private async Task<DialogTurnResult> ShowCardStepAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
    {
        _logger.Log@R_935_4045@ion("MainDialog.ShowCardStepAsync");
        var receivedMessage = (string)stepContext.Result;
        var userProfile = await _userProfileAccessor.GetAsync(stepContext.Context,() => new UserProfile(),cancellationToken);
        userProfile.Question = receivedMessage;
        *
        *
        *
        *
        msg = msg + sec.ToString() + ".知りたい質問がありません\n\n" + third.ToString() + ".質問を変える\n\n";
        var reply = MessageFactory.Text(msg);
        list1.Add(sec.ToString());
        list1.Add(third.ToString());
        reply.Attachments.Add(Cards.GetHeroCard(list1).ToAttachment());
        await stepContext.Context.SendActivityAsync(reply,cancellationToken);

        var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("番号を押してください") };
        return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);
        }
    }

image of the dialog flow

解决方法

添加

var accessor = ConversationState.CreateProperty<DialogState>(nameof(DialogState));
await Dialog.RunAsync(turnContext,accessor,cancellationToken);

在 OnMember⚓Async和OnMessageActivityAsync解决了这个问题。