我有一个演示机器人,它将用户的日期和时间作为输入,然后将其重复给他们。但是,它以 ISO-8601 格式重复,这是我不想要的。我设法在 Google Assistant 的内联编辑器中格式化,但它在 Facebook Messenger 中不起作用。有什么方法可以在 Messenger 的内联编辑器中格式化它吗?
这是我正在使用的代码,它在测试控制台中正确格式化,但在 Messenger 上仍然使用我在 Dialogflow 中输入的响应。(例如,当然,我会在 $Date 的 $Time 上为您安排一个调整。到时见!)
const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google');
const WELCOME_INTENT = 'Default Welcome Intent';
const FALLBACK_INTENT = 'Default Fallback Intent';
const TUNEUP_INTENT = 'Book Tune-Up';
const DATE_ENTITY = 'Date';
const TIME_ENTITY = 'Time';
const timeZone = 'Europe/Belgrade';
const app = dialogflow();
function getLocaleTimeString(dateObj){
return dateObj.toLocaleTimeString('en-US', { hour: 'numeric', hour12: true, timeZone: timeZone });
}
function getLocaleDateString(dateObj){
return dateObj.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric', timeZone: timeZone });
}
app.intent(TUNEUP_INTENT, (conv) => {
const date = getLocaleDateString(new Date(conv.parameters[DATE_ENTITY]));
const time = getLocaleTimeString(new Date(conv.parameters[TIME_ENTITY]));
const responses = [`Sure thing, I'll hook you up with a tune-up at ${time} on ${date}. See you then!`,
`Cool! So to recap - I'll book you with a tune-up on ${date} at ${time}. Thanks for booking!`,
`Great, you're booked for ${date} at ${time}. See you then!`];
conv.ask(responses[Math.floor(Math.random() * responses.length)]);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);