Hi community.
I’m very new to JS so apologies if this seems basic :pray: .
I’m using Twilio Functions (node.js) to load to AirTable all incoming texts. I’m utilizing 2 tables -
- “Receive Text” with columns Text date, Text Body and UID.
- “Users” with columns UID and Phone Number (and a bunch of others).
When a text comes in, I’m trying to use FilterByFormula with the phone number to retrieve the user’s UID from the “Users” table.
Here’s the code I’m running -
var filter = "({Phone Number} = '" + event.From + "')";
base('Users').select({
filterByFormula: filter
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
console.log('Retrieved ', record.get('UID'));
alert('Retrieved ', record.get('UID'));
});
fetchNextPage();
}, function done(error) {
console.log(error);
});
let message = {
"UID" : record.get('UID'),
"Phone Number" : format_phone,
"Inbound Text Date" : Date.now(),
"Inbound Text Content" : event.Body
};
base('Receive Text').create(message, function(err, record) {
if (err) { console.error(err); return; }
console.log(record.getId());
callback(null, message);
});
};
Last note - Without the “UID” in the message, the message uploads just fine.
My questions are -
- Both the UID and Phone Number are unique values in “Users”, so I’m not sure if I even need the whole piece on handling multiple records. Is there maybe a simpler way of doing it?
- I’m not sure I understand how exactly I retrieve the UID once I run the select function. Where exactly is the response stored?
Thanks in advance!