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.
Installation
Section titled “Installation”Put the helper into bitrix/php_interface/init.php (or include a separate file from there):
<?phpfunction 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');New online store order
Section titled “New online store order”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 ); });Order status change
Section titled “Order status change”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 ); });Form submission (module form)
Section titled “Form submission (module form)”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 ); });New user registration
Section titled “New user registration”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 ); });PHP errors
Section titled “PHP errors”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 ); }});Canary for agents
Section titled “Canary for agents”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.
Benefits
Section titled “Benefits”- 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.
Further improvements
Section titled “Further improvements”- 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.