简体   繁体   English

如何在 wehhook c# 中使用 dialogflow 中的权限助手意图

[英]how to use the Permission helper intent from dialogflow in wehhook c#

I'm new to dialogflow and trying to use permission handler to ask for location permission using .NET core webapi.我是 dialogflow 的新手,正在尝试使用权限处理程序来使用 .NET 核心 webapi 请求位置权限。 I've created intent, entities and event(google.assistent.permission) in dialogflow console.我在 dialogflow 控制台中创建了意图、实体和事件(google.assistent.permission)。 Now I want to send a request from my webapi to send the request to access location.现在我想从我的 webapi 发送请求以发送访问位置的请求。

Can somebody please provide a code sample how to send request to access location from my webhook?有人可以提供代码示例如何从我的 webhook 发送访问位置请求吗?

Dialogflow 请求权限

You need to include the helper intent DialogFlow JSON as part of the payload:您需要将帮助程序意图 DialogFlow JSON作为有效负载的一部分包括在内:

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

Alternatively, it can be added as a fulfillment message with the payload type 1 .或者,它可以作为负载类型为1的履行消息添加。

The payload struct can be parsed from JSON:可以从 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?""
          }
        }
      }
    }
  }
}");

Or created using the Protobuf API (slightly faster due to skipping the parsing step and type safe, but incredibly ugly):或者使用 Protobuf API 创建(由于跳过解析步骤和类型安全,速度稍快,但非常丑陋):

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

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).请记住,在有效负载中包含任何消息(这是调用帮助程序所必需的)将覆盖您之前添加的任何其他消息并忽略之后添加的任何消息(它们仍然是返回对象的一部分,但被 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.到那时,您还不如从头开始创建整个 JSON 响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM