public async Task OnTurnAsync()

in SDKV4-Samples/dotnet_core/DialogPromptBot/DialogPromptBot.cs [92:153]


        public async Task OnTurnAsync(
            ITurnContext turnContext,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            switch (turnContext.Activity.Type)
            {
                // On a message from the user:
                case ActivityTypes.Message:

                    // Get the current reservation info from state.
                    var reservation = await _accessors.ReservationAccessor.GetAsync(
                        turnContext,
                        () => null,
                        cancellationToken);

                    // Generate a dialog context for our dialog set.
                    var dc = await _dialogSet.CreateContextAsync(turnContext, cancellationToken);

                    if (dc.ActiveDialog is null)
                    {
                        // If there is no active dialog, check whether we have a reservation yet.
                        if (reservation is null)
                        {
                            // If not, start the dialog.
                            await dc.BeginDialogAsync(ReservationDialog, null, cancellationToken);
                        }
                        else
                        {
                            // Otherwise, send a status message.
                            await turnContext.SendActivityAsync(
                                $"We'll see you on {reservation.Date}.",
                                cancellationToken: cancellationToken);
                        }
                    }
                    else
                    {
                        // Continue the dialog.
                        var dialogTurnResult = await dc.ContinueDialogAsync(cancellationToken);

                        // If the dialog completed this turn, record the reservation info.
                        if (dialogTurnResult.Status is DialogTurnStatus.Complete)
                        {
                            reservation = (Reservation)dialogTurnResult.Result;
                            await _accessors.ReservationAccessor.SetAsync(
                                turnContext,
                                reservation,
                                cancellationToken);

                            // Send a confirmation message to the user.
                            await turnContext.SendActivityAsync(
                                $"Your party of {reservation.Size} is confirmed for " +
                                $"{reservation.Date} in {reservation.Location}.",
                                cancellationToken: cancellationToken);
                        }
                    }

                    // Save the updated dialog state into the conversation state.
                    await _accessors.ConversationState.SaveChangesAsync(
                        turnContext, false, cancellationToken);
                    break;
            }
        }