Exemple #1
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            await dc.Context.SendActivityAsync(_responseManager.GetResponse(MainResponses.CancelMessage));

            await CompleteAsync(dc);

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #2
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            await _responder.ReplyWith(dc.Context, MainResponses.Cancelled);

            await CompleteAsync(dc);

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #3
0
        public async Task <DialogTurnResult> ExecuteAsync(DialogContext dialogContext, UserId userId,
                                                          CancellationToken cancellationToken)
        {
            _userService.RemoveUserAnswers(userId);
            await dialogContext.Context.SendActivityAsync("done", cancellationToken : cancellationToken);

            await dialogContext.CancelAllDialogsAsync(cancellationToken);

            return(await dialogContext.BeginDialogAsync(nameof(ScenarioListDialog), userId, cancellationToken));
        }
Exemple #4
0
        protected virtual async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            // If user chose to cancel
            await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Cancelled);

            // Cancel all in outer stack of component i.e. the stack the component belongs to
            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #5
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            await dc.Context.SendActivityAsync(_responseManager.GetResponse(PhoneMainResponses.CancelMessage));

            await dc.CancelAllDialogsAsync();

            await outgoingCallDialog.OnCancel(dc);

            return(InterruptionAction.End);
        }
Exemple #6
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(ToDoMainResponses.CancelMessage));

            await CompleteAsync(dc);

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #7
0
        private async Task <DialogTurnResult> InterruptAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                var text        = innerDc.Context.Activity.Text.ToLower();
                var _DialogInfo = await _dialogInfoStateProperty.GetAsync(innerDc.Context);

                switch (text)
                {
                case "lang":


                    await innerDc.ReplaceDialogAsync(nameof(LanguageDialog), "ChangeLanguage",
                                                     cancellationToken : cancellationToken);

                    return(new DialogTurnResult(DialogTurnStatus.Waiting));

                case "restart":
                case "again":
                case "new":
                case "reload":
                    innerDc.Context.Activity.Text = "begin";
                    await innerDc.ReplaceDialogAsync(nameof(LocationDialog), "begin", cancellationToken);

                    return(new DialogTurnResult(DialogTurnStatus.Waiting));

                case "quit":
                case "exit":
                    await innerDc.Context.SendActivityAsync($"Cancelling", cancellationToken : cancellationToken);

                    return(await innerDc.CancelAllDialogsAsync());

                case "sub":
                case "subscriptions":
                    await innerDc.ReplaceDialogAsync(nameof(SubscriptionDialog),
                                                     cancellationToken : cancellationToken);

                    return(new DialogTurnResult(DialogTurnStatus.Waiting));

                case "email":
                    await innerDc.ReplaceDialogAsync(nameof(EmailDialog),
                                                     cancellationToken : cancellationToken);

                    return(new DialogTurnResult(DialogTurnStatus.Waiting));

                case "help":
                    await innerDc.ReplaceDialogAsync(nameof(HelpDialog),
                                                     cancellationToken : cancellationToken);

                    return(new DialogTurnResult(DialogTurnStatus.Waiting));
                }
            }

            return(null);
        }
Exemple #8
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var cancelling = dc.Context.Activity.CreateReply(EmailBotResponses.CancellingMessage);
            await dc.Context.SendActivityAsync(cancelling);

            await this._accessors.EmailSkillState.SetAsync(dc.Context, new EmailSkillState());

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #9
0
        private async Task <DialogTurnResult> Logout(DialogContext innerDc, CancellationToken cancellationToken)
        {
            // The bot adapter encapsulates the authentication processes.
            var botAdapter = (BotFrameworkAdapter)innerDc.Context.Adapter;
            await botAdapter.SignOutUserAsync(innerDc.Context, _connectionName, null, cancellationToken);

            _resetToken();
            await innerDc.Context.SendActivityAsync(MessageFactory.Text("You have been signed out."), cancellationToken);

            return(await innerDc.CancelAllDialogsAsync());
        }
