如何在 DialogFlow 中为 Facebook Messenger 响应设置 @sys.date & @sys.time 的格式?

How do I format the @sys.date & @sys.time for a Facebook Messenger response in DialogFlow?

我有一个演示机器人,它接受用户的日期和时间作为输入,然后将它重复给他们。但是,它以我不想要的 ISO-8601 格式重复出现。我设法在 Google 助手的内联编辑器中设置了格式,但它在 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);

您走在正确的轨道上 - 您需要使用 fulfillment webhook 按照您想要的方式格式化结果。

但是,您使用的是 actions-on-google 库,它只为 Google 智能助理生成响应。如果您想在 Dialogflow 支持的所有集成中生成输出,您应该查看 dialogflow-fulfillment library。它的概念类似于 actions-on-google,但有一些细微的风格差异。