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

拜拜、爱过 提交于 2020-02-06 13:10:30

问题


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.

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


回答1:


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

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

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

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?""
          }
        }
      }
    }
  }
}");

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
        })
      }
    })
  }
};

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.



来源:https://stackoverflow.com/questions/59100437/how-to-use-the-permission-helper-intent-from-dialogflow-in-wehhook-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!