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}}
Inbound Domain Apps{{SipUser}}

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.

Using Custom Mustache Templates

A custom mustache template can be created by adding the mustache variable within an XML Bin/Webhook URL or a SIP Address.

With XML Bins or Webhooks

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. Assuming we want to make the value of the variable equal to Something, our XML Bin URL or Webhook URL will look similar to:

<?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.

With Domain Applications

When calling a Domain Application that handles incoming calls with a LaML Webhook, you can still pass the custom mustache variable in the SIP URL, much like you would with Webhooks, by adding ?YOURVARIABLE=YOURVALUE at the end:

Assuming the Domain App calls the same XML Bin/Webhook as the one we outlined above, we just need to prefix the variable name with SipHeader_X-, making the end result SipHeader_X-YOURVARIABLE.

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

This is particularly useful in BYOC setups where you wish to send calls to SignalWire and adjust the FROM number on the fly using a custom variable:

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

If you wished to call +1111111111 from +123456789, your SIP URL would look like this:

URL Encoding

Notice the encoded + in the FROM_NUMBER, as %2B? Since it is a reserved character, we need to encode it when passing it in the URL. To learn more about URL Encoding, please read this page.

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.