首页 > 解决方案 > 未使用 Twilio 节点服务器发起来电(未发送 VoIP 通知) - 已修复

问题描述

我正在尝试通过我的节点服务器在我的移动应用程序(入站呼叫)上发起呼叫。我已经在 env 文件中设置了所有凭据并多次交叉检查它们。我正在使用 Twiml 这样做。我正在向 Twilio 发送下面的 Twiml 响应,但调用只是继续路由回 Webhook URL。如果这不是正确的方法,我如何在设备上路由呼叫。

Twiml 响应:

  <Response>
    <Dial>
      <Number>+12528881526</Number>
    </Dial>
  </Response>

我的 Node.js 代码

  let twimlResponse = new VoiceResponse()
  const dial = twimlResponse.dial()
  dial.number({}, "+1234567891")
  console.log(twimlResponse.toString())
  return response.send(twimlResponse.toString())

解决方案: 我们需要使用身份发起呼叫,Twilio 将开始发送 VoIP 通知

  let twimlResponse = new VoiceResponse()
  const dial = twimlResponse.dial()
  dial.client({}, "alice")
  console.log(twimlResponse.toString())
  return response.send(twimlResponse.toString())

标签: node.jstwiliotwilio-twimltwilio-programmable-voice

解决方案


我相信您使用的过程是将收到的呼叫重定向到另一个号码“new VoiceResponse()”,我相信您要发起呼叫,您应该使用下面的代码。请让我知道 tha 是否有效。

const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

client.calls
      .create({
         twiml: '<Response><Say>Ahoy there!</Say></Response>',
         to: '+15558675310',
         from: '+15552223214'
       })
      .then(call => console.log(call.sid));


推荐阅读