Last active
June 13, 2020 20:42
-
-
Save dmurawsky/6b5ede97d96eae2ebf9dc943e5531068 to your computer and use it in GitHub Desktop.
Helper functions for Firebase and Twilio on Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const client = require("twilio")(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN); | |
const getDateObj = () => { | |
const date = new Date(); | |
const hour = date.getHours(); | |
const d = date.getDate(); | |
const m = date.getMonth() + 1; | |
const y = date.getFullYear(); | |
return { hour, date: `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}` }; | |
}; | |
const firebasePut = (path, obj) => axios | |
.put(`https://project-id.firebaseio.com/${path}.json`, obj); | |
const firebaseGet = (path, obj) => axios | |
.get(`https://project-id.firebaseio.com/${path}.json`); | |
const sendTwilioMessage = (body, from, to) => | |
client.messages.create({ body, from, to }); | |
const getTwilioParam = (body, param) => body.split(`&${param}=`)[1].split("&")[0]; | |
module.exports = { | |
getDateObj, | |
firebasePut, | |
sendTwilioMessage, | |
getTwilioParam, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment