Using Twilio Autopilot to fetch Airtable records and display them to users

I’m working with Twilio Autopilot and need help with data retrieval. My bot first uses a Collect task to get a date input from users (like Feb 15, 2019). After getting this date, I want to query my Airtable base to find the matching record and then tell the user what’s happening on that date (something like “on Feb 15 the Downtown Cinema is showing this film, the Uptown Theater has…”).

I’ve got the Airtable lookup working, but I’m stuck on how to take the response data and turn it into variables I can use in my bot’s reply.

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

var Airtable = require('airtable');
var database = new Airtable({apiKey: 
'myapikey'}).base('mybasekey');

database('MovieSchedule').find('recXYZ123ABC456DEF', function(error, result) {
if (error) { console.error(error); return; }
console.log(result);
});
}

The response from Airtable looks like this:

{
    "id": "recXYZ123ABC456DEF",
    "fields": {
        "ShowDate": "2019-02-15",
        "Downtown Cinema": "Spider-Man",
        "Uptown Theater": "Batman"
    },
    "createdTime": "2019-02-15T18:30:22.000Z"
}

you’re missing the callback to send data back to autopilot. try adding callback(null, {say: 'On ' + result.fields.ShowDate + ' downtown cinema shows ' + result.fields['Downtown Cinema']}); after you get the airtable response. that’s how i got mine working.

I encountered a similar issue while integrating with Twilio Autopilot. You successfully retrieve the Airtable record, but the data needs to be packaged correctly for your bot’s response. Modify your handler to use the callback function to send the data back after fetching. You can extract necessary fields like result.fields[‘Downtown Cinema’] and result.fields[‘Uptown Theater’], then construct your response message using these values. Remember to adhere to Twilio’s callback format: callback(null, responseObject). Testing the Airtable query independently beforehand can also help ensure you’re working with the correct data structure before linking it to Autopilot.