Building More Powerful Voice Applications With Enhanced TwiML Bins Templates
Time to read: 2 minutes
Today I’m excited to announce that TwiML Bins now supports Mustache templates and a new built-in function that make it even easier to build Twilio applications.
Last October we added the ability for Twilio customers to use a simple templating syntax in their TwiML Bins to build more kinds of Voice and SMS experiences without the need to operate a web server. Customers used templates in ways that we expected:
- Call forwarding
- SMS forwarding
And in ways that we did not, such as customized voicemail experiences.
However, there were still some use cases that seemed simple on the surface, but weren’t possible with TwiML Bins, such as forwarding incoming SIP phone calls to PSTN destinations.
How to Build a Simulring Outbound Dialer using TwiML Bins
Let’s modify the outbound dial example from our previous blog post, but this time let’s pass an array of phone numbers that we’d like to dial. This is called a Simulring and the idea is to call several phone numbers with the first person to answer being connected. Here is a snippet of Python code that implements this outbound dial:
Now, once Twilio dials +14155551212 and they answer the phone, Twilio will then make an HTTP request to the TwiML Bin URL that we specified in our REST API call. We can then take advantage of the new TwiML Bin templates feature to convert the array of HTTP parameters into a list of <Number> nouns:
This will end up being rendered at runtime as:
Bridging SIP Endpoints with PSTN
Another use case that has come up often has been bridging SIP endpoints, such as a Polycom phone, with the PSTN world. For instance, let’s say a Voice call comes in to a SIP Interface with a To value of sip:+15125551212@mydomain.sip.us1.twilio.com. Since the e.164 phone number is embedded in the SIP URI’s address, it would be great if Twilio allowed customers to pull this value out and use it in a <Dial>. With the new built-in e164 function, you can do that:
We know that standing up and operating web infrastructure can get in the way of what you really care about, which is building useful and reliable communications experiences. We think that Mustache templates combined with a limited set of built-in functions that unlock well-defined Voice and SMS use cases will provide developers and non-developers alike with a powerful set of tools to build useful communications experiences with Twilio.
If you have any any questions about TwiML Bins Templates don’t hesitate to reach out to me at @crtr0 on Twitter or carter@twilio.com.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.