max
max

Reputation: 101

Bot context.Wait not showing next message

I am working on Bot application that have IDialog. When the increment value reaching 4 it is not calling MessageEndAsync and waiting for the user input. Without user input not showing next message in the Emulator.

I am looking some solution once the validation is passed then move to the next message otherwise keep checking the validation.

Could you pleas help me to fix the issue.

[Serializable]
    public class PlayGame: IDialog<object>
    {

        private int increment = 0;
        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);
        }
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            var message = await argument;
            increment++;
            if (increment == 4)
            {
                await context.PostAsync(increment.ToString());
                context.Wait(MessageEndAsync);
            }
            else
            {
                await context.PostAsync(increment.ToString());
                context.Wait(MessageReceivedAsync);
            }
        }
        public virtual async Task MessageEndAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            await context.PostAsync("Thanks for your information");
            context.Done<object>(null);
        }
    }

Upvotes: 1

Views: 423

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

MessageEndAsync won't be called until the user send an input. Instead of doing context.Wait just put the code within the if clause. So if the increment is 4, you will post the message and end the dialog.

context.Wait is used to put the bot in wait state for the upcoming user input.

Upvotes: 4

Related Questions