MS Bot如何将Luis实体转发给子Dialog

时间:2018-04-18 10:47:32

标签: c# botframework luis

我正在尝试将EntitiesLuisResults转发到子对话框类。任何人都可以协助如何解决这个问题吗?

Luis Dialog Class

...
[LuisIntent("Foo")]
public async Task Foo(IDialogContext context, LuisResult result)
{
    var entities = result.Entities;
    await context.Forward(new FooDialog(), AfterFooDialog, entities, 
    CancellationToken.None);
}
...

FooDialog Class

...
public async StartAsync(IDialogContext context)
{
    context.Wait(MessageReceivedAsync);
}

private async Task MessageReceivedAsync(IDialogContext context, List<string> entities, IAwaitable(IMessageActivity) result)
{
    var _entites = await entities;
    ...

}
...

1 个答案:

答案 0 :(得分:1)

执行此操作的一种方法是,通过构造函数初始化FooDialog中的实体。因此,在从FooDialog转发实体时,将实体传递给构造函数中的LuisDialog

所以你的代码是:

Luis Dialog

[LuisIntent("Foo")]
    public async Task Foo(IDialogContext context, LuisResult result)
    {
        var entities = result.Entities;
        await context.Forward(new FooDialog(entities), AfterFooDialog, entities, CancellationToken.None);
    }

你的 FooDialog

[Serializable]
public class FooDialog : IDialog<object>
{
    public IList<EntityRecommendation> _entities { get; set; }

    public FooDialog(IList<EntityRecommendation> entities)
    {
        this._entities = entities;
    }

    public FooDialog()
    {}

    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(this.MessageReceivedAsync);
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result )
    {
        await context.PostAsync("Entity : " + _entities.First().Entity);
    }

}

所以现在你有了FooDialog类中的实体,并且可以被对象中的任何函数访问。