Message template

General information

The message is generated by parsing the incoming request according to the twig pattern. The template allows basic formatting using the html tags <b> (bold), <i> (italic), <a> (link) and <br> (wrap on a new line). If the final recipient does not support formatting, it will be cut into a plain text. Links, in this case, will be converted into text looks like: "text (link)". It is possible to add files and pictures to the message like as an attachment (files and pictures will be sent to the recipients as file entities), and as an link to these files. If the final recipient does not support files and images and the template developer has not processed the processing of such a case, then the attempt to add the file will fail.
The following is an example of a message template for processing a request from Grafana:
As we see, in this template we decode the incoming request as json, extract the title from it and put it in the message header.
Next, we display the message text, highlighting the title in bold. And finally we display a link to the chart below.

Request

A set of functions for working with incoming request data.

Parameters

Returns the message header by name.
Parameter Type Required Comment
name String Yes The header name.
default String The default value if specified header name was not found.
first Boolean Return the first found header with the specified name. Otherwise, return all found headers as an array.
String | String[] Returns the value of the found header (or an array of values if "first" = false) or the default value if the header with the specified name was not found.
Example:
Get the request query parameter value.
Parameter Type Required Comment
name String Yes The query parameter name.
default String The default value if specified query parameter name was not found.
String Returns the specified query parameter value.
Example:
Get the value of the request POST parameter passed as multipart/form-data or multipart/x-www-form-urlencoded.
Parameter Type Required Comment
name String Yes The POST parameter name.
default String The default value if specified POST parameter name was not found.
String Returns the specified POST parameter value.
Example:
A function that combines the functionality of request.get and request.post functions. It will return a variable with the specified name if it was passed as a GET or POST parameter.
Parameter Type Required Comment
name String Yes Parameter name.
default String The default value if specified parameter name was not found.
String Returns the specified parameter value.
Example:
Get the cookie value by specified name.
The index of the message to parse if the incoming message contains multiple messages.
Parameter Type Required Comment
Int Returns the index of the message being parsed.
Example:

Files

Functions for manage files transferred in the request body using multipart/form-data. The functions return a File structure which can be analyzed by parameters and/or used for further addition to the final message.
The File structure contains the following fields:
Parameter Type Comment
id Int File identity.
name String File name.
mime_type String MIME-type.
size Int File size in bytes.
content String File content.
Get all files transferred in the request.
Parameter Type Required Comment
File[] Returns an array of File structures.
Example:
Get files with the specified variable name.
Parameter Type Required Comment
fieldName String Yes File field name.
File[] Returns an array of File structures.
Example:
Get files with the specified name.
Parameter Type Required Comment
fileName String Yes File name.
File[] Returns an array of File structures.
Example:

Body

Actual for POST, PUT and other requests that allows data transfer in the request body. These functions work only when the request is not sent in multipart/form-data or multipart/x-www-form-urlencoded format (in this case, use the request.post() function to get the request parameters).
Get the request body content "as is".
Parameter Type Required Comment
String Returns the request body content "as is".
Example:
Get the contents of the request body as json.
Parameter Type Required Comment
Mixed Returns the contents of the request body as json.
Example:
Get the contents of the request body as xml.
Parameter Type Required Comment
Mixed Returns the contents of the request body as xml.
Example:

Message

Functions that define the features, parameters and content of the message.

Features

A function that allows you to determine whether the recipient supports long text (depending on the recipient capabilities, the length of the message may be limited or may involve additional costs, for example SMS).
Parameter Type Required Comment
Boolean Return the long text support flag.
Example:
A function that allows you to determine whether the recipient supports formatting. Formatting with <b>, <i> and <a> html tags is allowed.
Parameter Type Required Comment
Boolean Return the formatting support flag.
Example:
A function that allows you to determine whether the recipient supports chat actions.
Parameter Type Required Comment
Boolean Return the chat actions support flag.
Example:
A function that allows you to determine whether the recipient supports file sending.
Parameter Type Required Comment
Boolean Return the file sending support flag.
Example:
A function that allows you to determine whether the recipient supports images.
Parameter Type Required Comment
Boolean Return the images support flag.
Example:

Parameters

