Can I get requester's local time (or offset) from Actions On Google?
Asked Answered
R

2

6

I'm building on the Actions On Google API using API.ai. In order to fulfil one of my actions I need to know the user's location and local time.

I have been able to successfully ask for and receive back the user's location.

However, I cannot see any way of getting the user's local time or timezone offset. Is there a way to do this?

(I realise that I could use the location to find out the offset but that would require another API call or use of another library, which I'd rather avoid.)

Thanks in advance.

-- Update --

As per Leon's answer below and as of 18th Jan 2017 this info isn't currently provided by the API. In order to get the required info I requested permission for the user's precise location, which returns lat and lng. I then used the GeoNames timezone API to get the timezone offset.

Rainband answered 18/1, 2017 at 11:30 Comment(2)
Would it be an option to use @sys.date-time as an Entity in the request?Harrow
Mmm, that could be an option to get it but as I understand it the user would first have to be encouraged to say a date and time that would be matched by the entity. I don't think the entity slot would be filled without this... Unless you know differently?Rainband
A
0

The device's timezone isn't provided to the action yet.

Artimas answered 18/1, 2017 at 16:35 Comment(1)
Thanks for answering, Leon. It seems to me that it'd be a useful and not particularly privacy-invasive piece of info to provide so hopefully it'll be provided soon and I'll be able to add an addendum here. In the meantime, I guess that is the answer :)Rainband
F
3

Whilst the timezone isn't included natively yet to my knowledge. You can use location permission alongside libraries to get the local time dynamically.

The libraries I have used here are momentTz and timezone. The latter gets the timezone interpolated from lat/long supplied by location permission. The resolved timezone is then used to convert the standard time in UTC which momentTz provides natively to the local time sought.

const startTz = momentTz(); //Returns standard UTC time, independent of locality
const timestamp = 1402629305; // Any random timestamp will work, it wouldn't unnecessarily impede your results 

timezone.data(latitudeValue, longitudeValue, timestamp, function(err, tz) {
  if (err) {
    console.log(err);
  }

var zoneHolder = tz.raw_response.timeZoneId; //Appropriate timezone is returned here based on latitudeValue and longitudeValue passed
const localTime = startTz.tz(zoneHolder).format('LLL'); //local time which you seek;
});
Fylfot answered 2/4, 2018 at 11:59 Comment(2)
Thanks for the answer. Looks similar to what I ended up doing except that I do the timzone interpolation via the Geonames API. Does the timezone library you reference do the interpolation offline? Or does it also require a call out to a 3rd party API? Can you please add a link to the timezone library as from a quick Google search, I'm not sure which you are using.Rainband
You are welcome. I am not certain the interpolation is offline..., In my case though, I am running other requests online simultaneously whenever I utilise the call, so it might be difficult to exactly tell. See the link here: (npmjs.com/package/node-google-timezone)Fylfot
A
0

The device's timezone isn't provided to the action yet.

Artimas answered 18/1, 2017 at 16:35 Comment(1)
Thanks for answering, Leon. It seems to me that it'd be a useful and not particularly privacy-invasive piece of info to provide so hopefully it'll be provided soon and I'll be able to add an addendum here. In the meantime, I guess that is the answer :)Rainband

© 2022 - 2024 — McMap. All rights reserved.