Skip to content

Instantly share code, notes, and snippets.

@Eclairemoy
Created February 11, 2021 20:35
Show Gist options
  • Save Eclairemoy/fe677e0c03a5a14ed3940844731d8306 to your computer and use it in GitHub Desktop.
Save Eclairemoy/fe677e0c03a5a14ed3940844731d8306 to your computer and use it in GitHub Desktop.
sendSmsReminder.js
const airtable = require("airtable");
exports.handler = function (context, event, callback) {
const base = new airtable({apiKey: context.AIRTABLE_API_KEY}).base(context.AIRTABLE_BASE_ID);
const client = context.getTwilioClient()
let paramsMap = new Map();
base("appointments")
.select()
.all()
.then((records) => {
const sendingMessages = records.map((record) => {
if (record.get('Appointment_Status') === "pending"){
paramsMap['name'] = record.get('Name');
paramsMap['appointment_date'] = record.get('Appointment_Date');
paramsMap['appointment_time'] = record.get('Appointment_Time');
paramsMap['airtable_record_id'] = record.getId();
paramsMap['appt_id'] = record.get('ID');
}
});
return Promise.all(sendingMessages);
})
.then(() => {
if (paramsMap['name'] === undefined) //No appointments in system
{
console.log("No appointments in system");
callback(null, "from studio function");
}
params_list = {
"appointment_date": paramsMap['appointment_date'],
"appointment_time": paramsMap['appointment_time'],
"provider_name":"Owl Health",
"patient_name": paramsMap['name'],
"airtable_record_id": paramsMap['airtable_record_id'],
"appt_id": paramsMap['appt_id']
};
client.studio.v1.flows('FW718bd79cdb89a7195e382ac5dce838a8').executions.create(
{
to: '+16145077579',
from: '+17403278492',
parameters: JSON.stringify(params_list)
}
)
.then(function(execution) {
console.log("Execution Id:" + execution.sid);
callback(null, "sent from studio function");
})
.catch(err => callback(err));
})
.catch((err) => {
console.log("airtable error");
callback(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment