Skip to content

Instantly share code, notes, and snippets.

@dmurawsky
Last active June 13, 2020 20:42
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 dmurawsky/6b5ede97d96eae2ebf9dc943e5531068 to your computer and use it in GitHub Desktop.
Save dmurawsky/6b5ede97d96eae2ebf9dc943e5531068 to your computer and use it in GitHub Desktop.
Helper functions for Firebase and Twilio on Lambda
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