Skip to content

Instantly share code, notes, and snippets.

@ChloeCodesThings
Created June 3, 2019 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChloeCodesThings/8137aa645fd1a5eebaf20e3ad7c69b62 to your computer and use it in GitHub Desktop.
Save ChloeCodesThings/8137aa645fd1a5eebaf20e3ad7c69b62 to your computer and use it in GitHub Desktop.
Reminder app sample code (phone call)
const accountSid = process.env.TWILIO_SID;
const authToken = process.env.TWILIO_TOKEN;
const client = require('twilio')(accountSid, authToken);
module.exports = async function (context, myTimer) {
var timeStamp = new Date().toISOString();
if (myTimer.IsPastDue)
{
context.log('JavaScript is running late!');
}
context.log('JavaScript timer trigger function ran!', timeStamp);
client.calls
.create({
url: process.env.TWIML_URL,
to: process.env.RECIPIENT_NUMBER,
from: process.env.SENDER_NUMBER,
})
.then(call => {
context.log("Call sent");
context.res = {
// status: 200, /* Defaults to 200 */
body: 'Call successfully sent'
};
context.done();
}).catch(err => {
context.log.error("Twilio Error: " + err.message + " -- " + err.code);
context.res = {
status: 500,
body: `Twilio Error Message: ${err.message}\nTwilio Error code: ${err.code}`
};
context.done();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment