如果文本中未指定时间,DialogFlow 将 12:00:00 设置为一天的开始
DialogFlow sets 12:00:00 as a beginning of the day if time isn't specified in text
我正在学习使用 DialogFlow 构建聊天机器人。例如,我创建了一个简单的意图来报告我当前的体重。我在我的服务器上构建端点以接收数据作为履行请求以将其保存到数据库中。
作为数据参数,我将重量指定为@sys.unit-重量,将日期指定为@sys.date。当我用“今天”或“明天”一词指定日期时,日期部分被正确解析,但 DialogFlow 添加 12:00:00 作为时间部分。这有点奇怪,我真的不明白那个时候的意义是什么。看起来不正确。
我附上了在 DialogFlow 的控制台中执行意图的屏幕截图以及履行请求有效负载。有没有人知道如何在没有时间的情况下或在没有提供时间的情况下使用 00:00:00 获取日期?
Screen shot of triggering intent by DialogFlow's console
{
"responseId": "518945f5-33bf-43a8-86ce-42e422033e6c-425db6e2",
"queryResult": {
"queryText": "yes",
"action": "TrackWeight",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Your weight log was saved. Do you want anything else?",
"fulfillmentMessages": [
{
"text": {
"text": [
"Your weight log was saved. Do you want anything else?"
]
}
}
],
"outputContexts": [
{
"name": "projects/chatbot-59dda/agent/sessions/414dfa61-4850-eb27-804a-afea25516ab8/contexts/trackweight-followup",
"parameters": {
"weight": {
"amount": 50,
"unit": "kg"
},
"weight.original": "50 kg",
"date": "2020-07-09T12:00:00+03:00",
"date.original": "today"
}
},
{
"name": "projects/chatbot-59dda/agent/sessions/414dfa61-4850-eb27-804a-afea25516ab8/contexts/__system_counters__",
"parameters": {
"no-input": 0,
"no-match": 0
}
}
],
"intent": {
"name": "projects/chatbot-59dda/agent/intents/c8bafb9d-1c44-401c-877f-9929d4fc23c2",
"displayName": "Track Weight - yes"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
},
"originalDetectIntentRequest": {
"payload": {}
},
"session": "projects/chatbot-59dda/agent/sessions/414dfa61-4850-eb27-804a-afea25516ab8"
}
在此先感谢您的帮助!
这就是 Dialogflow 报告的格式 date/time。您需要做的就是将日期和时间分开并将其转换为您需要的格式。
您可以通过 agent.parameters.date
或 agent.parameter.time
访问日期或时间,格式仍然相同。以下是一些可以提供帮助的功能:
function convertParametersDateTime(date, time){
return new Date(Date.parse(date.split('T')[0] + 'T' + time.split('T')[1].split('+')[0]));
}
// A helper function that adds the integer value of 'hoursToAdd' to the Date instance 'dateObj' and return a new Data instance.
function addHours(dateObj, hoursToAdd){
return new Date(new Date(dateObj).setHours(dateObj.getHours() + hoursToAdd));
}
// A helper funciton that converts the Date instance 'dateObj' into a string that represents this time in English.
function getLocaleTimeString(dateObj){
return dateObj.toLocaleTimeString('en-US', {hour: 'numeric', hour12: true});
}
// A helper dunction that converts the Date instance 'dateObj' into a string that represents this date in English
function getLocaleDateString(dateObj){
return dateObj.toLocaleDateString('en-US', {weekday: 'long', month: 'long', day: 'numeric'});
}
想法是您可以按 'T'
拆分并使用您需要的部分
我正在学习使用 DialogFlow 构建聊天机器人。例如,我创建了一个简单的意图来报告我当前的体重。我在我的服务器上构建端点以接收数据作为履行请求以将其保存到数据库中。
作为数据参数,我将重量指定为@sys.unit-重量,将日期指定为@sys.date。当我用“今天”或“明天”一词指定日期时,日期部分被正确解析,但 DialogFlow 添加 12:00:00 作为时间部分。这有点奇怪,我真的不明白那个时候的意义是什么。看起来不正确。
我附上了在 DialogFlow 的控制台中执行意图的屏幕截图以及履行请求有效负载。有没有人知道如何在没有时间的情况下或在没有提供时间的情况下使用 00:00:00 获取日期?
Screen shot of triggering intent by DialogFlow's console
{
"responseId": "518945f5-33bf-43a8-86ce-42e422033e6c-425db6e2",
"queryResult": {
"queryText": "yes",
"action": "TrackWeight",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Your weight log was saved. Do you want anything else?",
"fulfillmentMessages": [
{
"text": {
"text": [
"Your weight log was saved. Do you want anything else?"
]
}
}
],
"outputContexts": [
{
"name": "projects/chatbot-59dda/agent/sessions/414dfa61-4850-eb27-804a-afea25516ab8/contexts/trackweight-followup",
"parameters": {
"weight": {
"amount": 50,
"unit": "kg"
},
"weight.original": "50 kg",
"date": "2020-07-09T12:00:00+03:00",
"date.original": "today"
}
},
{
"name": "projects/chatbot-59dda/agent/sessions/414dfa61-4850-eb27-804a-afea25516ab8/contexts/__system_counters__",
"parameters": {
"no-input": 0,
"no-match": 0
}
}
],
"intent": {
"name": "projects/chatbot-59dda/agent/intents/c8bafb9d-1c44-401c-877f-9929d4fc23c2",
"displayName": "Track Weight - yes"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
},
"originalDetectIntentRequest": {
"payload": {}
},
"session": "projects/chatbot-59dda/agent/sessions/414dfa61-4850-eb27-804a-afea25516ab8"
}
在此先感谢您的帮助!
这就是 Dialogflow 报告的格式 date/time。您需要做的就是将日期和时间分开并将其转换为您需要的格式。
您可以通过 agent.parameters.date
或 agent.parameter.time
访问日期或时间,格式仍然相同。以下是一些可以提供帮助的功能:
function convertParametersDateTime(date, time){
return new Date(Date.parse(date.split('T')[0] + 'T' + time.split('T')[1].split('+')[0]));
}
// A helper function that adds the integer value of 'hoursToAdd' to the Date instance 'dateObj' and return a new Data instance.
function addHours(dateObj, hoursToAdd){
return new Date(new Date(dateObj).setHours(dateObj.getHours() + hoursToAdd));
}
// A helper funciton that converts the Date instance 'dateObj' into a string that represents this time in English.
function getLocaleTimeString(dateObj){
return dateObj.toLocaleTimeString('en-US', {hour: 'numeric', hour12: true});
}
// A helper dunction that converts the Date instance 'dateObj' into a string that represents this date in English
function getLocaleDateString(dateObj){
return dateObj.toLocaleDateString('en-US', {weekday: 'long', month: 'long', day: 'numeric'});
}
想法是您可以按 'T'
拆分并使用您需要的部分