How to user SkillContext to pass data from VirtualAssistant to a Skill

会有一股神秘感。 提交于 2020-01-05 13:06:56

问题


I need to share an information from my Virtual Assistant with a Skill. I try to use SkillContext, I don't get errors but in the Skill the SkillContext is empty.

This is the code I use in the VirtualAssistant MainDialog::RouteAsync to set the payload

                Dictionary<string, JObject> dictionary = new Dictionary<string, JObject>();

                dictionary.Add("userEmail", JObject.Parse("{ email: 'emiliano.carlesi@itattitude.com'}"));

                await _skillContextAccessor.SetAsync(dc.Context, new SkillContext(dictionary));

                var result = await dc.BeginDialogAsync(identifiedSkill.Id);

In the Cosmos DB botstate-db I found the value:

        "SkillContext": {
            "$type": "Microsoft.Bot.Builder.Skills.SkillContext, Microsoft.Bot.Builder.Skills",
            "userEmail": {
                "email": "emiliano.carlesi@itattitude.com"
            }
        },

This is the code in MainDialog::RouteAsync I use to retrieve the payload:

            SkillContext skillContext = await _contextAccessor.GetAsync(dc.Context, () => new SkillContext());

            if (skillContext == null)
            {
                TelemetryClient.TrackTrace("skillContext is null", Severity.Information, null);
            }
            else
            {
                TelemetryClient.TrackTrace("skillContext is not null", Severity.Information, null);

                if (skillContext.Keys != null && skillContext.Keys.Count > 0)
                {
                    foreach (string key in skillContext.Keys)
                    {
                        TelemetryClient.TrackTrace(String.Format("Key in skillContext: {0}", key), Severity.Information, null);
                    }
                }
            }

来源:https://stackoverflow.com/questions/57747846/how-to-user-skillcontext-to-pass-data-from-virtualassistant-to-a-skill

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!