コード例 #1
0
        private async Task <DialogTurnResult> PerformActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //_logger.LogInformation($"MainDialog.PerformActionStepAsync[{((FoundChoice)stepContext.Result)?.Value}]");

            var userProfileTemporary = await _userProfileTemporaryAccessor.GetAsync(stepContext.Context, () => new UserProfileTemporary());

            var actionHandler     = new ActionHandler();
            var repromptThisRound = false;

            switch (((FoundChoice)stepContext.Result)?.Value)
            {
            // Hack coz Facebook Messenge stopped showing "Send Location" button
            case "Set Location":
                repromptThisRound = true;
                await stepContext.Context.SendActivityAsync(CardFactory.CreateGetLocationFromGoogleMapsReply());

                break;

            case "Attractor":
                stepContext.Values["PointType"] = "Attractor";
                return(await stepContext.NextAsync(cancellationToken : cancellationToken));

            case "Void":
                stepContext.Values["PointType"] = "Void";
                return(await stepContext.NextAsync(cancellationToken : cancellationToken));

            case "Anomaly":
                stepContext.Values["PointType"] = "Anomaly";
                return(await stepContext.NextAsync(cancellationToken : cancellationToken));

            case "Intent Suggestions":
                await actionHandler.IntentSuggestionActionAsync(stepContext.Context, userProfileTemporary, cancellationToken, this);

                break;

            case "Pair":
                stepContext.Values["PointType"] = "Pair";
                return(await stepContext.NextAsync(cancellationToken : cancellationToken));

            case "Blind Spots & More":
                await stepContext.EndDialogAsync(cancellationToken : cancellationToken);

                return(await stepContext.BeginDialogAsync(nameof(MoreStuffDialog), this, cancellationToken));

            case "Scan":
                await stepContext.EndDialogAsync(cancellationToken : cancellationToken);

                return(await stepContext.BeginDialogAsync(nameof(ScanDialog), this, cancellationToken));

            case "My Location":
                repromptThisRound = true;
                await actionHandler.LocationActionAsync(stepContext.Context, userProfileTemporary, cancellationToken);

                break;

            case "Settings":
                await stepContext.EndDialogAsync(cancellationToken : cancellationToken);

                return(await stepContext.BeginDialogAsync(nameof(SettingsDialog), this, cancellationToken));
            }

            if (repromptThisRound)
            {
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), cancellationToken : cancellationToken));
            }
            else
            {
                // Long-running tasks like /getattractors etc will make use of ContinueDialog to re-prompt users
                return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
            }
        }