Exemple #1
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var skillDialogOptions = (SkillDialogOptions)options;

            _skill = skillDialogOptions.MatchedSkill;

            // Set our active Skill so later methods know which Skill to use.
            dc.ActiveDialog.State[ActiveSkillStateKey] = skillDialogOptions.MatchedSkill;

            _authPrompt = new OAuthPrompt(nameof(OAuthPrompt), new OAuthPromptSettings()
            {
                ConnectionName = skillDialogOptions.MatchedSkill.AuthConnectionName,
                Title          = "Skill Authentication",
                Text           = $"Please login to access this feature.",
            });

            var parameters = new Dictionary <string, object>();

            if (skillDialogOptions.MatchedSkill.Parameters != null)
            {
                foreach (var parameter in skillDialogOptions.MatchedSkill.Parameters)
                {
                    if (skillDialogOptions.Parameters.TryGetValue(parameter, out var paramValue))
                    {
                        parameters.Add(parameter, paramValue);
                    }
                }
            }

            var skillMetadata = new SkillMetadata(
                skillDialogOptions.LuisResult,
                skillDialogOptions.LuisService,
                skillDialogOptions.MatchedSkill.Configuration,
                parameters);

            var dialogBeginEvent = new Activity(
                type: ActivityTypes.Event,
                channelId: dc.Context.Activity.ChannelId,
                from: new ChannelAccount(id: dc.Context.Activity.From.Id, name: dc.Context.Activity.From.Name),
                recipient: new ChannelAccount(id: dc.Context.Activity.Recipient.Id, name: dc.Context.Activity.Recipient.Name),
                conversation: new ConversationAccount(id: dc.Context.Activity.Conversation.Id),
                name: SkillBeginEventName,
                value: skillMetadata);

            return(await ForwardToSkill(dc, dialogBeginEvent));
        }
Exemple #2
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options, CancellationToken cancellationToken)
        {
            var skillDialogOptions = (SkillDialogOptions)options;

            // Set our active Skill so later methods know which Skill to use.
            dc.ActiveDialog.State[ActiveSkillStateKey] = skillDialogOptions.MatchedSkill;

            // If Parameters are requested by a Skill we try to resolve them from the UserInformation storage
            // If they aren't present (a valid scenario) we don't pass
            var parameters = new Dictionary <string, object>();

            if (skillDialogOptions.MatchedSkill.Parameters != null)
            {
                foreach (var parameter in skillDialogOptions.MatchedSkill.Parameters)
                {
                    if (skillDialogOptions.UserInfo.TryGetValue(parameter, out var paramValue))
                    {
                        parameters.Add(parameter, paramValue);
                    }
                }
            }

            var skillMetadata = new SkillMetadata(skillDialogOptions.LuisResult,
                                                  skillDialogOptions.MatchedSkill.Configuration,
                                                  parameters);

            // Send a skillBegin event to the down-stream Skill/Bot and pass the Luis result already performed by the dispatcher to
            // shortcut processing by the Skill but also enables the Skill to be used directly by the emulator
            // We also send a SkilLMetadata object in the Value property to exchange configuration and user information
            var dialogBeginEvent = new Activity(
                type: ActivityTypes.Event,
                channelId: dc.Context.Activity.ChannelId,
                from: new ChannelAccount(id: dc.Context.Activity.From.Id, name: dc.Context.Activity.From.Name),
                recipient: new ChannelAccount(id: dc.Context.Activity.Recipient.Id, name: dc.Context.Activity.Recipient.Name),
                conversation: new ConversationAccount(id: dc.Context.Activity.Conversation.Id),
                name: SkillBeginEventName,
                value: skillMetadata);

            // Send event to Skill/Bot
            await ForwardActivity(dc, dialogBeginEvent);

            return(EndOfTurn);
        }