With this functionality, you can create your own PHP Functions and Classes that can be used in the PHP Code field or in PHP code in automation. Thus, by performing various integrations with third-party services, you will not duplicate repetitive code for multiple entities.

Creating code

Go to the "Settings / Custom PHP" page and click on the "Create" button. You have the ability to create multiple pages with code and the pages can be grouped into folders.

In the "PHP code" option, enter your code. After saving the record, the entered code will be automatically included in the application.

Please note that errors are checked before saving the code, so you cannot add non-working code to the application.

For the convenience of working with the editor, hot keys have been added:
F11 - expands the editor to full screen
CTRL+S - saves the code

Live Example

Suppose we need to send a message to Telegram when adding a new task, but only if the status of the task is "New" and the type is "Urgent".

The standard rules for sending messages will not cope with this task, since only one condition can be applied in the rules.

Step 1: Create the Required Global Variables

Step 2: On Custom PHP page create a function to send a message. In the "PHP" code field, enter the following code:

function telegram_send_message($message)
{    
  global $alerts;
  
  $params=[
    'chat_id' => VAR_TELEGRAM_CHAT_ID,
    'text' => strip_tags($message,'<b><i><a><code><pre>'),
    'parse_mode' => 'HTML',
    'disable_web_page_preview' => 'true',
  ];
                                    
  $ch = curl_init("https://api.telegram.org/bot" . VAR_TELEGRAM_BOT_TOKEN ."/sendMessage");
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);            
  $result = curl_exec($ch);
  curl_close($ch);
    
  $result = json_decode($result,true);
  if(isset($result['error_code']) and is_object($alerts))
  {
    $alerts->add('Telegram Error: ' . $result['error_code'] . ' ' .  $result['description'],'error');      
  }     
}            

Step 3: In the automation of actions, we create a process for the "Task" entity and set the "Button location" option:
 Perform the process after adding the record.

Step 4: add an action for the process "execute php script" and in the "PHP code" option, enter the conditions we need to send a message to Telegram:

Step 5: check the work of the code.

As a result, we can apply the telegram_send_message function to any entity where it is necessary to send a message to Telegram.