This Number Rocks, Rocking Out with Elixir Lang

Henri Morlaye is a developer in Leon, France. He works for a small company there that builds tools for professionals to facilitate innovative instructive and training environments at their companies.

Until recently, Henri and his team relied on a landline as the main phone system for their company. While searching for a way to modernize, they decided to build a solution themselves with Twilio that would allow for both more flexibility and control.

The team took the simple concept of a Twimlet but decided to give it their own flair. Using Elixir with the Twilio REST API, they were quickly up and calling!

They built the CRUD app with the Phoenix Framework and deployed on Heroku. A Postgresql database table keeps track of the Twilio numbers and phone numbers they point to, stored as embedded structs using an array of maps and Elixir’s Ecto embedded schema.

All Twilio calls are routed to two functions which determine what to do if there is an incoming SMS or a call.  The function for SMS sends an email and the function for a call will try in turn each “real” phone number associated with the “virtual” Twilio number.

A call comes in:

The try_real_number private function looks for the called number in the database, tries to dial a “real” number – Henri’s phone for example – and sets an HTTP callback to Twilio keeping track of the current trial index. If no one answers, or a call comes in outside of open hours, a TwiML <Record> instruction is sent back to Twilio.

The callback action URL provided in the <Dial> instruction uses destructuring to run different routines according to the type of action:

  • Voicemail recording notifications are forwarded to the other user by email.
  • Completed calls are finished.
  • Unanswered call attempts trigger a new call to try_real_number with the next “real” number in the list.

The answer function just wraps an XML snippet in a Twilio response:

Without a helper library for Elixir, Henri said he relied heavily on the logging system in the Console. “It was really a piece of cake!”

This Number Rocks

Henri created the solution with their own use in mind. “It did not require a lot of work. It was perfect,” he said. But after sharing it with friends in the local startup community, people loved it and wanted to start using it too. “Having a Twilio number could bring a lot of benefits to them as it does for us.” They set up thisnumber.rocks to make it so others, even without technical knowledge, could also have a fancy call forwarding system.

 

 

Whether you’re inspired to start building your own solution from scratch or following the tutorial to get started on thisnumber.rocks is more your style, we’re always happy to hear what you’re up to.

Feel free to drop a line to: