twilio node voice outgoing quickstart fails silently - twilio

I know this is a complete n00b question but I'm stumped.
I've created an account and cut/pasted the node quickstart code into a make_call.js file. I've put in my account info and the correct from (my twilio number) and to (my home) phone numbers.
when I run via 'node make_call.js' there is a slight pause and then a shell prompt, no output, no phone call.
if I modify the account fields so they are wrong, either one, I get the same results so it seems like this code is not communicating with the twilio servers at all?
any pointers on how to figure out what's going on?
here's my code, literally copied/pasted from the example with 4 fields changed.
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const authToken = '0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const Twilio = require('twilio');
const client = new Twilio(accountSid, authToken);
client.api.calls
.create({
url: 'http://demo.twilio.com/docs/voice.xml',
to: '+1212xxxxxxx',
from: '+1929xxxxxxx',
})
.then((call) => console.log(call.sid));

Looks like the quick start guide and the REST API docs for node are different. What happens if you try the code for an outbound call from the REST docs?
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'accountSid';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);
client.calls.create({
url: 'http://demo.twilio.com/docs/voice.xml',
to: '+14155551212',
from: '+15017250604',
})
.then((call) => process.stdout.write(call.sid));

I have no idea why this code wasn't working and silently failing yesterday but I just ran the (unchanged) code again today and it worked (and output the sid at the end.)

The problem with the example make_call.js is that it does not catch any errors. Here is a slightly modified version with error catching that greatly helps debugging.
const accountSid = 'Your account sid';
const authToken = 'Your auth token';
const Twilio = require('twilio');
const client = require('twilio')(accountSid, authToken);
client.api.calls
.create({
url: 'http://demo.twilio.com/docs/voice.xml',
to: 'your mobile',
from: 'your twilio number',
}, function(err, call){
if(err) {
console.log(err);
} else {
console.log(call.sid);
}
})

Related

cant play audio url with twilio play

i try to do a simple call phone from twilio that play a massage and hang up,
but no matter what url i put, when the call made i get a voice massage about function error
here is my code:
let twilio = require('twilio');
var accountSid =; // Your Account SID from www.twilio.com/console
var authToken = ; // Your Auth Token from www.twilio.com/console
var client = new twilio(accountSid, authToken);
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();
response.play({
loop : 1,
},"https://scribie.com/records/7941e240b8884865872ac859e389927b78757fae_orig.mp3?fn=test2.mp3&to=FHtRpSzUlmmaVRWjl7n23mC3Ezm5nYwK");
console.log(response.toString());
client.calls
.create({
twiml: response.toString(),
to: '',
from: ''
}).then(call => console.log(call.sid)).catch(e=>console.log(e));
Twilio developer evangelist here.
I can get your code to work when I replace the Scribie URL with "http://demo.twilio.com/docs/classic.mp3". When I try to open up the Scribie URL you have, it takes me to this webpage one has to log-in to view. Instead of that, I'd try uploading the file to Twilio Assets or a different hosting service.

Twilio Verify called from Twilio Functions returns resource not found

I am making a simple to the verify api from a Twilio Function triggered in a studio flow.
The error I am recieving is "verifications resource not found".
I assumed it was an authentication issue, but I have the correct SIDS and have checked that a number of times.
Not sure what I am missing.
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
const functions = Runtime.getFunctions();
const formatPhone = require(functions['formatters/formatPhone'].path);
exports.handler = function (context, event, callback) {
const verifyPhone = formatPhone.toSearch(event.verifyPhone);
const verifyType = event.verifyType;
client.verify
.services('<Verify SID>')
.verifications.create({ to: '+1' + verifyPhone, channel: verifyType })
.then((verification) => {
console.log(verification.sid);
callback(null, 'done');
})
.catch((err) => callback(err, null));
};
I can run this code from my machine and hit it from studio using NGROK and an http widget instead of a function.
SAME CODE.
I feel that it may be the work of Legacy Systems!
So as strange as it sounds it ended up being a library versioning issue.
npm i 'twilio'
and then pushed again to the server
twilio serverless:deploy --override-existing-project
I also realize that I didn't list the error originally. I have edited it to make more sense as to the problem I was having.

What to Set in StatusCallback on an outbound call if the application running locally

I have created my application with NODE.JS . I am running my application locally . I want to Monitor outbound call events.
As I am running my application locally , what I have to Set in StatusCallback on an outbound call.
I am using this code snippet.
const accountSid = 'your_accountSid';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);
client.calls
.create({
method: 'GET',
statusCallback: '',
statusCallbackMethod: 'POST',
url: 'http://demo.twilio.com/docs/voice.xml',
to: '+14155551212',
from: '+18668675310'
})
.then(call => console.log(call.sid));
Twilio developer evangelist here.
We recommending using a tunnelling program to give your local development server a public URL. My favourite is ngrok, check out this post on how to use ngrok and if you use VS Code, I also wrote a plugin to make it easy to use ngrok in VS Code.

Twilio function giving invalid content-type error

I'm trying to make an outgoing call to an automated phone system, but I'm running into a content-type error. I don't understand what a content-type error is, so if someone could help me understand that would be great. Here's the code I have right now.
exports.handler = function(context, event, callback) {
const accountSid = 'AC5ca0acd115283b6d7ed38279';
const authToken = 'not my real auth token';
const client = require('twilio')(accountSid, authToken);
client.calls
.create({
to: '+14805402416',
from: '+18448345500',
record: 'True',
transcribe: 'True',
sendDigits: 'wwww1wwww123#wwww1', // w's are .5 second delays to navigate pauses in the automated system
// '1' - English, '123#' - PIN #, '1' - Confirm PIN
});
callback(null, client);
};
You are missing either url or twiml in your construct.
https://www.twilio.com/docs/voice/api/call-resource
url
The absolute URL that returns the TwiML instructions for the call. We will call this URL using the method when the call connects. For more information, see the Url Parameter section in Making Calls.
TwiML instructions for the call Twilio will use without fetching Twiml
from url parameter. If both twiml and url are provided then twiml
parameter will be ignored.

Twilio Client Sending custom call parameters from nodejs server to ios client

we're using a nodejs on the serverside, and then ios sdk (Version 3 w/support for custom parameters)
we need a way to be able to send custom parameters from our nodejs server into the client. In PHP i was able to figure it out by just sending it with the dial verb by doing
$dial->parameter(['name'=>'param','value'=>'value']);
but for nodejs i am not able to find a solution that fits with:
call = await client.api.calls.create({
url: url,
to: 'client:' + defaultIdentity,
from: callerId,
});
Twilio developer evangelist here.
You can absolutely generate TwiML with the Twilio Node.js library. To generate a <Dial> you need code like:
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();
const dial = response.dial({
callerId: '+15551112222'
});
dial.number('+15558675310');
console.log(response.toString());
Let me know if that helps at all.
Okay so, apparantly its the same way you would do it in php, except a bit different
function incoming() {
const voiceResponse = new VoiceResponse();
const dial = voiceResponse.dial({action:'http://21402340.ngrok.io/endCall'});
let client = dial.client({
statusCallback: 'completed',
statusCallback: 'http://21402340.ngrok.io/endCall',
statusCallbackMethod: 'POST'
},'alice');
client.parameter({name:'subscriber_name',value:'Richard abear'});
return voiceResponse.toString();
}
here is a sample function that sends a custom parameter subscriber_name to the client's customCallParameters

Resources