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.
Related
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.
My company uses Twilio Flex as our phone system and I was recently tasked with setting up a feature that will let us edit a TwiML voice message that plays before our normal voice message. This TwiML message will be changed through a Twilio bot that I've published in our Microsoft Teams.
The reason for this is so that our support desk can add a short message in the lines of "We're currently experiencing issues with X" before our normal "Welcome to [Company] support" message.
If TwiML's can be edited using HTTP POST/PUT or Twilio's API this should be a trivial matter, but so far I've not been able to figure out how.
I couldn't find any reference to this in the API doc, so I decided that HTTP POST would be the way to go. Using this as a start off point, I'm able to retrieve my TwiML using HTTP GET:
https://support.twilio.com/hc/en-us/articles/223132187--Not-Authorized-error-when-trying-to-view-TwiML-Bin-URL
const axios = require('axios');
const crypto = require('crypto');
const accountSidFlex = process.env.accountSidFlex;
const authTokenFlex = process.env.authTokenFlex;
var URL = 'https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + '?AccountSid=' + accountSidFlex
var twilioSig = crypto.createHmac('sha1', authTokenFlex).update(new Buffer(URL, 'utf-8')).digest('Base64')
var config = {
headers:{
'X-TWILIO-SIGNATURE': twilioSig
}
}
axios.get(
URL,config
).catch(error => console.log(error))
.then(response => {
console.log(response.data)
})
response.data shows the TwiML's current XML content.
My attempts at a POST only gives the same output as the GET, while PUT gives 405 Method Not Allowed.
var URL = 'https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + '?AccountSid=' + accountSidFlex
var twilioSig = crypto.createHmac('sha1', authTokenFlex).update(new Buffer(URL, 'utf-8')).digest('Base64')
var config = {
headers:{
'X-TWILIO-SIGNATURE': twilioSig,
'Content-Type': 'text/xml'
}
}
var xml =
'<?xml version="1.0" encoding="UTF-8"?>\
<Response><Play digits="www"/>\
<Say voice="alice">"We are currently experiencing X related issues". </Say>\
</Response>';
axios.post(
URL,xml,config
)
.catch(error => console.log(error))
.then(response => {
console.log(response.data)
})
Ideally I'd like to be able to change a specific TwiML using either HTTP methods or the Twilio-API, so that we can use it in out Studio Flow. We'd just keep it silent until we need to add something to it and revert back to silent once the issues have passed.
Any help would be appreciated!
You cannot currently change the contents of TwiML Bins, Studio Flows, or Twilio Functions programatically. I believe the key functionality you are looking for is a way to dynamically update the messaging (Say/Play Widget) in a Studio flow based on some condition.
One way is to use a Function Widget to retrieve a Twilio Sync document for the message, returning the message as JSON and have the Say/Play widget play that message. You can find the Twilio Sync REST API examples for Add, Modify, and Retrieve in the associated document.
You can retrieve the parsed response using variable syntax detailed here, https://www.twilio.com/docs/studio/widget-library#run-function.
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
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);
}
})
I am following the tutorial on https://www.twilio.com/docs/api/rest/change-call-state#post I am coding in php the portion that allows you to forward a current inbound call to a new Twiml URL. How do I get the inbound call Sid? Currently, the call Sid that I am retrieving forwards my browser to the new Twiml URL and hangs up the inbound caller. I think that I may have the wrong call Sid since I want to forward the current inbound caller to the new Twiml URL. Not The Browser. Can someone please give me some advice on retrieving the inbound call Sid to use in this php script? Thanks
Twilio.Device.incoming(function (conn) {
callSid = conn.parameters.CallSid;
$("#log").text("Incoming connection from " + conn.parameters.From);
// accept the incoming connection and start two-way audio
conn.accept();
});
This is how I am getting the Call Sid. If I input this Call Sid into
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('TwilioAPI/twilio-php-master/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = '';
$token = '';
$client = new Services_Twilio($sid, $token);
// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$call = $client->account->calls->get("THE CALL SID I GOT FROM THE JS GOES HERE");
$call->update(array(
"Url" => "http://twimlets.com/message?Message%5B0%5D=I%20finally%20did%20it&",
"Method" => "POST"
));
echo $call->to;
?>
This code forwards the browser which receives the call to the new Twiml URL. Not the inbound caller.