Reputation: 741
is there a way to make calls/send messages using twilioAPI only with JavaScript ? The twilio documentation clearly explains how to make calls using Nodejs,Python, php,ruby ...but can it be done with JavaScript alone?
The below nodeJS code worked for me when i ran it on my PC.but how can i make it run in a website ?? I have done some research to find Heroku to host nodejs apps.if so,How to invoke this code hosted in heroku from my JavaScript?
var accountSid = 'AC5ef8732a3c49700934481addd5ce1659';
var authToken = "{{ auth_token }}";
var client = require('twilio')(accountSid, authToken);
client.calls.create({
url: "http://demo.twilio.com/docs/voice.xml",
to: "+14155551212",
sendDigits: "1234#",
from: "+18668675309",
method: "GET"
}, function(err, call) {
process.stdout.write(call.sid);
});
Upvotes: 2
Views: 460
Reputation: 10366
Twilio evangelist here.
Using the Twilio API from JavaScript is not recommended because it would require you to put your API credentials into the web page exposing them for all the world to see.
You can use some JavaScript in your webpage to make an async request to your node app on the server and have it interact with the API, or you can embed the aility to make a call directly from your web page using the Twilio Client JavaScript SDK.
Hope that helps.
Upvotes: 3