Skip to content

Instantly share code, notes, and snippets.

@asaf400
Created March 29, 2021 01:39
Show Gist options
  • Save asaf400/50a04322e10d878b2d959e9bd813bd78 to your computer and use it in GitHub Desktop.
Save asaf400/50a04322e10d878b2d959e9bd813bd78 to your computer and use it in GitHub Desktop.
const { VoipList } = require('twilio/lib/rest/api/v2010/account/availablePhoneNumber/voip');
var express = require('express');
require('dotenv').config()
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const twilio_callback_url = process.env.TWILIO_CALLBACK_URL;
const twilio_from = process.env.TWILIO_FROM
const twilio_to = process.env.TWILIO_TO
const twilio = require('twilio')
const twilio_client = twilio(accountSid, authToken);
async function voice_call() {
ret = await twilio_client.calls
.create({
url: twilio_callback_url,
to: twilio_to,
from: twilio_from
})
console.log(ret.sid)
// .then(call => console.log(call.sid));
}
var app = express();
app.use(express.urlencoded());
app.listen(8081)
// Create a route to respond to a call
app.post('/respondToVoiceCall', function(req, res) {
//Validate that this request really came from Twilio...
if (twilio.validateExpressRequest(req, authToken)) {
const twiml = new twilio.twiml.VoiceResponse();
twiml.say('Hello World');
twiml.play('http://demo.twilio.com/docs/classic.mp3');
twiml.hangup();
res.type('text/xml');
res.send(twiml.toString());
}
else {
res.send('you are not twilio. Buzz off.');
}
});
(async () => {
await voice_call()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment