0

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:

  1. (Error: 11200) HTTP retrieval failure There was a failure attempting to retrieve the contents of this URL.

error

Postman Test Results:

  1. Response time is less than 1000ms | AssertionError: expected 2315 to be below 1000

error

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);
   });
};

Studio flow

philnash
  • 70,667
  • 10
  • 60
  • 88

1 Answers1

0

Twilio developer evangelist here.

I think, from your question, that you are creating the Studio Flow Execution by making the API request directly to the Flow. However the Function that you included is intended to make that request after collecting the data from Airtable.

The Studio Flow is not supposed to call that function, the function creates an execution with this code:

     client.studio.v1.flows('Vaccine-Reminder').executions.create(
       {
         to: '+91xxxxxxxxxx',
         from: '+12xxxxxxxxxx',
         parameters: JSON.stringify(params_list)
       }
     )

The Postman test results are misleading. The fact that the API didn't respond in under 1000ms means it could maybe be faster, but the 201 response shows that it was successful at least.

Instead of using Postman to create the Studio execution, try using it to call your Twilio Function instead and let me know if that helps.

Studio Flow

philnash
  • 70,667
  • 10
  • 60
  • 88
  • 1.The second test-results of Postman throws an AssertionError as the time it is expecting is < 1000ms but it is = 2315ms, which means the response is slower instead if the test results aren't misleading. – Tisha Singh Aug 24 '21 at 07:10
  • 2. Also tried calling the Twilio Function directly instead of calling the REST API in order to execute the Studio Flow, but that too didn't help in my case. – Tisha Singh Aug 24 '21 at 07:15
  • Are things still not working for you? I notice in one of your screenshots that you are showing outbound messages that failed to send. Do you have the [correct geographic permissions for sending SMS](https://support.twilio.com/hc/en-us/articles/223181108-How-International-SMS-Permissions-work)? – philnash Aug 24 '21 at 07:24
  • Nope, it isn't. The geographic permissions for SMS are alright as it's working fine for the rest of my projects, but not this one. – Tisha Singh Aug 24 '21 at 11:09
  • For those failed outbound messages, if you hover over the `i` next to failed, or click into the message, is there further information about why the message failed? – philnash Aug 25 '21 at 03:23
  • The information of failure is : _(Error: 12300)_ Invalid Content-Type Twilio is unable to process the Content-Type of the provided URL. Please see Twilio's documentation on accepted content types for more information on valid Content-Types. – Tisha Singh Aug 25 '21 at 06:10
  • I'm sorry, I don't understand where this application is failing at the moment. Can you explain what you do and what stage this error happens, please? – philnash Aug 25 '21 at 06:18
  • In the list of accepted content types for media, there exists Text/CSV, since I am using Airtable under the scope of this project my content-type is supposed to be CSV, is it? – Tisha Singh Aug 25 '21 at 06:20
  • That seems unlikely. It would be better for me to know what part of your flow is causing the error. What is calling the Function from your question? – philnash Aug 25 '21 at 06:23
  • There is this widget in my studio flow, send and wait for reply, which is supposed to fetch details of the Patient from the Airtable base. – Tisha Singh Aug 26 '21 at 08:13
  • The Send and Wait for Reply widget doesn't fetch data though, it just sends messages and waits for a response. So what is calling the function? – philnash Aug 26 '21 at 08:15
  • There is this widget in my studio flow, send and wait for reply, which is supposed to fetch details of the Patient from the Airtable base. Message body contains, {{flow.data.patient_name}} has an appointment on {{flow.data.appointment_date}} at {{flow.data.appointment_time}}. As it is reflected in the screenshot, of the error, above, that the function is unable to fetch it from the database, i.e., Airtable . This seems to occur because of Invalid Content-Type, as per the documentation https://www.twilio.com/docs/sms/accepted-mime-types, one of the accepted types for text-SMS is text/csv. – Tisha Singh Aug 26 '21 at 08:20
  • For the function, I have this Run Function widget, before Send and wait for reply and after the Trigger (REST API) which is calling the required function. – Tisha Singh Aug 26 '21 at 08:24
  • I just observed that the content-type in my case is application/json , is it not an accepted under MIME types for sms? – Tisha Singh Aug 26 '21 at 08:34
  • Can you edit your question and post a screenshot of your Studio flow? – philnash Aug 26 '21 at 08:38
  • Extreme Thanks for the Response Philnash, let me do it. – Tisha Singh Aug 26 '21 at 08:52
  • From what I can see in the error message screenshot, you are not getting the information out of airtable correctly. The message body is " has an appointment on at." and that should be filled in with details. Have you set up the data in the airtable correctly? – philnash Aug 27 '21 at 00:53
  • What I believe is that , the data in the Airtable is added correctly and the message body in the widget is also correct, i.e., {{flow.data.patient_name}} has an appointment on {{flow.data.appointment_date}} at {{flow.data.appointment_time}}. using right syntax of Liquid template language. – Tisha Singh Aug 27 '21 at 20:22
  • Yes, but you can also see that the failed message does not have that data in the body. So something is wrong there. You are going to need to debug the function to see whether you are correctly returning that data. – philnash Aug 29 '21 at 23:18