Reputation: 45
I am trying to loop through a and give the customer 5 seconds then repeat prompt again, wait 5 seconds and after that redirect to my error handler. It is not clear how to do this in the documentation.
What I have found is the solutions to do the then to my current url, but this will just loop continuously and not what we want. We need to stop after n number of times.
gather.say(
'Please enter or say your 10 Digit Account number.',
{voice: 'alice', language: 'en-GB'}
);
gather.pause({
length: 5
});
twiml.redirect({
method: 'POST',
}, '/ivr/wager/account');
Upvotes: 0
Views: 1210
Reputation: 10801
If you are up to using Twilio Studio, there is an example using the Set Variable Widget as a counter along with Liquid Syntax, to increment the counter, otherwise you will need to maintain your own counter, which gets incremented, using a URL query parameter appended to your Redirect URL. See Twilio Function code below.
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let counter = event.count || 0;
if (counter < 3) {
counter ++;
let gather = twiml.gather({action: `https://anonymous-1234.twil.io/gatherLoopCheck`, input: ' dtmf',
timeout: 3,
numDigits: 1})
.say("Please enter a digit");
twiml.redirect(`https://anonymous-1234.twil.io/gatherLoopCheck?count=${counter}`);
return callback(null, twiml);
} else {
twiml.say("You've reached the limit!");
return callback(null, twiml);
}
};
Upvotes: 1