问题
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