Set the message title (by default, the message title is set based on the name of the source that generated this message).
Parameter Type Required Comment
title String Yes New message title.
Example:
Returns the previously set message title.
Parameter Type Required Comment
String Returns the message title.
Example:
Set the message priority (by default, the priority value is set to "Medium").
Parameter Type Required Comment
title String Yes New message priority. Allowed values: highest, high, normal, low, lowest.
Boolean Return the "priority is set" flag.
Example:
Returns the previously set message priority.
Parameter Type Required Comment
String Returns the message priority.
Example:
Set the message level (by default, the level value is set to "Info").
Parameter Type Required Comment
title String Yes New message level. Allowed values: verbose, info, notice, warning, error, success.
Boolean Return the "level is set" flag.
Example:
Returns the previously set message level.
Parameter Type Required Comment
String Returns the message level.
Example:

Actions

Actions are buttons that appears under the message and allow the user to take some action directly from the chat. If the recipient does not support actions, then they will be sent using simple links (if the corresponding functionality was provided by the source developer). An external service can produce a reaction to an action either using a direct call to the url specified for this action, or by requesting the message status on its own.
Adding an action button. If during of an action creation a callback url was specified, then this url will be called in the background when the action is activated.
Parameter Type Required Comment
name String Yes The action internal name for the identification.
title String Yes The displayed for user action name.
callback String Url called in the background when the action is activated.
Boolean Return the "action added successfully" flag.
Example:
Adding an action as a link. Source developer should place the link to message by himself. If during of an action creation a callback url was specified, then this url will be called in the background when the action is activated.

Files

Adding a file to the message.
Parameter Type Required Comment
file File Yes The File you get from the Request model by functions: files, filesByField, filesByName.
name String File name. By default, it will be set from the File structure (file.name).
mime_type String File MIME-type. By default, it will be set from the File structure (file.mime_type).
Boolean Returns the "file added successfully" flag.
Example:
Adding a file to the message from the content.
Parameter Type Required Comment
content String Yes File content.
name String File name.
mime_type String File MIME-type.
Boolean Returns the "file added successfully" flag.
Example:
Adding a file to the message by the link.
Parameter Type Required Comment
url String Yes File link.
name String File name.
mime_type String File MIME-type.
Boolean Returns the "file added successfully" flag.
Example:
Adding an image to the message.
Parameter Type Required Comment
file File Yes The File you get from the Request model by functions: files, filesByField, filesByName.
name String File name. By default, it will be set from the File structure (file.name).
mime_type String File MIME-type. By default, it will be set from the File structure (file.mime_type).
Boolean Returns the "image added successfully" flag.
Example:
Adding an image to the message from the content.
Parameter Type Required Comment
content String Yes File content.
name String File name.
mime_type String File MIME-type.
Boolean Returns the "image added successfully" flag.
Example:
Adding an image to the message by the link.
Parameter Type Required Comment
url String Yes File link.
name String File name.
mime_type String File MIME-type.
Boolean Returns the "image added successfully" flag.
Example:
You must use one of the functions: addFileLink, addFileLinkFromContent, addFileLinkFromUrl to organize a file link. All of these functions return a TplFile structure.
The TplFile structure contains the following fields:
Parameter Type Comment
name String File name.
url String File link.
Adding a file link to the message.
Adding a file link to the message from content.
Adding a file link to the message by the link.

Secondary functions

Calculate md5-hash of the string.
Parameter Type Required Comment
value String Yes String.
String Returns md5-hash.
Example:
Calculate sha1-hash of the string.
Parameter Type Required Comment
value String Yes String.
String Returns sha1-hash.
Example:
Decodes base64 encoded MIME data.
Parameter Type Required Comment
value String Yes base64 encoded string.
String Returns decoded data.
Example:
Encodes data to base64 MIME.
Parameter Type Required Comment
value String Yes String to encode.
String Returns encoded string.
Example:
Decodes JSON string.
Parameter Type Required Comment
value String Yes Json string.
Mixed Returns decoded data.
Example:
Encodes data to JSON string.
Parameter Type Required Comment
value Mixed Yes Data to encode
String Returns encoded JSON string.
Example:
Decodes XML string.
Parameter Type Required Comment
value String Yes XML string.
Mixed Returns decoded data.
Example:
Shortens the specified link.
Parameter Type Required Comment
link String Yes Link.
String Returns the shortened link.
Example:
Perform a regular expression match.
Parameter Type Required Comment
pattern String Yes The pattern.
content String Yes The input string.
full Boolean Return full result.
Array|String|False Returns found matches.
Example:
Perform a global regular expression match.
Parameter Type Required Comment
pattern String Yes The pattern.
content String Yes The input string.
Array|False Returns found matches.
Example: