// Starts the SkillDialog based on the user's selections.
        private async Task <DialogTurnResult> CallSkillActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var selectedSkill = (SkillDefinition)stepContext.Values[_selectedSkillKey];

            // Save active skill in state.
            await _activeSkillProperty.SetAsync(stepContext.Context, selectedSkill, cancellationToken);

            // Create the initial activity to call the skill.
            var skillActivity = selectedSkill.CreateBeginActivity(((FoundChoice)stepContext.Result).Value);

            if (skillActivity.Name == "Sso")
            {
                // Special case, we start the SSO dialog to prepare the host to call the skill.
                return(await stepContext.BeginDialogAsync($"{SsoDialogPrefix}{selectedSkill.Id}", cancellationToken : cancellationToken));
            }

            // We are manually creating the activity to send to the skill; ensure we add the ChannelData and Properties
            // from the original activity so the skill gets them.
            // Note: this is not necessary if we are just forwarding the current activity from context.
            skillActivity.ChannelData = stepContext.Context.Activity.ChannelData;
            skillActivity.Properties  = stepContext.Context.Activity.Properties;

            // Create the BeginSkillDialogOptions and assign the activity to send.
            var skillDialogArgs = new BeginSkillDialogOptions {
                Activity = skillActivity
            };

            if (stepContext.Values[_deliveryMode].ToString() == DeliveryModes.ExpectReplies)
            {
                skillDialogArgs.Activity.DeliveryMode = DeliveryModes.ExpectReplies;
            }

            // Start the skillDialog instance with the arguments.
            return(await stepContext.BeginDialogAsync(selectedSkill.Id, skillDialogArgs, cancellationToken));
        }
