Nodejs-dialogflow: timeZone in detectIntent api not working

Created on 1 Jun 2018  路  2Comments  路  Source: googleapis/nodejs-dialogflow

I am working on some kind of reminder bot using dialogFlow (API v2)

Here is my problem

I am passing the timeZone in detectIntent API as follows

const query = 'remind me to check backup sync at 5pm';
const languageCodeDefault = 'en-US';
const timeZoneDefault = process.env.TZ; // {Asia/Karachi}

// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();

// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);

// The text query request.
const request = {
    session: sessionPath,
    queryInput: {
        text: {
            text: query,
            languageCode: languageCodeDefault,
        },
    },
    queryParams: {
        timeZone: timeZoneDefault,
    },
};

sessionClient
                .detectIntent(request)
                .then(responses => {

                    console.log('Detected intent');
                    const result = responses[0].queryResult;
                    // console.log(`  Query: ${result.queryText}`);
                    // console.log(`  Response: ${result.fulfillmentText}`);

                    if (result.intent) {
                        console.log(`  Intent: ${result.intent.displayName}`);
                    } else {
                        console.log(`  No intent matched.`);
                    }
                    resolve(responses);
                })
                .catch(err => {
                    console.error('ERROR:', err);
                    reject(err);
                });

but dialogFlow is picking up the Default Time Zone defined in dialogFlow Agent's settings
image

here are my params extracted from dialogFlow query

{date_time: 
   { stringValue: '2018-06-01T17:00:00+02:00',
     kind: 'stringValue' },
  remindeMeEntities: { listValue: { values: [Object] }, kind: 'listValue' },
  task_title: { stringValue: 'check backup sync', kind: 'stringValue' } }

checkout date_time param value i.e 2018-06-01T17:00:00+02:00 it has timeZone +02:00, but it should be Asia/Karachi timeZone which is GMT+5:00

Environment details

  • OS:
  • Node.js version: v6.3.0
  • npm version: 3.10.3
  • dialogflow V2:
triage me dialogflow

Most helpful comment

Hello @qadirsuh

I'm not on the dialogflow team, but I had a similar problem before. Here is a payload that works fork me:

{
  "session": sessionPath,
  "queryParams": {
    "timeZone": "America/Detroit"
  },
  "queryInput": {
    "text": {
      "text": "what happened at 8am today",
      "languageCode": "en-US"
    }
  }
}

and the corresponding slot fulfillment which you can see has the correct time zone:

{ "date-time": { "date_time": "2018-06-15T08:00:00-04:00" } }

I don't see any immediate difference, but maybe the Asia/Karachi timezone isn't a recognized timezone by dialogflow? Only timezones in the time zone database are recognized by dialogflow. Maybe try one like "America/Detroit" that is confirmed working to see if it makes a difference.

edit: I just tried "Asia/Karachi" and received 2018-06-15T08:00:00+05:00 which is correct. Are you completely sure that process.env.TZ is populated and that you are using the v2 API?

screen shot 2018-06-15 at 10 34 02 am

All 2 comments

Hello @qadirsuh

I'm not on the dialogflow team, but I had a similar problem before. Here is a payload that works fork me:

{
  "session": sessionPath,
  "queryParams": {
    "timeZone": "America/Detroit"
  },
  "queryInput": {
    "text": {
      "text": "what happened at 8am today",
      "languageCode": "en-US"
    }
  }
}

and the corresponding slot fulfillment which you can see has the correct time zone:

{ "date-time": { "date_time": "2018-06-15T08:00:00-04:00" } }

I don't see any immediate difference, but maybe the Asia/Karachi timezone isn't a recognized timezone by dialogflow? Only timezones in the time zone database are recognized by dialogflow. Maybe try one like "America/Detroit" that is confirmed working to see if it makes a difference.

edit: I just tried "Asia/Karachi" and received 2018-06-15T08:00:00+05:00 which is correct. Are you completely sure that process.env.TZ is populated and that you are using the v2 API?

screen shot 2018-06-15 at 10 34 02 am

Thanks @dyladan its working now. I don't know why it was not working.
actually I am creating a Telegram bot and Telegram is banned in our country (Pakistan), I am using the a freeVPN.com
image

may be that was affecting at that time.

Now I am getting the correct date returned from dialogFlow.com
date_time 2018-06-21T20:00:00+05:00
Note: VPN is active still and its working fine too :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avallone-google picture avallone-google  路  3Comments

yusufkhan07 picture yusufkhan07  路  5Comments

BenjaminHoegh picture BenjaminHoegh  路  7Comments

jdelman picture jdelman  路  5Comments

yanniks picture yanniks  路  8Comments