Twilio出站呼叫API-如何在出站呼叫接收者的语音邮件上放置记录?

时间:2019-06-20 12:27:47

标签: node.js twilio twilio-api

假设我要向餐馆老板发出自动呼叫的订单,如果餐馆老板没有接电话,我想记录TWIML响应并将其放入餐馆老板的语音信箱中。我已经看到了有关拨入电话的语音邮件的文档,但是拨出电话该怎么做?

router.post('/voice', (request, response) => {

  var parentSpeech = request.query.parentSpeech

  const twiml = new VoiceResponse();

  /** helper function to set up a <Gather> */
  function gather() {

    const gatherNode = twiml.gather({ numDigits: 1 });

    gatherNode.say(parentSpeech);

    // If the user doesn't enter input, loop
    twiml.redirect("/twilio/voice?parentSpeech=" + parentSpeech);
  }


  // If the user entered digits, process their request
  if (request.body.Digits) {
    switch (request.body.Digits) {
      case '1':
          twiml.say('You have accepted the order. An email notification will be sent to you and customer shortly. Thank you for using FoodieBee and have a nice day!');
          break;
      case '2':
          twiml.say('You have rejected the order. An email notification will be sent to you and customer shortly. Thank you for using FoodieBee and have a nice day!');
          break;
      default:
          twiml.redirect("/twilio/voice?parentSpeech=" + parentSpeech);            
          break;
    }
  } else {
    // If no input was sent, use the <Gather> verb to collect user input
    gather();
  }

  // Render the response as XML in reply to the webhook request
  response.type('text/xml');
  response.send(twiml.toString());
});

以上是在餐厅老板拿起电话时可以正常使用的代码。如果接收者不接电话,我会尝试将此twiml响应放入接收者的语音邮件中。

1 个答案:

答案 0 :(得分:0)

不确定是否仍需要它,但是参数机器检测= DetectMessageEnd似乎是您所需要的。