Help

Twilio call log auto write new logs

579 0
cancel
Showing results for 
Search instead for 
Did you mean: 
AppleMac_89
4 - Data Explorer
4 - Data Explorer

I'm trying to create a script automation that will write update call log data from a phone number pool to airtable. 

Here is my code so far. The problem that I'm having is that the script within the automation section doesn't support my envo. 

const Twilio = envo('twilio');
const Airtable = envo('airtable');

const accountSid = 'TWILIO_ACCOUNT_SID';
const authToken = 'TWILIO_AUTH_TOKEN';
const twilioClient = Twilio(accountSid, authToken);

const apiKey = 'AIRTABLE_API_KEY';
const baseId = 'AIRTABLE_BASE_ID';
const tableName = 'AIRTABLE_TABLE_NAME';
const airtableBase = new Airtable({ apiKey }).base(baseId);

const phoneNumbers = [FriendlyNameExample'];

phoneNumbers.forEach((phoneNumber) => {
twilioClient.calls.list({ from: phoneNumber }, (err, calls) => {
if (err) {
console.error(`Error retrieving call logs for ${phoneNumber}:`, err);
} else {
console.log(`Retrieved ${calls.length} call logs for ${phoneNumber}`);
calls.forEach((call) => {
airtableBase(tableName).create({
'Phone Number': phoneNumber,
'Duration': call.duration,
'Direction': call.direction,
'Status': call.status,
'Start Time': call.startTime.toISOString(),
'End Time': call.endTime.toISOString()
}, (err, record) => {
if (err) {
console.error(err);
} else {
console.log(`Created record ${record.getId()} in Airtable`);
}
});
});
}
});
});

0 Replies 0