Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

node.js - Twilio how to make two outbound calls and join(conference) them using node js

I have to make two outbound calls to two random mobile numbers and join both of them in conference using node.js. Is there a way to make it possible using twilio and node.js.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Twilio developer evangelist here.

You say you are getting two numbers provided to you and you need to make calls to both of them, joining them up in a conference. You can use the REST API to make the calls and here's a basic example of a function that would create those calls using the Node.js Twilio module:

const accountSid = 'your_account_sid';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

function connectNumbers(number1, number2) {
  [number1, number2].forEach(function(number) {
    client.calls.create({
      url: 'https://example.com/conference',
      to: number,
      from: 'YOUR_TWILIO_NUMBER',
    })
    .then((call) => process.stdout.write(`Called ${number}`));
  })
}

When the calls connect, Twilio will make an HTTP request to the URL supplied.

You would then need a server application on your own URL (in place of example.com in the function above) that could return the TwiML to set up the conference.

<Response>
  <Dial>
    <Conference>Room Name</Conference>
  </Dial>
</Response>

[edit]

If you want to play a message before users join the conference, you just need to use the <Say> TwiML verb before you <Dial>. Like this:

<Response>
  <Say voice="alice">This is a call from xyz.org</Say>
  <Dial>
    <Conference>Room Name</Conference>
  </Dial>
</Response>

Let me know if that helps at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...