1

I have a demo bot which takes in the user's date & time as inputs, and just repeats it back to them. However, it gets repeated in the ISO-8601 format, which I don't want. I managed to format in the inline editor for Google Assistant, but it doesn't work in Facebook Messenger. Is there any way I can format it in the inline editor for Messenger as well?

This is the code I'm using, it formats it correctly in the test console, but on messenger in still uses the responses that I entered in Dialogflow. (e.g. Sure thing, I'll hook you up with a tune-up at $Time on $Date. See you then!)

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);
zzzz4
  • 23
  • 1
  • 6

1 Answers1

2

You're on the right track - you need to use a fulfillment webhook to format the result the way you want it.

However, you're using the actions-on-google library, which only produces responses for the Google Assistant. If you want to produce output across all the integrations that Dialogflow supports, you should look into the dialogflow-fulfillment library. The concepts for it are similar to actions-on-google, but there are some slight style differences.

Prisoner
  • 49,922
  • 7
  • 53
  • 105