Skip to content

Instantly share code, notes, and snippets.

@ChloeCodesThings

ChloeCodesThings/index.js

Last active Jun 4, 2019
Embed
What would you like to do?
Reminder app sample code
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!');
}
client.messages
.create({ from: process.env.SENDER_NUMBER,
body: "Guess what time it is? TIME TO TAKE YOUR PILLS!! YAY!",
to: process.env.RECIPIENT_NUMBER
})
.then(message => {
context.log("Message sent");
context.res = {
// status: 200, /* Defaults to 200 */
body: 'Text successfully sent'
};
context.log('JavaScript timer trigger function ran!', timeStamp);
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