简体   繁体   中英

How to make twilio outbound call types in nodejs

i found two examples on making an outbound call using twilio , and i was not clear about the difference among them 1]

client.calls.create({
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  from: '+15017250604',
})
.then((call) => process.stdout.write(call.sid));

This is the first procedure which is clear to me where 'to' and 'from' are listed

2]

const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();
response.dial('415-123-4567');
response.say('Goodbye');

console.log(response.toString());

Here in the second code , 'from' parameter is not there and also its different

Do both work the same ? Which one is better for making outbound calls using node.js

Also can i replace the 'url' parameter in the first method with the TwiML written in node.js ie second method

Twilio developer evangelist here.

The different methods there are using the REST API and TwiML to make calls respectively. There's more to your question though.

When you want to generate a new call you need to use the REST API . This allows you to set the number you want to call and the Twilio number you are calling from. You also need to set a URL in this request, as you included in this example.

When the call connects from your REST API outbound call, Twilio will make an HTTP request, a webhook, to that URL to find out what to do next. Your URL needs to respond with TwiML which describes what to do next. You can make a simple response like <Say> , <Play> or <Record> , but you can also <Dial> the call onto another number. This is technically another outbound call, but you can only make a call in this way in reaction to a webhook from Twilio.

Let me know if this makes things more clear for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM