问题
I have one main Luis dialog, i need to Forward CheckListDialog and pass the 'luisresult.entity' to CheckListDialog, code like below:
context.Forward(new CheckListDialog(), this.DialogResumeAfter,result.Entities,CancellationToken.None);
Question: In "CheckListDialog", how can i get the "result.Entities" ?
PS: There is another solution to get the Luisresult.Entities,
context.Call(new CheckListDialog(result.Entities), this.DialogResumeAfter);
This solution is working, but I would like to know how to get the parameter value using context.Forward.
回答1:
When using context.Forward method, it expects you to send parameter of type IMessageActivity. If you just want to send your first entity then you can create a variable of IMessageActivity and then forward that to your intended method.
["YourLuisIntent"]
public async Task YourLuisIntent(IDialogContext context, IAwaitable<IMessageActivity> argument, LuisResult result)
{
var message = await argument;
message .Text = result.Entities[0].Entity;
var dialog = new CheckListDialog();
await context.Forward(dialog, this.DialogResumeAfter, message , CancellationToken.None);
}
This is the conventional method of getting things done. But if you insist of passing the LuisResult to the method then Bot Framework lets you do that you can do the following:
Luis Dialog
["YourLuisIntent"]
public async Task YourLuisIntent(IDialogContext context, LuisResult result)
{
var dialog = new CheckListDialog();
await context.Forward(dailog, this.DialogResumeAfter, result.Entities, CancellationToken.None);
}
CheckList Dialog
Here you are expecting a value of type IList and not IMessageActivity. You need to keep that in mind and only use this dialog to access the Luis Entities.
public Task StartAsync(IDialogContext context)
{
context.Wait<IList<EntityRecommendation>>(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IList<EntityRecommendation>> result)
{
var LuisResult = await result as IList<EntityRecommendation>;
foreach( var entity in LuisResult)
{
await context.PostAsync($"{entity.Entity} - {entity.Type}");
}
}
来源:https://stackoverflow.com/questions/50288842/after-call-context-forward-how-to-get-the-item-in-child-dialog