An introduction to saving parameters as mustache variables through XML webhooks.
What is Mustache templating?
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 (https://yourspace.signalwire.com/laml-bins/your-xml-bin-id?YOURVARIABLE=123). Either method of Mustache variable declaration will work well in translating values into your XML bin.
Type of Parameter | Default 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:
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.
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'
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
For more information about SignalWire Compatible XML and Mustache templates, please review this SignalWire resource HERE
For further information about the functions of mustache templates, please read HERE