0

Currently i am using Bot Framework with Node for my chat bot and i am using API AI as my Natural Language Processing.

My question is, let say the user replied with "yesterday" or "today" or "tomorrow" and it is base on the server time. Now, it will go wrong if a person in Australia says today at 6 AM in the morning and their time which is in GMT will still be previous day and this gives a wrong date.

May i have suggestion on how do i solve this timezone issue?

  • So your question basically is [how to get the client's local time](https://stackoverflow.com/questions/10659523/how-to-get-the-exact-local-time-of-client)? – lenz Aug 29 '17 at 07:14
  • No, because the date is an entities in the API AI, so when i retrieve it how do i ensure that the entities is "yesterday", "today" or "tomorrow" date? Example i told the chatbot "today at 6 AM..." the server would still retrieve the date from yesterday and when i retrieve the entities from my NodeJS it will still be the yesterday date. – coffeeman Aug 29 '17 at 08:00
  • And to add on, i need to check whether the entities exist before i retrieve the date, therefore if the entities exist i am only able to retrieve the date base on the server response – coffeeman Aug 29 '17 at 08:08
  • Ok, I don't know this API, but it seems pretty high-level. I suggest you clarify your post with an example that shows (1) what information exactly you get (eg. show a fragment of the response) and (2) what you want to have instead. Timezone problems get confusing quickly, so be sure to make very clear which timestamp is local or UTC, and what it should be (and why). For example, for an Australian user, the bot should behave as if it was in Australia as well, I think (ie. using local time), but you might want to have UTC timestamps in some database, etc. – lenz Aug 29 '17 at 08:51
  • This can be confusing to humans too. What do you expect from computers? – Daniel Aug 29 '17 at 14:00
  • Just asking is there any solution for this? – coffeeman Aug 29 '17 at 15:21

1 Answers1

1

Each API.AI agent has a default time zone setting which can be altered in your agents settings (documentation here) which will be used to determine the meaning of user's date/time queries like "tomorrow" and "yesterday" and "3pm":

enter image description here

If you're using API.AI's /query API you can send the timezone parameter in the request JSON to indicate what timezone the user you are sending the request on behalf of is in.

mattcarrollcode
  • 3,429
  • 16
  • 16
  • May i know how do you do that in Node JS? Can i have some examples? Thanks – coffeeman Aug 30 '17 at 01:57
  • What are you looking for an example of? – mattcarrollcode Aug 30 '17 at 03:57
  • For example an user enter "yesterday" or "today" or "tomorrow" in the chatbot, How am i going to send the timezone parameter to request for the JSON to find out the user timezone? – coffeeman Aug 30 '17 at 04:05
  • If you're using a one-click integration (i.e. Google Assistant, Facebook Messenger, Slack, etc.) you can't set the timezone parameter for those requests and they will default to the default time zone of the agent. If you're using the query endpoint just include the timezone parameter in the top level of the JSON object in your request to the /query endpoint. – mattcarrollcode Aug 30 '17 at 04:16