Integrating WhatsApp Bot with Database Storage - Data Collection Issues

I’m building a conversational bot using Twilio Studio and need help storing user responses in an Airtable database.

I found a tutorial online but the serverless function code doesn’t seem to work properly. Here’s what I’m trying to accomplish:

  1. Capture user input from bot conversations
  2. Store this data automatically in my Airtable workspace
  3. Make it work within Twilio Studio flows

Current function code:

exports.handler = function(context, event, callback) {

    let userInfo = {
        fullName : event.fullName,
        emailAddress : event.emailAddress,
        timestamp : Date.now()
    };

    var AirtableAPI = require('airtable');
    var database = new AirtableAPI({apiKey: context.AIRTABLE_KEY}).base('appXYZ123ABC456');

    database('Contacts').create(userInfo, function(error, newRecord) {
        if (error) { 
            console.error(error); 
            return; 
        }
        console.log(newRecord.getId());
        callback(null, userInfo);
    });
};

The problem: When I test this with Postman, I get errors in the Twilio console and the data isn’t being saved to my Airtable base.

My Airtable has these fields: Id, fullName, emailAddress, timestamp

I’m also wondering if I should use the HTTP Request widget in Studio Flow instead. How would I configure that properly?

Any suggestions on what might be going wrong here? I’m not very experienced with coding so simple explanations would be really helpful.

Been there with Twilio Functions + Airtable. Your code looks mostly right, but I bet it’s a data passing issue from Studio to the function.

In Studio, make sure your parameters match exactly - fullName and emailAddress. Studio sometimes sends different key names depending on how you collect the data.

Add this at the start of your function:

console.log('Received event data:', event);

This shows you exactly what Studio’s sending. I’ve seen bots collect “name” but functions expect “fullName”.

Your timestamp might be the problem too. Airtable gets weird with raw timestamps. Try new Date().toISOString() instead of Date.now().

I always use Functions over HTTP widgets for database stuff. Better error messages and you can handle retries when Airtable acts up.

Had the same headache with my WhatsApp bot last year. Your error handling’s broken - you’re logging the error but not calling the callback, so Twilio just sits there waiting. Add callback(error) in your error block instead of just returning. Also double-check your Airtable field names match exactly. Airtable’s super picky about case and spaces. I’d test the Airtable connection with a basic script first before throwing it into Studio. For the HTTP Request widget - honestly, I just use Functions instead. Better error handling and you can add validation. The HTTP widget works but you can’t control the response format as well.

your Airtable base ID looks wrong - appXYZ123ABC456 is def a placeholder. double-check that and make sure AIRTABLE_KEY is set in your env variables. i had the same issue and it turned out to be bad creds. add some console.log to see what data you are sending before hitting the db.