简体   繁体   中英

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. 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?

Dialogflow 请求权限

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 type 1 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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