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

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
dialogflow V2: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?

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

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 :)
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:
and the corresponding slot fulfillment which you can see has the correct time zone:
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:00which is correct. Are you completely sure thatprocess.env.TZis populated and that you are using the v2 API?