I am attempting to build this Appointment Management System for scheduling vaccination appointments using Twilio+ Airtable + Postman. ( [Link to the blog following])2
In order to trigger the Twilio studio flow via Rest API and to get the Programmable message on my personal number from my Twilio number, I made this POST request by providing the URL of the flow which contains the authentic flow_sid and other details, but every time the post request is made the following errors are encountered :
Twilio Error logs:
- (Error: 11200) HTTP retrieval failure There was a failure attempting to retrieve the contents of this URL.
Postman Test Results:
- Response time is less than 1000ms | AssertionError: expected 2315 to be below 1000
The function being called by the studio flow at the very first instance is:
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('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('Vaccine-Reminder').executions.create(
{
to: '+91xxxxxxxxxx',
from: '+12xxxxxxxxxx',
parameters: JSON.stringify(params_list)
}
)
.then(function(execution) {
console.log("Execution Id:" + execution.sid);
callback(null, "Message sent via studio function");
})
.catch(err => callback(err));
})
.catch((err) => {
console.log("Airtable error");
callback(err);
});
};