如何在Wehhook C#中使用来自对话框流的权限帮助器意图 [英] how to use the Permission helper intent from dialogflow in wehhook c#

查看:103
本文介绍了如何在Wehhook C#中使用来自对话框流的权限帮助器意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是dialogflow的新手,并尝试使用权限处理程序通过.NET核心webapi来请求位置权限。我已经在dialogflow控制台中创建了意图,实体和事件(google.assistent.permission)。现在,我想从我的webapi发送一个请求,以将请求发送到访问位置。

I'm new to dialogflow and trying to use permission handler to ask for location permission using .NET core webapi. I've created intent, entities and event(google.assistent.permission) in dialogflow console. Now I want to send a request from my webapi to send the request to access location.

请问有人可以提供代码示例如何从我的Webhook发送访问位置的请求?

Can somebody please provide a code sample how to send request to access location from my webhook?

推荐答案

您需要添加帮助程序意图DialogFlow JSON 作为有效负载的一部分:

You need to include the helper intent DialogFlow JSON as part of the payload:

WebhookResponse response;
Struct payload;
response.Payload = payload;

或者,也可以将其添加为有效载荷类型为 1

Alternatively, it can be added as a fulfillment message with the payload type1.

有效载荷结构可以从JSON中解析:

The payload struct can be parsed from JSON:

response.Payload = Struct.Parser.ParseJson(@"{
  ""google"": {
    ""expectUserResponse"": true,
    ""systemIntent"": {
      ""intent"": ""actions.intent.PLACE"",
      ""data"": {
        ""@type"": ""type.googleapis.com/google.actions.v2.PlaceValueSpec"",
        ""dialogSpec"": {
          ""extension"": {
            ""@type"": ""type.googleapis.com/google.actions.v2.PlaceValueSpec.PlaceDialogSpec"",
            ""permissionContext"": ""To find a location"",
            ""requestPrompt"": ""Where would you like to go?""
          }
        }
      }
    }
  }
}");

或使用Protobuf API创建(由于跳过了解析步骤并输入安全,因此速度略快,但令人难以置信丑陋):

Or created using the Protobuf API (slightly faster due to skipping the parsing step and type safe, but incredibly ugly):

response.Payload = new Struct
{
  Fields =
  {
    ["google"] = Value.ForStruct(new Struct
    {
      Fields =
      {
        ["expectUserResponse"] = Value.ForBool(true),
        ["systemIntent"] = Value.ForStruct(new Struct
        {
          // ... and so on
        })
      }
    })
  }
};

请记住,在有效负载中包括任何消息(调用帮助程序是必需的)您之前添加的所有其他消息,然后忽略之后添加的任何消息(它们仍然是返回对象的一部分,但被DialogFlow删除了)。这意味着:如果您需要任何其他丰富的响应,则当前还需要将其手动添加到有效负载中。此时,您最好从头开始创建整个JSON响应。

Keep in mind that including any message in the payload (which is necessary to call the helper) will override any other messages you added previously and ignore anything added afterwards (they are still part of the returned object, but stripped out by DialogFlow). That means: If you want any other rich response, it currently also needs to be manually added to the payload. At that point, you might as well create the entire JSON response from scratch.

这篇关于如何在Wehhook C#中使用来自对话框流的权限帮助器意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