Exemplo n.º 2
0
        // Starts the SkillDialog based on the user's selections.
        private async Task <DialogTurnResult> CallSkillActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var selectedSkill = (BotFrameworkSkill)stepContext.Values[_selectedSkillKey];

            Activity skillActivity;

            switch (selectedSkill.Id)
            {
            case "DialogSkillBot":
                skillActivity = CreateDialogSkillBotActivity(((FoundChoice)stepContext.Result).Value, stepContext.Context);
                break;

            // We can add other case statements here if we support more than one skill.
            default:
                throw new Exception($"Unknown target skill id: {selectedSkill.Id}.");
            }

            // Create the BeginSkillDialogOptions and assign the activity to send.
            var skillDialogArgs = new BeginSkillDialogOptions {
                Activity = skillActivity
            };

            // Save active skill in state.
            await _activeSkillProperty.SetAsync(stepContext.Context, selectedSkill, cancellationToken);

            // Start the skillDialog instance with the arguments.
            return(await stepContext.BeginDialogAsync(selectedSkill.Id, skillDialogArgs, cancellationToken));
        }
        // Runs when this dialog ends. Handles result of prompt to switch skills or resume waiting dialog.
        protected override async Task <DialogTurnResult> EndComponentAsync(DialogContext outerDc, object result, CancellationToken cancellationToken)
        {
            var skillId = await _skillIdAccessor.GetAsync(outerDc.Context, () => null).ConfigureAwait(false);

            var lastActivity = await _lastActivityAccessor.GetAsync(outerDc.Context, () => null).ConfigureAwait(false);

            outerDc.Context.Activity.Text = lastActivity.Text;

            if ((bool)result)
            {
                // If user decided to switch, replace current skill dialog with new skill dialog.
                var skillDialogOptions = new BeginSkillDialogOptions {
                    Activity = outerDc.Context.Activity
                };

                // End the SwitchSkillDialog without triggering the ResumeDialog function of current SkillDialog
                outerDc.Stack.RemoveAt(0);

                // Start the skill dialog.
                return(await outerDc.ReplaceDialogAsync(skillId, skillDialogOptions).ConfigureAwait(false));
            }
            else
            {
                // Ends this dialog.
                return(await outerDc.EndDialogAsync().ConfigureAwait(false));
            }
        }
        // Starts the SkillDialog based on the user's selections.
        private async Task <DialogTurnResult> CallSkillActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var selectedSkill = (BotFrameworkSkill)stepContext.Values[_selectedSkillKey];

            var skillActivity = CreateBeginActivity(stepContext.Context, selectedSkill.Id, ((FoundChoice)stepContext.Result).Value);

            // Create the BeginSkillDialogOptions and assign the activity to send.
            var skillDialogArgs = new BeginSkillDialogOptions {
                Activity = skillActivity
            };

            // Comment or uncomment this line if you need to enable or disabled buffered replies.
            // skillDialogArgs.Activity.DeliveryMode = DeliveryModes.ExpectReplies;

            // Save active skill in state.
            await _activeSkillProperty.SetAsync(stepContext.Context, selectedSkill, cancellationToken);

            if (skillActivity.Name == "Sso")
            {
                // Special case, we start the SSO dialog to prepare the host to call the skill.
                return(await stepContext.BeginDialogAsync(nameof(SsoDialog), cancellationToken : cancellationToken));
            }

            // Start the skillDialog instance with the arguments.
            return(await stepContext.BeginDialogAsync(selectedSkill.Id, skillDialogArgs, cancellationToken));
        }
        public async Task ShouldNotInterceptOAuthCardsForTokenException()
        {
            var connectionName = "connectionName";
            var firstResponse  = new ExpectedReplies(new List <Activity> {
                CreateOAuthCardAttachmentActivity("https://test")
            });
            var mockSkillClient = new Mock <BotFrameworkClient>();

            mockSkillClient
            .Setup(x => x.PostActivityAsync <ExpectedReplies>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <Activity>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new InvokeResponse <ExpectedReplies>
            {
                Status = 200,
                Body   = firstResponse
            }));

            var conversationState = new ConversationState(new MemoryStorage());
            var dialogOptions     = CreateSkillDialogOptions(conversationState, mockSkillClient, connectionName);

            var sut            = new SkillDialog(dialogOptions);
            var activityToSend = CreateSendActivity();
            var testAdapter    = new TestAdapter(Channels.Test)
                                 .Use(new AutoSaveStateMiddleware(conversationState));
            var initialDialogOptions = new BeginSkillDialogOptions {
                Activity = activityToSend
            };
            var client = new DialogTestClient(testAdapter, sut, initialDialogOptions, conversationState: conversationState);

            testAdapter.ThrowOnExchangeRequest(connectionName, Channels.Test, "user1", "https://test");
            var finalActivity = await client.SendActivityAsync <IMessageActivity>("irrelevant");

            Assert.IsNotNull(finalActivity);
            Assert.IsTrue(finalActivity.Attachments.Count == 1);
        }
        private async Task <DialogTurnResult> RouteStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var activity    = stepContext.Context.Activity.AsMessageActivity();
            var userProfile = await _userProfileState.GetAsync(stepContext.Context, () => new UserProfileState());

            if (!string.IsNullOrEmpty(activity.Text))
            {
                // Get current cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Get dispatch result from turn state.
                var dispatchResult = stepContext.Context.TurnState.Get <DispatchLuis>(StateProperties.DispatchResult);
                (var dispatchIntent, var dispatchScore) = dispatchResult.TopIntent();

                if (IsSkillIntent(dispatchIntent))
                {
                    var dispatchIntentSkill = dispatchIntent.ToString();
                    var skillDialogArgs     = new BeginSkillDialogOptions {
                        Activity = (Activity)activity
                    };

                    // Start the skill dialog.
                    return(await stepContext.BeginDialogAsync(dispatchIntentSkill, skillDialogArgs));
                }
                else if (dispatchIntent == DispatchLuis.Intent.q_Faq)
                {
                    stepContext.SuppressCompletionMessage(true);

                    return(await stepContext.BeginDialogAsync("Faq"));
                }
                else if (dispatchIntent == DispatchLuis.Intent.q_Chitchat)
                {
                    stepContext.SuppressCompletionMessage(true);

                    return(await stepContext.BeginDialogAsync("Chitchat"));
                }
                else
                {
                    stepContext.SuppressCompletionMessage(true);

                    await stepContext.Context.SendActivityAsync(_templateManager.GenerateActivityForLocale("UnsupportedMessage", userProfile));

                    return(await stepContext.NextAsync());
                }
            }
            else
            {
                return(await stepContext.NextAsync());
            }
        }
Exemplo n.º 7
0
        // Starts SkillDialog based on the user's selections
        private async Task <DialogTurnResult> CallSkillActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var selectedSkill = (BotFrameworkSkill)stepContext.Values[_selectedSkillKey];

            Activity skillActivity;

            switch (selectedSkill.Id)
            {
            case "EchoSkillBot":
                // Echo skill only handles message activities, send a dummy utterance to get it started.
                skillActivity      = (Activity)Activity.CreateMessageActivity();
                skillActivity.Text = "Start echo skill";
                break;

            case "DialogSkillBot":
                skillActivity = CreateDialogSkillBotActivity(((FoundChoice)stepContext.Result).Value);
                break;

            default:
                throw new Exception($"Unknown target skill id: {selectedSkill.Id}.");
            }

            // Create the BeginSkillDialogOptions
            var skillDialogArgs = new BeginSkillDialogOptions {
                Activity = skillActivity
            };

            // We are manually creating the activity to send to the skill, ensure we add the ChannelData and Properties
            // from the original activity so the skill gets them.
            // Note: this is not necessary if we are just forwarding the current activity from context.
            skillDialogArgs.Activity.ChannelData = stepContext.Context.Activity.ChannelData;
            skillDialogArgs.Activity.Properties  = stepContext.Context.Activity.Properties;

            // Comment or uncomment this line if you need to enable or disabled buffered replies.
            skillDialogArgs.Activity.DeliveryMode = DeliveryModes.ExpectReplies;

            // Save active skill in state
            await _activeSkillProperty.SetAsync(stepContext.Context, selectedSkill, cancellationToken);

            // Start the skillDialog instance with the arguments.
            return(await stepContext.BeginDialogAsync(selectedSkill.Id, skillDialogArgs, cancellationToken));
        }
