Skip to main content
Version: 1.23.3

Bot Implementation Example

Consider a use case: you need to implement direct notifications via messengers.

Input data you have:

Data typevalue
Employee nameJohn Doe
Employee's messenger ID#R11F0G2SD
Employee's ID on the SimpleOne instance160707678680781750

First step: create a bot method


Create a notification method in the Bot Method (sys_bot_method) table as described in the REST Bot Engine article. Fill in the Body field with the following value:

Bot Method
{
"channel": "<routing_parameter_0>",
"text": "<content>",
"as_user": "true",
"link_names": "true"
}

In this example, the "channel": "<routing_parameter_0>" bundle specifies that the channel key substitutes the routing_parameter_0 parameter when the request is sent.

Second step: create a routing rule


Create a notification rule in the Bot Routing Rule (sys_bot_routing_rule) table.

In this case, the trigger is a new record creation in the Task table.

The routing parameters are defined in the Routing by column field of the related Routing Rule record and used for sending messages. You can specify more than one parameter; their numeration should start from 0:

Routing Parameters
{
"channel": "<routing_parameter_0>",
"thread": "<routing_parameter_1>",
"text": "<content>",
"as_user": "true",
"link_names": "true"
}

To specify the content of the method more precisely, use the fields located in the Content tab of the Bot Routing Rule record.

caution

Avoid using double quotes (" ") in the content of the bot routing rule. Ensure the number of backslashes in a row is even. If content is generated by a script that is specified in the Content script field, escape quotes and replace single backslashes (for example, by a slash) before returning values.

The following code example contains a regular expression implementing necessary substitutions:

  • single backslashes are replaced with slashes.
  • double quotes are escaped with a backslash.
Regular Expression
return `Comment: ${current.additional_comments}`
.replace(/(?<!\\)(?:((\\\\)*)\\)(?![\\/])/g, '\/')
.replace(/"/g, '\\"')

Third step: create a routing parameter


Create a routing parameter in the Routing Parameter (sys_routing_parameter) table. Fill in the field with the following values:

FieldDescriptionValue
Bot methodReference to the method that contains the current routing parameter to send a message to an employee.send.message.to.employee
Column valueThis value is checked by the bot routing rule. In this example, it is employee's ID on the SimpleOne instance.160707678680781750
Parameter valueThis parameter value is used in the body of the method specified in the Bot method field. In this example, it is an employee's ID in his messenger.#R11F0G2SD