Skip to main content

Mustache Template Parameters in XML Bins

Certain incoming message information can be extracted and added to an XML Bin response by using parameters. Mustache templates are parameters in curly braces, like {{Name}}, which output the given value of a parameter.

Mustache template variables are used to make your XML Bin dynamic. Variables can be parameters of the HTTP payload for the request, or a query string variable you set in your webhook ( Either method of Mustache variable declaration will work well in translating values into your XML bin.

Which parameters work as mustache templates in an XML bin or webhook?

Type of ParameterDefault Parameter Names
General Parameters{{From}}, {{To}}, {{AccountSid}} (Equivalent to Project ID), {{APIVersion}}
Messaging Specific{{SmsSid}}, {{Body}}, {{NumSegments}} (Number of segments), {{NumMedia}} (Number of Media files)
Voice Specific{{CallSid}}, {{CallStatus}}, {{Direction}}, {{ParentCallSid}}

Messaging Examples

In looking at how to forward an incoming message to another number, the mustache parameters {{From}} and {{Body}} can be retrieved and stored as variables to then be utilized in forwarding the message.

Please follow this knowledge base article for more information on forwarding an incoming message to another number:

Following a similar format to the above article to show all the available message parameters, an XML Bin/webhook can use the below XML:

<Message to='+1XXXXXXXXXX' from='+1XXXXXXXXXX'> Message received with the following details:
Number of Media:{{NumMedia}}
Number of Segments: {{NumSegments}}


Voice Examples

The following XML will result in all calls being forwarded to the specified number.

Notice what is declared in the third line, the {{From}} parameter is being assigned as the value of the callerId property.

<?xml version="1.0" encoding="UTF-8"?>
<Dial callerId="{{From}}">

In this case, we are using the {{From}} value so that the caller ID for the forwarded call echoes the original calling number. In this way, your calls will have the correct caller identification.

Creating Custom Mustache Templates

A custom mustache template can be created by adding the mustache variable within an XML Bin /webhook URL.

Using the below XML in an XML Bin/webhook, the Say verb will state the value of {{YOURVARIABLE}}. We will set this value in our webhook by amending the end of the URL. We can do this by following the syntax of '?YOURVARIABLE=YOURVALUE'.

<?xml version="1.0" encoding="UTF-8"?>
Mustache Variable

Remember that after copying and pasting the XML bin URL into the phone setting options, manually add the mustache variable to the end of the URL to create and declare your custom variable.

For example, to set the variable to 123, we would enter it as '?YOURVARIABLE=123' to the end of your URL

Further References

For more information about SignalWire Compatibility XML and Mustache templates, please review this SignalWire resource HERE.

For further information about the functions of mustache templates, please read HERE.