Exemple #10
0
 protected override Task <DialogTurnResult> EndComponentAsync(DialogContext outerDc, object result, CancellationToken cancellationToken)
 {
     if (result.ToString().Equals(CommonUtil.DialogTurnResultCancelAllDialogs, StringComparison.InvariantCultureIgnoreCase))
     {
         return(outerDc.CancelAllDialogsAsync());
     }
     else
     {
         return(base.EndComponentAsync(outerDc, result, cancellationToken));
     }
 }
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var state = await _stateAccessor.GetAsync(dc.Context, () => new CalendarSkillState());

            state.Clear();
            await dc.Context.SendActivityAsync(_responseManager.GetResponse(CalendarMainResponses.CancelMessage));

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.End);
        }
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var response = _responseManager.GetResponse(AutomotiveSkillMainResponses.CancelMessage);
            await dc.Context.SendActivityAsync(response);

            await OnDialogCompleteAsync(dc);

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.End);
        }
Exemple #13
0
 protected override Task<DialogTurnResult> EndComponentAsync(DialogContext outerDc, object result, CancellationToken cancellationToken)
 {
     var resultString = result?.ToString();
     if (!string.IsNullOrWhiteSpace(resultString) && resultString.Equals(CommonUtil.DialogTurnResultCancelAllDialogs, StringComparison.InvariantCultureIgnoreCase))
     {
         return outerDc.CancelAllDialogsAsync();
     }
     else
     {
         return base.EndComponentAsync(outerDc, result, cancellationToken);
     }
 }
Exemple #14
0
        public override async Task <DialogTurnResult> ExecuteAsync(DialogContext dc, CancellationToken cancellationToken)
        {
            UserProfile userProfile = await this.state.UserProfile.GetAsync(dc.Context, () => new UserProfile(), cancellationToken);

            userProfile.SurveyState.EndDate  = DateTime.UtcNow;
            userProfile.SurveyState.Progress = ProgressState.OptedOut;

            // TODO: Add to suppression list here
            await dc.Context.SendActivityAsync($"OK. You have opted out successfully.", cancellationToken : cancellationToken);

            return(await dc.CancelAllDialogsAsync(cancellationToken));
        }
Exemple #15
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var state = await _conversationStateAccessor.GetAsync(dc.Context, () => new RestaurantBookingState());

            state.Clear();

            await dc.Context.SendActivityAsync(_responseManager.GetResponse(RestaurantBookingSharedResponses.CancellingMessage));

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.End);
        }
Exemple #16
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var cancelling = dc.Context.Activity.CreateReply(ToDoBotResponses.CancellingMessage);
            await dc.Context.SendActivityAsync(cancelling);

            var state = await this.toDoSkillAccessors.ToDoSkillState.GetAsync(dc.Context);

            state.Clear();
            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #17
0
        // Runs on every turn of the conversation to check if the conversation should be interrupted.
        protected async Task <DialogTurnResult> InterruptDialogAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            DialogTurnResult interrupted = null;
            var activity = innerDc.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get connected LUIS result from turn state.
                var generalResult = innerDc.Context.TurnState.Get <General>(StateProperties.GeneralLuisResult);
                (var generalIntent, var generalScore) = generalResult.TopIntent();

                if (generalScore > 0.5)
                {
                    switch (generalIntent)
                    {
                    case General.Intent.Cancel:
                    {
                        var state = await _conversationStateAccessor.GetAsync(innerDc.Context, () => new RestaurantBookingState(), cancellationToken);

                        state.Clear();

                        await innerDc.Context.SendActivityAsync(_localeTemplateManager.GenerateActivity(RestaurantBookingSharedResponses.CancellingMessage), cancellationToken);

                        await innerDc.CancelAllDialogsAsync(cancellationToken);

                        if (innerDc.Context.IsSkill())
                        {
                            interrupted = await innerDc.EndDialogAsync(state.IsAction?new ActionResult { ActionSuccess = false } : null, cancellationToken);
                        }
                        else
                        {
                            interrupted = await innerDc.BeginDialogAsync(InitialDialogId, cancellationToken : cancellationToken);
                        }

                        break;
                    }

                    case General.Intent.Help:
                    {
                        await innerDc.Context.SendActivityAsync(_localeTemplateManager.GenerateActivity(RestaurantBookingMainResponses.HelpMessage), cancellationToken);

                        await innerDc.RepromptDialogAsync(cancellationToken);

                        interrupted = EndOfTurn;
                        break;
                    }
                    }
                }
            }

            return(interrupted);
        }
Exemple #18
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var state = await _stateAccessor.GetAsync(dc.Context, () => new CalendarSkillState());

            state.Clear();
            await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(CalendarMainResponses.CancelMessage));

            await CompleteAsync(dc);

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.StartedDialog);
        }
Exemple #19
0
        public async Task <DialogTurnResult> GetPairAsync(DialogContext dialogContext, string text, CancellationToken cancellationToken)
        {
            if (!await IsActiveSession(dialogContext, dialogContext.Context.Activity.From, cancellationToken))
            {
                return(await dialogContext.CancelAllDialogsAsync(cancellationToken));
            }

            var serviceName = text.Replace("get", "").Trim();

            var pairs = (await _storageService.RetrieveEntityUsingPointQueryAsync <PairEntity>("Pair", dialogContext.Context.Activity.From.Id, serviceName)).ToArray();

            if (pairs.Length == 0)
            {
                await dialogContext.Context.SendActivityAsync(MessageFactory.Text("Information about this service is not found."), cancellationToken);
            }
            else
            {
                await dialogContext.Context.SendActivityAsync(MessageFactory.Text(await _keyVaultService.GetSecret(pairs[0].Service)), cancellationToken);
            }

            return(await dialogContext.CancelAllDialogsAsync(cancellationToken));
        }
        public async Task Handle(DialogContext ctx)
        {
            if (ctx.ActiveDialog != null)
            {
                await ctx.CancelAllDialogsAsync();

                await ctx.Context.Senddd("Ok. I've canceled our last activity.");
            }
            else
            {
                await ctx.Context.Senddd("I don't have anything to cancel.");
            }
        }
Exemple #21
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            var cancelling = dc.Context.Activity.CreateReply(PointOfInterestBotResponses.CancellingMessage);
            await dc.Context.SendActivityAsync(cancelling);

            var state = await _accessors.PointOfInterestSkillState.GetAsync(dc.Context);

            state.Clear();

            await dc.CancelAllDialogsAsync();

            return(InterruptionAction.NoAction);
        }
Exemple #22
0
        public async Task <DialogTurnResult> AddPairAsync(DialogContext dialogContext, string text, CancellationToken cancellationToken)
        {
            if (!await IsActiveSession(dialogContext, dialogContext.Context.Activity.From, cancellationToken))
            {
                return(await dialogContext.CancelAllDialogsAsync(cancellationToken));
            }

            var data = text.Replace("add", "").Trim().Split(":");

            try
            {
                if (data.Length == 2 && await _keyVaultService.SetSecret(data[0], data[1]))
                {
                    var pairEntity = new PairEntity(dialogContext.Context.Activity.From.Id, data[0])
                    {
                        UserId  = new Guid(dialogContext.Context.Activity.From.Id),
                        Service = data[0]
                    };

                    var entity = await _storageService.InsertOrMergeEntityAsync("Pair", pairEntity);

                    if (entity == null)
                    {
                        await dialogContext.Context.SendActivityAsync(MessageFactory.Text("Try again."), cancellationToken);
                    }
                    else
                    {
                        await dialogContext.Context.SendActivityAsync(MessageFactory.Text("New pair id successfully added. \nTo get password from service use 'get SERVICE_NAME' command. \n To get list pairs use 'get all' command"), cancellationToken);
                    }
                }
            }
            catch
            {
                return(await dialogContext.CancelAllDialogsAsync(cancellationToken));
            }

            return(await dialogContext.CancelAllDialogsAsync(cancellationToken));
        }
        // Runs on every turn of the conversation to check if the conversation should be interrupted.
        protected async Task <DialogTurnResult> InterruptDialogAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            DialogTurnResult interrupted = null;
            var activity = innerDc.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get connected LUIS result from turn state.
                var generalResult = innerDc.Context.TurnState.Get <General>(StateProperties.GeneralLuisResult);
                (var generalIntent, var generalScore) = generalResult.TopIntent();

                if (generalScore > 0.5)
                {
                    switch (generalIntent)
                    {
                    case General.Intent.Cancel:
                    {
                        await innerDc.Context.SendActivityAsync(_templateManager.GenerateActivityForLocale(MainStrings.CANCELLED), cancellationToken);

                        await innerDc.CancelAllDialogsAsync(cancellationToken);

                        if (innerDc.Context.IsSkill())
                        {
                            var state = await _stateAccessor.GetAsync(innerDc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

                            interrupted = await innerDc.EndDialogAsync(state.IsAction?new ActionResult(false) : null, cancellationToken : cancellationToken);
                        }
                        else
                        {
                            interrupted = await innerDc.BeginDialogAsync(InitialDialogId, cancellationToken : cancellationToken);
                        }

                        break;
                    }

                    case General.Intent.Help:
                    {
                        await innerDc.Context.SendActivityAsync(HeroCardResponses.SendHelpCard(innerDc.Context, _templateManager), cancellationToken);

                        await innerDc.RepromptDialogAsync(cancellationToken);

                        interrupted = EndOfTurn;
                        break;
                    }
                    }
                }
            }

            return(interrupted);
        }
Exemple #24
0
        // Handle help requests for the main/root level.
        protected virtual async Task <InterruptionStatus> OnMainHelpAsync(DialogContext dc)
        {
            if (dc.ActiveDialog != null)
            {
                await dc.CancelAllDialogsAsync();
            }

            await dc.Context.SendActivityAsync("Welcome to the Basic Bot.");

            await dc.Context.SendActivityAsync("I understand greetings, being asked for help, or being asked to cancel what I am doing.");

            // Signal the conversation was interrupted and should immediately continue
            return(InterruptionStatus.Interrupted);
        }
Exemple #25
0
        public async override Task <DialogTurnResult> ResumeDialogAsync(DialogContext dc, DialogReason reason, object result, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (result is bool && (bool)result)
            {
                // User said yes to cancel prompt.
                await dc.Context.SendActivityAsync("Sure. I've canceled that!");

                return(await dc.CancelAllDialogsAsync());
            }
            else
            {
                // User said no to cancel.
                return(await base.ResumeDialogAsync(dc, reason, result, cancellationToken));
            }
        }
Exemple #26
0
        // Determine if an interruption has occurred before we dispatch to any active dialog.
        private async Task <bool> IsTurnInterruptedAsync(DialogContext dc, string topIntent)
        {
            // See if there are any conversation interrupts we need to handle.
            if (topIntent.Equals(CancelIntent))
            {
                if (dc.ActiveDialog != null)
                {
                    await dc.CancelAllDialogsAsync();

                    await dc.Context.SendActivityAsync("Ok. I've canceled our last activity.");
                }
                else
                {
                    await dc.Context.SendActivityAsync("I don't have anything to cancel.");
                }

                return(true);        // Handled the interrupt.
            }

            if (topIntent.Equals(HelpIntent))
            {
                await dc.Context.SendActivityAsync("Let me try to provide some help.");

                await dc.Context.SendActivityAsync("I understand greetings, being asked for help, or being asked to cancel what I am doing.");

                if (dc.ActiveDialog != null)
                {
                    await dc.RepromptDialogAsync();
                }

                return(true);        // Handled the interrupt.
            }

            if (topIntent.Equals(UpdateIntent))
            {
                await _dialogStateAccessor.SetAsync(dc.Context, new DialogState());

                await _greetingStateAccessor.SetAsync(dc.Context, new GreetingState());

                await _weatherStateAccessor.SetAsync(dc.Context, new WeatherState());

                await dc.Context.SendActivityAsync("Updated.");

                return(true);        // Handled the interrupt.
            }

            return(false);           // Did not handle the interrupt.
        }
        /// <summary>
        /// Handle dialog cancellation.
        /// </summary>
        /// <param name="dc">The current <see cref="DialogContext"/>.</param>
        /// <returns>A <see cref="Task"/> representing the <see cref="InterruptionStatus"/>.</returns>
        protected virtual async Task <InterruptionStatus> OnCancelAsync(DialogContext dc)
        {
            if (dc.ActiveDialog != null)
            {
                await dc.CancelAllDialogsAsync().ConfigureAwait(false);

                await dc.Context.SendActivityAsync("Ok. I've cancelled our last activity.");
            }
            else
            {
                await dc.Context.SendActivityAsync("I don't have anything to cancel.");
            }

            // Else, continue
            return(InterruptionStatus.NoAction);
        }
