1

I'm trying to initiate calls on my mobile app (Inbound call ) through my node server. I have set up all credentials in the env file and cross-checked them many times. I'm doing so using the Twiml. I'm sending the below the Twiml response to Twilio but the call just keeps routing back to the Webhook URL. How can I route the call on the device if this is not the right way to do it.

Twiml Response :

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

My Node.js code

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

Solution: We need to initiate calls using the identity and Twilio will start sending VoIP notifications

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

2 Answers2

1

I believe the process you use is to redirect a received call to another number "new VoiceResponse()", i believa to you to originate a call you should use the code below. Please let me know if tha works.

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));

HamY_HaY
  • 29
  • 4
0

On Twilio you can create a new project,select you want to do calls and they will provide you the right code,just copy it and use node index.js in your application.Also if you have a trial version you can only call numbers you verified.

Flash
  • 169
  • 1
  • 6