Exemplo n.º 8
0
        // Starts the SkillDialog based on the user's selections.
        private async Task <DialogTurnResult> CallSkillActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var selectedSkill = (BotFrameworkSkill)stepContext.Values[_selectedSkillKey];

            Activity skillActivity;

            switch (selectedSkill.Id)
            {
            case "EchoSkillBot":
                // Echo only takes messages
                skillActivity = CreateDialogSkillBotActivity(SkillActionMessage, stepContext.Context);

                break;

            case "DialogSkillBot":
                skillActivity = CreateDialogSkillBotActivity(((FoundChoice)stepContext.Result).Value, stepContext.Context);
                break;

            default:
                throw new Exception($"Unknown target skill id: {selectedSkill.Id}.");
            }

            // Create the BeginSkillDialogOptions and assign the activity to send.
            var skillDialogArgs = new BeginSkillDialogOptions {
                Activity = skillActivity
            };

            // Comment or uncomment this line if you need to enable or disabled buffered replies.
            //skillDialogArgs.Activity.DeliveryMode = DeliveryModes.ExpectReplies;

            // Save active skill in state.
            await _activeSkillProperty.SetAsync(stepContext.Context, selectedSkill, cancellationToken);

            // Start the skillDialog instance with the arguments.
            return(await stepContext.BeginDialogAsync(selectedSkill.Id, skillDialogArgs, cancellationToken));
        }
Exemplo n.º 9
0
        private async Task <DialogTurnResult> RouteStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var activity    = stepContext.Context.Activity.AsMessageActivity();
            var userProfile = await _userProfileState.GetAsync(stepContext.Context, () => new UserProfileState(), cancellationToken);

            if (!string.IsNullOrEmpty(activity.Text))
            {
                // Get current cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Get dispatch result from turn state.
                var dispatchResult = stepContext.Context.TurnState.Get <DispatchLuis>(StateProperties.DispatchResult);
                (var dispatchIntent, var dispatchScore) = dispatchResult.TopIntent();

                if (IsSkillIntent(dispatchIntent))
                {
                    var dispatchIntentSkill = dispatchIntent.ToString();
                    var skillDialogArgs     = new BeginSkillDialogOptions {
                        Activity = (Activity)activity
                    };

                    // Save active skill in state.
                    var selectedSkill = _skillsConfig.Skills[dispatchIntentSkill];
                    await _activeSkillProperty.SetAsync(stepContext.Context, selectedSkill, cancellationToken);

                    // Start the skill dialog.
                    return(await stepContext.BeginDialogAsync(dispatchIntentSkill, skillDialogArgs, cancellationToken));
                }

                if (dispatchIntent == DispatchLuis.Intent.q_Faq)
                {
                    stepContext.SuppressCompletionMessage(true);

                    var knowledgebaseId = FaqDialogId;
                    var qnaDialog       = TryCreateQnADialog(knowledgebaseId, localizedServices);
                    if (qnaDialog != null)
                    {
                        Dialogs.Add(qnaDialog);
                    }

                    return(await stepContext.BeginDialogAsync(knowledgebaseId, cancellationToken : cancellationToken));
                }

                if (ShouldBeginChitChatDialog(stepContext, dispatchIntent, dispatchScore))
                {
                    stepContext.SuppressCompletionMessage(true);

                    var knowledgebaseId = "Chitchat";
                    var qnaDialog       = TryCreateQnADialog(knowledgebaseId, localizedServices);
                    if (qnaDialog != null)
                    {
                        Dialogs.Add(qnaDialog);
                    }

                    return(await stepContext.BeginDialogAsync(knowledgebaseId, cancellationToken : cancellationToken));
                }

                stepContext.SuppressCompletionMessage(true);

                await stepContext.Context.SendActivityAsync(_templateManager.GenerateActivityForLocale("UnsupportedMessage", userProfile), cancellationToken);

                return(await stepContext.NextAsync(cancellationToken : cancellationToken));
            }

            return(await stepContext.NextAsync(cancellationToken : cancellationToken));
        }