I'm trying to build a very simple Dialogflow app for Actions on google.
What I had in mind was a very simple timer, but every X seconds the agent will tell the user "X seconds left".
I'm using the Fulfillment section on dialogflow. What I've tried to do was a simple "setTimeout" that include another agent.add but this seems to be ignored by Dialogflow when I deploy it:
function startTimer(agent)
{
agent.add("Timer started! 20 seconds from now.");
setTimeout(function(){
agent.add("10 seconds left!");
}, 10000);
agent.add("Time out.");
}
let intentMap = new Map();
intentMap.set('timer', startTimer);
agent.handleRequest(intentMap);
The response from assistant is a simple "Timer started" and "Time out", without the X seconds remaining. Is there any way to add a reply when an intent is started? Thanks!
EDIT | as suggested, I have tried with SSML, but the tags are displayed on the screen when they get said by the assistant.
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function startTimer(agent)
{
agent.add("Something to say");
agent.add(`<speak><seq><media begin="30s"><speak>30 seconds</speak></media><media begin="30s"><speak>1 minute</speak></media></seq></speak>`);
agent.add(new Suggestion(`Quit`));
}
let intentMap = new Map();
intentMap.set('timer-go', startTimer);
agent.handleRequest(intentMap);
});
It's not possible to an Action start a conversation, the fulfillment code (your function) must return within 10 seconds, or the Google Assistant will close the Action with a time-out warning.
And your setTimeout is not working because this code is running in the cloud, and to actually send it back to the Assistant, you must send the response, and you are only adding items to it, but not returning the object.
This page from DialogFlow documentation explains how the back-end fulfillment works on DialogFlow / Google Assistant.
You can use SSML in your response and set when to respond.
e.g.
Also, check for more information.