当我在 Dialogflow 意图中使用“日期”实体时,我希望它根据特定时区解释
today
的日期。
该时区可能因会话而异,因为我的网络客户端知道用户的特定时区,并且可以在请求中或首次启动会话时传达这一点。
目前,Dialogflow 仅使用 UTC,因此如果用户位于加利福尼亚州,UTC-7,并且在加利福尼亚州为
January 1st, 9pm
,则在 UTC 中为 4am on January 2n
d,因此用户说 today
会被解释为 January 2nd
而不是所需的 January 1st
。
根据docs,发送查询时有一个
timezone
参数:
POST /query sample
HTTPCURL
curl \
https://api.dialogflow.com/v1/query?v=20150910 \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN' \
-d '{
"contexts": [
"shop"
],
"lang": "en",
"query": "I need apples",
"sessionId": "12345",
"timezone": "America/New_York"
}'
因此,如果您知道用户的时区,则只需在每次请求时发送即可。
对于 API V2 代理,可以发送时区
queryParams.timeZone
const sessionClient = new dialogflow.SessionsClient({
keyFilename: '/path/to/google.json'
});
const sessionPath = sessionClient.sessionPath('[PROJECT_ID]', '[SESSION_ID]');
const request = {
session: sessionPath,
queryInput: {
text: {
text: 'query',
languageCode: 'en'
}
},
queryParams: {
timeZone: 'America/New_York'
}
};
sessionClient.detectIntent(request)
.then(res => console.log(res))
.catch(err => console.error(err))