How can I use <Say> multiple times in one call? I have come up with an example for my question:
exports.handler = async function (context, event, callback) {
try {
const twiml = new Twilio.twiml.VoiceResponse();
const client = context.getTwilioClient();
console.log("The call is " + JSON.stringify(event.CallSid));
var i = 0;
const sentences = ['Ahoy there', 'How are you today?', 'Nice to meet you', 'Hope you have a great day', 'Goodbye'];
const intervalId = setInterval(async () => {
if (i < sentences.length) {
const resp = await client.calls(event.CallSid).update({
twiml: `<Response><Say>${sentences[i]}</Say></Response>`
});
i += 1;
} else {
clearInterval(intervalId);
return callback(null, twiml);
}
}, 3000); // update every 3 seconds
} catch (err) {
console.error(err);
}
};
Here, there are a set of four sentences that I would like to say separately every three seconds. I am following the update documentation here.
But, this doesn't seem to work. It just leads to a Twilio timeout. Is there a way to do this without having to recursively return a callback and redirect each time?
Try to construct a single TwiML instruction that includes all the
<Say>and use<Pause>to introduce the delays between the sentences.