西浦直志
西浦直志

Reputation: 31

How can I get directly response initial dialog in chat bot developed by Microsoft bot frame work

I’m now developing chat bot that reply the question the customer asked. I want to delete the first communication line “Type some words for reply the question”. However, I can’t find the way.

Initialize the communication.

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

Ask a customer for a question.

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

Reply the question.

private async Task<DialogTurnResult> ShowCardStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        _logger.LogInformation("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), promptOptions, cancellationToken);
        }
    }

[![image of the dialog flow][1]][1]

Upvotes: 1

Views: 73

Answers (1)

西浦直志
西浦直志

Reputation: 31

Add

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

In OnMembersAddedAsync and OnMessageActivityAsync solved this issue.

Upvotes: 1

Related Questions