Reputation: 11
I'm trying to code an IVR in TwiML on the Twilio site. Ideally, what I would like to happen is:
I think I'm supposed to use action
somewhere, but I am not sure how to set "if" conditions for dialing. My knowledge on coding is extremely rudimentary at best, but here is what I have set up so far.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Pause length="2"/>
<Say voice="alice" language="en-gb">Thank you for calling our company, your number one source for commercial real estate listings.</Say>
<Gather numDigits="1">
<Say voice="alice" language="en-gb">Press 1 for Sales to Sign Up and Stand Out!</Say>
<Say voice="alice" language="en-gb">Press 2 for Support!</Say>
<Say voice="alice" language="en-gb">Press 3 for our company directory!</Say>
</Gather>
</Response>
Upvotes: 1
Views: 316
Reputation: 857
You are right - you have to use action on . This action URL will get "DIGITS" that user pressed and then you can take appropriate action.
See a sample below (action="/abcxyzDemoIvr").
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Pause length="2"/>
<Say voice="alice" language="en-gb">Thank you for calling our company, your number one source for commercial real estate listings.</Say>
<Gather numDigits="1" action="<urlHere>/abcxyzDemoIvr">
<Say voice="alice" language="en-gb">Press 1 for Sales to Sign Up and Stand Out!</Say>
<Say voice="alice" language="en-gb">Press 2 for Support!</Say>
<Say voice="alice" language="en-gb">Press 3 for our company directory!</Say>
</Gather>
</Response>
Sample of how you can organise your action URL for <Gather>
is also mentioned below :
app.post('/abcxyzDemoIvr',
function(i_Req,o_Res)
{
var ivrTwilRes = new twilio.TwimlResponse();
var iGathered=i_Req.body.Digits ;
if ( iGathered == 1)
{
ivrTwilRes.say("Action for Sales to Sign Up and Stand Out!");
ivrTwilRes.redirect( { method : 'GET' } , "/abcxyzDemoIvr_salesSignupAndStandOut" );
/*do your stuff here */
}
else if ( iGathered == 2 )
{
ivrTwilRes.say("Action for Support");
ivrTwilRes.redirect( { method : 'GET' } , "/abcxyzDemoIvr_support" );
/*do your stuff here */
}
else if ( iGathered == 3 )
{
ivrTwilRes.say("Action for CompanyDirectory");
ivrTwilRes.redirect( { method : 'GET' } , "/abcxyzDemoIvr_companyDirectory" );
/*do your stuff here */
}
else if ( iGathered == '*' )
{
ivrTwilRes.redirect( { method : 'GET' } , "/abcxyzDemoIvrMenu" );
}
else
{
ivrTwilRes.say("I'm sorry, that is not a valid choice. Please make a choice from the menu").redirect( { method : "GET" } );
}
ivrTwilRes.say("Thank you for calling my IVR . Goodbye.",
{
language:'en-gb',
voice : 'woman'
}
)
.pause({ length : 3 } )
.hangup();
o_Res.set('Content-Type','text/xml');
o_Res.send(ivrTwilRes.toString());
console.log("========================== Response Starts Here (for abcxyzDemoIvr post)============================");
console.log(o_Res);
console.log("========================== Response Ends Here (for abcxyzDemoIvr post)============================");
}
);
app.post('/abcxyzDemoIvr_CallAgent',
function(i_Req,o_Res)
{
var ivrTwilRes = new twilio.TwimlResponse();
var agentNum=i_Req.body.Digits ;
/*
console.log("========================== Request Starts Here (for abcxyzDemoIvr_CallAgent post)============================");
console.log(i_Req.body);
console.log("========================== Request Ends Here (for abcxyzDemoIvr_CallAgent post)============================");
*/
var whichAgent = /*your logic to get which number to dial */
ivrTwilRes.say("Connecting you to agent " + whichAgent )
.dial({callerId:'+447777777777',action:"/abcxyzDemoIvr_postCallHandler",method:"GET"},
function()
{
this.number('+44xxxxxxxxxx',{url:"/abcxyzDemoIvr_screenCaller",method:"GET"});
}
);
o_Res.set('Content-Type','text/xml');
o_Res.send(ivrTwilRes.toString());
}
);
Upvotes: 1