Exemple #28
0
        protected TestFlow CreateTestFlow(string dialogName, bool userConsentGiven = true)
        {
            return(new TestFlow(this.adapter, async(turnContext, cancellationToken) =>
            {
                this.turnContext = turnContext;
                this.cancellationToken = cancellationToken;

                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    // Initialize the dialog context.
                    DialogContext dialogContext = await this.dialogs.CreateContextAsync(turnContext, cancellationToken);

                    // Make sure this channel is supported.
                    if (!Phrases.ValidChannels.Contains(turnContext.Activity.ChannelId))
                    {
                        await Messages.SendAsync(Phrases.Greeting.InvalidChannel(turnContext), turnContext, cancellationToken);
                        return;
                    }

                    // Create the master dialog.
                    var masterDialog = new MasterDialog(this.state, this.dialogs, this.Api, this.Configuration);

                    // If the user sends the update keyword, clear the dialog stack and start a new update.
                    if (string.Equals(turnContext.Activity.Text, Phrases.Keywords.Update, StringComparison.OrdinalIgnoreCase))
                    {
                        dialogName = MasterDialog.Name;
                        await dialogContext.CancelAllDialogsAsync(cancellationToken);
                    }

                    // Attempt to continue any existing conversation.
                    DialogTurnResult result = await masterDialog.ContinueDialogAsync(dialogContext, cancellationToken);

                    // Start a new conversation if there isn't one already.
                    if (result.Status == DialogTurnStatus.Empty)
                    {
                        // Clear the user context when a new conversation begins.
                        await this.state.ClearUserContext(dialogContext.Context, cancellationToken);

                        // Tests must init the user once there is a turn context.
                        await InitUser(userConsentGiven);

                        // Difference for tests here is beginning the given dialog instead of master so that individual dialog flows can be tested.
                        await masterDialog.BeginDialogAsync(dialogContext, dialogName, null, cancellationToken);
                    }
                }
            }));
        }
        protected async Task <bool> TerminateIntentAsync(DialogContext dialogContext, TerminationIntent intent)
        {
            IActivity[] activities = intent.TerminationFailActivities;
            if (dialogContext.ActiveDialog != null)
            {
                await dialogContext.CancelAllDialogsAsync();

                activities = intent.TerminationSuccessActivities;
            }

            foreach (var activity in activities)
            {
                await dialogContext.Context.SendActivityAsync(activity);
            }

            return(true);
        }
Exemple #30
0
        // Runs on every turn of the conversation to check if the conversation should be interrupted.
        protected override async Task <InterruptionAction> OnInterruptDialogAsync(DialogContext dc, CancellationToken cancellationToken)
        {
            var activity = dc.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get connected LUIS result from turn state.
                var generalResult = dc.Context.TurnState.Get <GeneralLuis>(StateProperties.GeneralLuisResult);
                (var generalIntent, var generalScore) = generalResult.TopIntent();

                if (generalScore > 0.5)
                {
                    switch (generalIntent)
                    {
                    case GeneralLuis.Intent.Cancel:
                    {
                        await dc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale("CancelledMessage"));

                        await dc.CancelAllDialogsAsync();

                        return(InterruptionAction.End);
                    }

                    case GeneralLuis.Intent.Help:
                    {
                        await dc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale("HelpMessage"));

                        return(InterruptionAction.Resume);
                    }

                    case GeneralLuis.Intent.Logout:
                    {
                        // Log user out of all accounts.
                        await LogUserOut(dc);

                        await dc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale("LogoutMessage"));

                        return(InterruptionAction.End);
                    }
                    }
                }
            }

            return(InterruptionAction.NoAction);
        }