Twilio Sample PHP & Instructions

Welcome back to Part 2 of the Revolution11 – Twilio/FileMaker integration where we have fun with Twilio, the service that allows you to make and receive phone calls and text messages using its web service APIs. In Part 1, we went over using a simple HTTPS request to send an SMS message, including a media file. In this post we will drill down into each individual piece that makes this integration possible and help you find the pieces to build it.

Previously we talked about:

  1. Integrating Twilio and FileMaker
  2. The PHP web service for retrieving texts from Twilio’s server

Here is a screenshot of the Twilio Demo File

FileMakerTwilio

As you can see from the screenshot, a few fields need to be populated:

  • account_id
  • token
  • from_phone_number
  • to_phone_number
  • Message

These fields are used to populate the variables used in the script to send the SMS message.

This is what the FileMaker script code looks like:

FMScript

The script checks that the required fields are not empty and that the phone numbers are formatted properly. The $post variable is set using the variables named earlier in the script, which sends a request to Twilio’s API. Twilio’s API takes the data that you are passing through this transaction, validates your Twilio account, and sends the message out.

Pretty fancy! but what happens when someone replies to that SMS? We can handle the reply easily with just a touch of PHP. In our example we are sending the replies to the SMS straight to an email address.

md2

This PHP file is kept on your FileMaker server, with the standard web configuration turned on. In the example, we have used “Your file path” so you can configure the PHP file for your server.

The header and echo tags are basically telling our application that this is the type of data that we are going to be receiving from Twilio’s server.

The next portion is variable creation and assignment. For example:

  • The $to variable – where we are sending the response message once it’s retrieved from Twilio’s server
  • The $subject variable – The subject of the message
  • The $message – The actual message and,
  • The $headers variable – the person the email was sent from

The final section is an HTTP request method that will send the reply email.

You obviously don’t want to have to muck with the PHP files on your server every time you want to change the reply action to the outgoing SMS message, so stay tuned for a future Revolution11 blog post where we show you a few ways to get these preferences out of your FileMaker solution.

Get a PDF of this post: Twilio Sample PHP

Twilio Sample PHP & Instructions

One thought on “Twilio Sample PHP & Instructions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.