Template language
Description
Templates are used to access event fields. For example, when generating json, you need to add a identifier of a mailing, sender or message body to it.
Keywords
Keywords begin with one of the following prefixes:
| Parameter | Meaning |
|---|---|
| $ | Inserts a value as a string. |
| $# | Allows you to use the original field type. |
| $$ | Allows you to unpack an array into several repeating structures. It should only be used with a template field of the "file" type, since you often need to add several files to a message. |
For the $ and $# prefixes, there are two options for writing the pattern:
$template.field
And
${template.field}
The $$ prefix only supports a template's notation without curly braces.
A pattern prefixed with $ can be freely combined with strings, i.e. a pipe field containing such a template may also contain constant text.
For example:
qwerty$in.a_id
or
qwerty${in.a_id}ytsuken
Patterns prefixed with $# and $$ cannot be combined with strings.
Keywords:
| Parameter | Type | Description |
|---|---|---|
| $in | Object | Data that came into the pipe from the previous one, if any. |
| $in.send_message_id | string | Send Message ID. The unique identifier of the message generated by the mailing for each profile. |
| $in.launch_id | string | Unique submission identifier. One for each mailing launch. |
| $in.a_id | int | Account ID |
| $in.c_id | int | Mailing ID. |
| $origin | Object | Data received in the pipeline. |
| $template | Object | Data configured in the message for the channel. |
| $sender | Object | Data configured in the sender for the channel. |
| $resource | Object | The data configured in the resource for the channel. |
| $campaign | Object | Data configured in the mailing for the channel. |
| $subscription | Object | Data configured in the subscription for the channel. |
| $account | Object | Data configured in the account for the channel. |
| $camp_schedule | Обьект | Mailing start and stop settings. |
| $camp_schedule.start_time | time | Scheduled mailing start time. |
| $camp_schedule.stop_time | time | Scheduled mailing stop time. |
| $error | Object | Signs of a previous pipe error |
| $error.code | int | Error code, for example HTTP code. |
| $error.message | string | Text content of the error. |
Accessing object fields
All keywords that have an Object type can have nested fields, which can also be objects or arrays of objects. Therefore, the following syntax is introduced:
- An object field is accessed via
'.'(dot). There are no restrictions on the amount of nesting.
$template.field_name.inner_field_name
- An array element is accessed via
'.%<element index>'. There are no restrictions on the amount of nesting.
$template.field_attach.%0.name
Functions
| Function | Description | Example of usage | Result |
|---|---|---|---|
$base64 | Returns base64 from the value. | $base64('Hello') | SGVsbG8= |
$gen_uniq_int_id | Returns a unique 10-digit number. | $gen_uniq_int_id() | 1726573911 |
$escapeCharacters | Removes the symbols. | $escapeCharacters('Hello 'world') | Hello world |
$getWebhookURL | Provides a webhook. | $getWebhookURL($origin.send_message_id) | https://altcraft.com/fbp/v1/1/1?fffffffffff |
$removeCodeFromPhone | Removes the area code from the phone number. | $removeCodeFromPhone('89505062312') | 9505062312 |
$#toObject | Turns JSON from a string into an object. | $#toObject('{"a": "b"}') | {"a": "b"} |
Examples
- General example
At the entrance:
{
"attribute as string": "$sender.id",
"attribute as original type": "$#sender.id",
"attribute as part of string": "test $sender.name"
"$$template.field_files_template[array]": {
"content": "[$]content",
"filename": "[$]name",
"type": "[$]mime",
"size": "[$]size",
"constant": 1,
"sender_id": "$sender.id"
}
}
At the exit:
{
"attribute as string": "145",
"attribute as original type": 145,
"attribute as part of string": "test interstellar sender"
"array": [
{
"content": "base64string",
"filename": "file1.txt",
"type": "text/plain; charset=utf-8",
"size": "10",
"constant": 1,
"sender_id": "145"
},
{
"content": "base64string",
"filename": "file2.txt",
"type": "text/plain; charset=utf-8",
"size": "100",
"constant": 1,
"sender_id": "145"
}
]
}
- Let’s assume that the
params.urlfield in the HTTP Request pipe is configured as follows:
https://example.com/handler/v${sender.version}/test
then after processing the template the params.url field will be rendered as:
https://example.com/handler/v2/test
- Let’s assume that in the Pack the
params.template.test_fieldfield is configured as follows:
qwerty$in.a_id
then after processing the template the params.url field will be rendered as:
qwerty5
but the following option will return an error because you can't concatenate a string and an int:
qwerty$#in.a_id