如何从来电来电webhook请求中获取来电?

时间:2017-12-28 08:43:06

标签: node.js twilio twilio-api

我打算在Twilio中为来电开发一个webhook:

app.post('/voice', (req, res) => {
  const twiml = new VoiceResponse();
  const caller = ...;
  twiml.say('hello, your number is ' + caller);
  res.type('text/xml');
  res.send(twiml.toString());
});

如何从请求中获取来电号码(req)?我不需要名字,只需要数字。

我无法在docs中找到调用webhook时POST主体中发送的内容。

1 个答案:

答案 0 :(得分:3)

您要查找的caller phone number位于req个对象中。

它是req.body.From

在您的示例const caller = ...;

变为const caller = req.body.From;

<强> 文档: