How to fetch device location using API AI?

后端 未结 5 1010
情歌与酒
情歌与酒 2021-01-05 00:56

I am using GUI tools provided by API AI to create Actions. Is it possible to fetch device location? I have heard that this is possible by requesting permissions. Is this doc

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 01:17

    I was struggling with this for so long. I found this forum and something clicked. Turns out it's really not that hard.

    In your php webhook, your original intent should return this as json -- or json_encode this array:

    array(
    'data' => 
     array(
     'google' => 
      array(
       'expectUserResponse' => true,
       'systemIntent' => 
       array(
         'intent' => 'actions.intent.PERMISSION',
         'data' => 
       array(
           '@type' => 
          'type.googleapis.com/google.actions.v2.PermissionValueSpec',
           'optContext' => 'To find the closest site ',
           'permissions' => 
    
            'DEVICE_PRECISE_LOCATION'
          ,
           ),
         ),
       ),
     ),
    )
    

    then create another intent with the event: actions_intent_PERMISSION

    In your php webhook for the newly created intent, you will now have the location returned. It is in the response: ["originalRequest"]['data']['device']['location']['coordinates']

    Easy Peasy...

提交回复
热议问题