Airtable Twilio

broken image


The first sms.received event on Twilio sets off the Airtable API that selects all rows in Airtable matching the number you requested and will return Airtable fields via Twilio's API that sends a message. The collaborative synergies between both Twilio & Airtable is exciting and can play a great role in empowering founders & helping their startups to optimise, finding product-market fit. In this webinar, you will join experts from Airtable and Twilio to learn how to build Airtable-based startup workflows backed by Twilio's communications platform.

  1. Air Table Twilio Reviews
  2. Air Table Twilio 2
  3. Air Table Twilio Review
  4. Air Table Twilio App
  • >
  • Integrate Airtable with Twilio SMS
Airtable Twilio

By Twilio

  • SMS
  • Twilio
  • Quick Deploy
  • Integrations

Use this app if you would like to understand how Airtable can serve as a way to store data sent to your Twilio phone number via SMS.

If you have an existing Airtable instance with a list of contacts, you can use Twilio SMS to add to that database and broadcast messages to your contacts.

Quick Deploy to Twilio BetaGet code Use Twilio CLI
Launch and test this app in a few minutes with Quick Deploy. No server needed. Quick Deploy will automatically configure and deploy this app using Twilio Functions. Learn more about Twilio Functions
A Twilio phone number will enable this app to send and receive messages or calls. Learn more
When you click 'Deploy my application', we will automatically use your custom details above to deploy your app to Twilio Functions. You can view the application in the browser and edit it to fit your needs using the Functions UI.
Deploying applicationThis might take up to a minute
Oops...something went wrong. Retry
Step 4:View and edit your application
Air
Once deployed, any changes to the fields above will not be applied to your app. To make changes, here are two options
Refresh the page, edit customizations and re-deploy the application
Edit your customizations directly in code
Easy to edit and iterate post launch
Scales automatically

There was an issue loading the page.

Air Table Twilio Reviews

Please try again in some time.

'Air Hockey' photo by LadyDucayne is licensed under CC BY 2.0.

Airtable is an awesome product. It's kind of like a cross between a spreadsheet and a database, but with a lot more flexibility for creating dynamic views of your data. In this post you'll learn to read Airtable data from a Twilio serverless application. The advantages of doing so are as follows:

  • Rapid prototyping. If you need to persistently store data, it's easier to create an Airtable base than to set up a proper database.
  • Maintenance flexibility. Folks who don't know how to code can easily maintain and extend the data.
  • Easy authentication. Sure, you could use Google Sheets as a lightweight database, but authenticating with Google Sheets API can be tricky.

Today we'll be building an app that returns facts about animals, but you can customize this code to fit your use case.

Prerequisites

Table
  • A Twilio account -- sign up for a free one here
  • A free Airtable account
  • A Twilio phone number with SMS capabilities

Airtable 101

In order to use Airtable, you need to be familiar with a few key concepts. If you're already an Airtable whiz, feel free to skip to the 'Reading From Airtable with a serverless function' section.

  • Bases. According to Airtable documentation, 'A base is a database that contains all of the information you need for a specific project, and is made up of one or more tables.'
  • Bases are made up of one or more tables, which are essentially like different sheets or tabs of a spreadsheet.
  • Records are units of data, analogous to a row on a spreadsheet.
  • Information in records is stored in fields, which are kind of like a column on a spreadsheet.
  • Workspaces are folders where you can organize your bases so that other folks can collaborate with you.

To create a new base you can:

  • Choose one of Airtable's many official templates
  • Choose a template created by the Airtable community
  • Start from scratch

I've created a small base called 'Cute Animals' that we'll be working with today. You can view it here and create your own copy with the 'Copy base' button on the right-hand side.

Air Table Twilio 2

This base contains a 'Cute Animals' table that has 3 fields:

Air table twilio app
  • Name, a single line text field
  • Genus, a link to another record (in the Genus table)
  • Fact, a long text field

It also contains a 'Genus' table that has 2 fields:

  • Name, a single line text field
  • Cute Animals, a link to another record (in the 'Cute Animals' table)

While you're in Airtable, let's get some credentials. Generate an Airtable API key and save it somewhere -- you'll need it in a minute.

Airtable

By Twilio

  • SMS
  • Twilio
  • Quick Deploy
  • Integrations

Use this app if you would like to understand how Airtable can serve as a way to store data sent to your Twilio phone number via SMS.

If you have an existing Airtable instance with a list of contacts, you can use Twilio SMS to add to that database and broadcast messages to your contacts.

Quick Deploy to Twilio BetaGet code Use Twilio CLI
Launch and test this app in a few minutes with Quick Deploy. No server needed. Quick Deploy will automatically configure and deploy this app using Twilio Functions. Learn more about Twilio Functions
A Twilio phone number will enable this app to send and receive messages or calls. Learn more
When you click 'Deploy my application', we will automatically use your custom details above to deploy your app to Twilio Functions. You can view the application in the browser and edit it to fit your needs using the Functions UI.
Deploying applicationThis might take up to a minute
Oops...something went wrong. Retry
Step 4:View and edit your application
Once deployed, any changes to the fields above will not be applied to your app. To make changes, here are two options
Refresh the page, edit customizations and re-deploy the application
Edit your customizations directly in code
Easy to edit and iterate post launch
Scales automatically

There was an issue loading the page.

Air Table Twilio Reviews

Please try again in some time.

'Air Hockey' photo by LadyDucayne is licensed under CC BY 2.0.

Airtable is an awesome product. It's kind of like a cross between a spreadsheet and a database, but with a lot more flexibility for creating dynamic views of your data. In this post you'll learn to read Airtable data from a Twilio serverless application. The advantages of doing so are as follows:

  • Rapid prototyping. If you need to persistently store data, it's easier to create an Airtable base than to set up a proper database.
  • Maintenance flexibility. Folks who don't know how to code can easily maintain and extend the data.
  • Easy authentication. Sure, you could use Google Sheets as a lightweight database, but authenticating with Google Sheets API can be tricky.

Today we'll be building an app that returns facts about animals, but you can customize this code to fit your use case.

Prerequisites

  • A Twilio account -- sign up for a free one here
  • A free Airtable account
  • A Twilio phone number with SMS capabilities

Airtable 101

In order to use Airtable, you need to be familiar with a few key concepts. If you're already an Airtable whiz, feel free to skip to the 'Reading From Airtable with a serverless function' section.

  • Bases. According to Airtable documentation, 'A base is a database that contains all of the information you need for a specific project, and is made up of one or more tables.'
  • Bases are made up of one or more tables, which are essentially like different sheets or tabs of a spreadsheet.
  • Records are units of data, analogous to a row on a spreadsheet.
  • Information in records is stored in fields, which are kind of like a column on a spreadsheet.
  • Workspaces are folders where you can organize your bases so that other folks can collaborate with you.

To create a new base you can:

  • Choose one of Airtable's many official templates
  • Choose a template created by the Airtable community
  • Start from scratch

I've created a small base called 'Cute Animals' that we'll be working with today. You can view it here and create your own copy with the 'Copy base' button on the right-hand side.

Air Table Twilio 2

This base contains a 'Cute Animals' table that has 3 fields:

  • Name, a single line text field
  • Genus, a link to another record (in the Genus table)
  • Fact, a long text field

It also contains a 'Genus' table that has 2 fields:

  • Name, a single line text field
  • Cute Animals, a link to another record (in the 'Cute Animals' table)

While you're in Airtable, let's get some credentials. Generate an Airtable API key and save it somewhere -- you'll need it in a minute.

Be careful not to commit your Airtable API key to any code that's going up on GitHub, or share it with anybody. If you do they can gain full access to your Airtable account.

Grab your Airtable base ID from the (nifty!) auto-generated API documentation. Save that too.

Reading Airtable data from a serverless function

We'll use a Twilio Function to receive an incoming SMS message and fetch data from our Airtable base. Open the Functions configuration dashboard. Add your Airtable API key and base IDs as environment variables, AIRTABLE_API_KEY. And AIRTABLE_BASE_ID respectively.

While you're at it, add the Airtable Node.js SDK to the Dependencies section of the Functions configuration dashboard. Here we're using version ^0.8.1 (that is, 0.8.1 or the latest minor patch.) Hit 'Save' to save all your configuration changes.

Let's write a Function that, given an animal name, returns the animal fact. This will show you how to filter airtable records by field for a simple text search. Using the blank template, create a new Function called getAnimalFact. Give it a path, /get-animal-fact. Copy the following code into it:

What is even happening here? Let's break it down.

  • First, we instantiate the airtable base.
  • The select method allows you to select your Airtable view, which returns the records in the order listed in that view. Called with no args, records are returned in random order.
  • The all method is asynchronous and returns every record in the view. Which is okay if you have a small number of records, but for larger bases you may want to paginate using the eachPage function. See the Airtable auto-generated API docs for an example.
  • Then we iterate through the records until we find a matching one, grab data from the field we want, and wrap it in some good old-fashioned TwiML so it can be returned as a message.
  • This code returns the Fact field of the first matching record.

After adding this code, save your Function and wait for it to deploy itself. On the phone numbers dashboard, configure your Twilio number to call this Function when a new message comes in.

Test it out by texting 'Cat' to your Twilio number. You should receive the following response:

Testing error paths is important too. If we try the same with zebra, we get the following output:

Fetching linked record data from Airtable

The real power of Airtable is that you can have many different field types, including:

  • URLs
  • Dates
  • Phone numbers
  • Email addresses
  • Links to other records

See a full list of Airtable field types at this link.

Links to other records are powerful, and give you lightweight relational database functionality. Let's add the Genus field, which is a link to another record, to our SMS response.

Fetching the linked data requires an additional API call. In the code below, we'll use the find method to fetch one record with a specific ID. Replace the code in your Function with the following:

Save your Function again.

Air Table Twilio Review

Text dog to the number and witness the following response:

Conclusion: backing your Twilio app with Airtable data

In this post, you've learned to:

Air Table Twilio App

  • Fetch plain text data and linked records using the Airtable Node.js SDK
  • Create a Twilio app backed backed by a serverless Function and an Airtable base

I've heard about so many awesome Airtable projects recently, such as this mutual aid tool to help community groups keep people fed during the covid crisis. If you're building something cool I'd love to hear from you. Hit me up on Twitter or send me an email: tthurium [at] twilio [dot] com.





broken image