我正在尝试在Twilio网站上使用TwiML编写IVR代码。理想情况下,我想要发生的是:
我想我应该在某个地方使用action
,但我不确定如何设置拨号的“if”条件。我对编码的知识充其量只是极其简陋,但这是我到目前为止所建立的。
<?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>
答案 0 :(得分:1)
你是对的 - 你必须采取行动。此操作URL将获得用户按下的“DIGITS”,然后您可以采取适当的操作。
请参阅下面的示例( 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>
下面还提到了如何整理<Gather>
操作网址的示例:
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());
}
);