1

I am currently doing using node js twilio module for a functionality in a project that i am working on for a client. Basically the server is going to initiate a call using twilio api to call a certain person A the connect him to another person B. I am new to twilio so i am still a noob, but this is the code i have written so far. Please i need u guys input on how to achieve this. cheers

var client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

exports.makeCall = function(callDetails, cb) {

  client.makeCall({
    to:'+16515556677', // Any number Twilio can call
    from: TWILIO_CALLER_ID,
    url: 'https://demo.twilio.com/welcome/voice' // A URL that produces an XML document (TwiML) which contains instructions for the call
  }, function(err, responseData) {

      //executed when the call has been initiated.
      console.log(responseData.from); // outputs "+14506667788"

      var resp = new client.TwimlResponse();

      resp.say('Welcome to Acme Customer Service!')
        .gather({
          action:'http://www.example.com/callFinished.php',
          finishOnKey:'*'
      }, function() {
          this.say('Press 1 for customer service')
              .say('Press 2 for British customer service', { language:'en-gb' });
      });
  });
};
user3775998
  • 1,393
  • 3
  • 13
  • 22

1 Answers1

3

Twilio developer evangelist here.

You're part way there with this, but you don't want to be creating a TwiML response in the callback to your call to client.makeCall. The responseData there is a representation of the call in Twilio's system.

What you need to do is provide a URL to the makeCall function that hosts some TwiML that connects the call to another phone number. Currently you have the demo URL in place, so you'll need to point that to a URL that you own.

There's a very good in depth tutorial on how to accomplish all of this on the Twilio site which you might find helps out. You can find the tutorial here, give it a go and let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88