【问题标题】:How to pass data from RootDialog to LuisDialog in Bot Framework如何在 Bot Framework 中将数据从 RootDialog 传递到 LuisDialog
【发布时间】:2018-05-23 14:30:46
【问题描述】:

我正在尝试将我在 Rootdialog 中的用户名传递给我的 LuisDialog。但是 LuisDialog 中的所有意图只接受两个参数(IDialogContext context, LuisResult result)我不知道如何检索我从 `LuisResult 结果传递的数据。转发到 luis 对话框的代码是这样的:

await context.Forward(new Luis(), Resume, UserName, CancellationToken.None);

请问我该怎么做?哪个意图会收到数据?如何从 LuisResult 对象中检索数据?

【问题讨论】:

  • 不清楚:你想将数据从你的 RootDialog 传递给你的 LuisDialog,还是你想从你的 LuisResult 中获取数据?
  • 我想将数据从我的 RootDialog 传递到我的 LuisDialog 并在我的 LuisDialog 中检索这些数据

标签: .net botframework azure-language-understanding


【解决方案1】:

我正在尝试将我在 Rootdialog 中的用户名传递给我的 LuisDialog。

您可以尝试在您的 LuisDialog 类中定义一个构造函数来接受字符串类型参数,以便将用户名从 Rootdialog 传递给 LuisDialog。下面的代码sn -p对我有用,你可以参考一下。

在 LuisDialog 中:

[Serializable]
public class BasicLuisDialog : LuisDialog<object>
{

    private string uname = "";

    public BasicLuisDialog(string UserName) : base(new LuisService(new LuisModelAttribute(
        "{your_modelID_here}",
        "{your_subscriptionKey_here}", 
        domain: "{domain_here}")))
    {
        uname = UserName;
    }

    //....

    // Go to https://luis.ai and create a new intent, then train/publish your luis app.
    // Finally replace "Gretting" with the name of your newly created intent in the following handler
    [LuisIntent("Greeting")]
    public async Task GreetingIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    //....
    //for other intents
    //.... 

    private async Task ShowLuisResult(IDialogContext context, LuisResult result) 
    {
        await context.PostAsync($"You have reached {result.Intents[0].Intent}. UserName is : {uname}");
        context.Wait(MessageReceived);
    }
}

在 RootDialog 中:

var UserName = "Fei Han";
await context.Forward(new BasicLuisDialog(UserName), AfterLuis, activity, CancellationToken.None);

测试结果:

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 2016-10-30
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多