问题描述
这是代码,我希望twilio从作为后路由的路由读取,但它不从那里读取xlm,在那里我想从用户那里获得数字,并根据呼叫期间的输入,然后我想要流程根据该输入进行工作。
.create({
method: 'POST',url: 'https://stormy-everglades-64562.herokuapp.com/voice',to: '+923047931504',from: '+17207344485'
})
.then(call => console.log(call.sid));
app.post('/voice',(request,response) => {
// Create TwiML response
const twiml = new VoiceResponse();
twiml.gather(
{
numDigits: 1,action: '/gather',},gatherNode => {
gatherNode.say('For sales,press 1. For support,press 2.');
}
);
// If the user doesn't enter input,loop
twiml.redirect('/voice');
// Render the response as XML in reply to the webhook request
response.type('text/xml');
response.send(twiml.toString());
});```
解决方法
请尝试以下操作:
app.post('/voice',(request,response) => {
// Create TwiML response
const twiml = new twilio.twiml.VoiceResponse();
const gather = twiml.gather(
{
numDigits: 1,action: '/gather',})
gather.say('For sales,press 1. For support,press 2.');
// If the user doesn't enter input,loop
twiml.redirect('/voice');
// res.set('Content-Type','text/xml');
response.type('text/xml');
response.send(twiml.toString());
});