Skip to content

Notifly in 1C-Bitrix

In Bitrix everything happens through the event system (AddEventHandler). Let’s connect it to Notifly and learn how to receive pushes at important business events.

Put the helper into bitrix/php_interface/init.php (or include a separate file from there):

<?php
function notifly_send(string $title, string $message, int $priority = 5): void {
$url = defined('NOTIFLY_URL') ? NOTIFLY_URL : (getenv('NOTIFLY_URL') ?: '');
$token = defined('NOTIFLY_TOKEN') ? NOTIFLY_TOKEN : (getenv('NOTIFLY_TOKEN') ?: '');
if (!$url || !$token) return;
$body = json_encode([
'title' => mb_substr($title, 0, 200),
'message' => mb_substr($message, 0, 1500),
'priority' => $priority,
], JSON_UNESCAPED_UNICODE);
$ch = curl_init("$url/message?token=$token");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => $body,
CURLOPT_TIMEOUT => 5,
]);
curl_exec($ch);
curl_close($ch);
}

In bitrix/.settings_extra.php (or php_interface/dbconn.php) set:

define('NOTIFLY_URL', 'https://your-notifly.example.com');
define('NOTIFLY_TOKEN', 'AGdjfk_L.dKe8q');
use Bitrix\Main\EventManager;
use Bitrix\Sale\Order;
EventManager::getInstance()->addEventHandler(
'sale', 'OnSaleOrderSaved',
function (\Bitrix\Main\Event $event) {
$order = $event->getParameter('ENTITY');
if (!$order instanceof Order) return;
if (!$event->getParameter('IS_NEW')) return;
$items = [];
foreach ($order->getBasket() as $item) {
$items[] = '' . $item->getField('NAME')
. ' × ' . (int)$item->getQuantity();
}
notifly_send(
"🛒 Заказ #{$order->getId()}" . number_format($order->getPrice(), 2, '.', ' ') . '',
"Покупатель: " . $order->getField('USER_DESCRIPTION') . "\n" .
"Состав:\n" . implode("\n", $items) . "\n\n" .
"Админка: https://" . $_SERVER['SERVER_NAME']
. "/bitrix/admin/sale_order_view.php?ID={$order->getId()}",
8
);
}
);
EventManager::getInstance()->addEventHandler(
'sale', 'OnSaleStatusOrderChange',
function ($id, $status) {
notifly_send(
"📦 Заказ #$id → статус $status",
"https://" . $_SERVER['SERVER_NAME']
. "/bitrix/admin/sale_order_view.php?ID=$id",
5
);
}
);
EventManager::getInstance()->addEventHandler(
'form', 'onAfterResultAdd',
function ($form_id, $result_id) {
$form = \CForm::GetByID($form_id)->Fetch();
notifly_send(
"✉️ Форма «{$form['NAME']}» (#$result_id)",
"Открыть: https://" . $_SERVER['SERVER_NAME']
. "/bitrix/admin/form_result_view.php?WEB_FORM_ID=$form_id&RESULT_ID=$result_id",
6
);
}
);
EventManager::getInstance()->addEventHandler(
'main', 'OnAfterUserAdd',
function (&$fields) {
if (empty($fields['ID'])) return;
notifly_send(
"👤 Новый пользователь: {$fields['LOGIN']}",
"ID: {$fields['ID']}\n" .
"Email: {$fields['EMAIL']}\n" .
"https://" . $_SERVER['SERVER_NAME']
. "/bitrix/admin/user_edit.php?ID={$fields['ID']}",
4
);
}
);

Add an error-handler in php_interface/init.php:

set_error_handler(function ($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) return;
if ($severity === E_USER_NOTICE || $severity === E_NOTICE) return;
notifly_send(
"⚠️ PHP error: $message",
"Файл: $file:$line\nURL: " . ($_SERVER['REQUEST_URI'] ?? '-'),
7
);
});
register_shutdown_function(function () {
$err = error_get_last();
if ($err && in_array($err['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
notifly_send(
"🔥 Fatal: {$err['message']}",
"Файл: {$err['file']}:{$err['line']}\nURL: " . ($_SERVER['REQUEST_URI'] ?? '-'),
10
);
}
});

Bitrix agents are run by cron or by hits. If there are few hits, agents “sleep” for days. Set up a daily beacon agent:

function NotiflyDailyAgent() {
notifly_send('🟢 Bitrix агенты живы',
'Сервер: ' . $_SERVER['SERVER_NAME'] . ', ' . date('Y-m-d H:i:s'),
2);
return 'NotiflyDailyAgent();';
}
// Регистрируется через CAgent::AddAgent() в init.php или вручную в админке

If there is no “green” for 25 hours — something is wrong with agents or cron.

  • Business notifications arrive instantly. An order lands — the push arrives before the customer closes the tab.
  • An additional channel for critical events. When Bitrix’s standard SMTP notifications get stuck in the queue or don’t arrive, Notifly works.
  • A cheap “error tracker” for large sites. Not every Bitrix owner is willing to pay for Sentry/Bugsnag.
  • Separate Notifly channels: “orders”, “forms”, “errors” — different sounds and filters.
  • Throttling via \Bitrix\Main\Data\Cache, so you don’t receive the same thing during batch imports.