3
votes

my use-case is to : automate a voice call to a mobile/landline number and play an mp3 file when someone pickup the call. Basically a phone-number verification service. How can I do this in Twilio

1
Please show some effortsAnkur Aggarwal
Can you tell us more about your language preferences so we can give you a better answer?phalt

1 Answers

4
votes

Ricky from Twilio here.

Since you didn't share any language preferences I'll show an example using one of my favorite languages, JavaScript. If you want to dive a bit deeper I'd recommend my buddy Sam's great post on making and receiving phone calls that play an mp3 with Node.JS.

Now onto some code. First, you'll want to generate a TwiML file that lives on a publicly accessible server that tells Twilio to play an MP3. Here's an example file:

<Response>
  <Play>http://demo.rickyrobinett.com/jiggy.mp3</Play>
</Response>

You could save this as voice.xml. Then you need to write the JavaScript (or language of your choice):

var accountSid = '{{ account_sid }}';
var authToken = "{{ auth_token }}";
var client = require('twilio')(accountSid, authToken);

client.calls.create({
    url: "http://example.com/voice.xml",
    to: "+14155551212", // the number you want to call
    from: "+14158675309" // your Twilio number
}, function(err, call) {
    process.stdout.write(call.sid);
});

Hope that helps!