Integration of the MTS SMS (Belarus) SMS service with 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Integration of MTS SMS Service (Belarus) with 1C-Bitrix

MTS Belarus has no ready-made module for 1C-Bitrix. The MTS SMPP gateway (smpp.mts.by) works via the binary SMPP v3.4 protocol, while MTS SMS Pro HTTP API communicates via REST with OAuth 2.0 authorization. The standard messageservice module in Bitrix knows how to send SMS through providers, but out of the box only supports sms.ru, SMS-centre, and Twilio. For MTS Belarus, you need a custom provider.

Architecture of Bitrix SMS subsystem

The messageservice module stores the list of registered providers in the \Bitrix\MessageService\Sender\SmsManager class. Each provider is a class implementing the \Bitrix\MessageService\Sender\Base interface. Key methods:

  • sendMessage() — send a single message, returns SendMessage with external ID and status.
  • getShortName() — provider identifier for storage in the database.
  • canUse() — check availability (presence of keys, activity).

Provider registration occurs via the onMessageServiceSenderList event of the messageservice module. The handler returns an array of provider classes. After registration, the provider appears in the administrative interface Settings → Message Services.

Connection via MTS SMS Pro HTTP API

MTS SMS Pro provides a REST endpoint https://api.mts.by/sms/v1/messages. Authorization is a Bearer token obtained via https://api.mts.by/oauth/token using client_credentials.

Integration sequence:

  1. Obtaining credentials. In the MTS SMS Pro personal account, an application is created and client_id and client_secret are issued. An alphanumeric sender name (sender name) is registered separately — without it, messages are sent from a numeric number.

  2. Implementation of the provider class. The class inherits from \Bitrix\MessageService\Sender\Base and implements three things: OAuth token caching (lifetime — 3600 seconds), JSON request body formation, response handling with MTS error codes.

  3. Status mapping. MTS returns statuses: DELIVERED, EXPIRED, REJECTED, UNKNOWN. They need to be translated to Bitrix statuses: \Bitrix\MessageService\Message\StatusSemantic::DELIVERED, ERROR, etc.

Request format to MTS API:

POST /sms/v1/messages
{
  "phone": "375291234567",
  "text": "Your order #123 has been placed",
  "sender": "MyShop",
  "validity": 1440
}

The validity field is the message lifetime in minutes. For transactional SMS (confirmation codes) set 5–10 minutes, for informational — 1440 (24 hours).

Settings storage and security

Keys client_id and client_secret are stored in the b_option table of the messageservice module. Access via \Bitrix\Main\Config\Option::get('messageservice', 'mts_client_id'). Don't store secrets in configuration files that go into VCS — use .settings_extra.php or environment variables.

OAuth token is cached in \Bitrix\Main\Data\Cache with a key bound to client_id. On a 401 error (token expired), the provider should automatically request a new token and retry sending — once, without recursion.

Integration with CRM and Sale

After registering the SMS provider, MTS becomes available in several places:

  • sale module — order status change notifications. Templates are set in Store → Settings → Order Statuses → SMS Notifications. Variables #ORDER_ID#, #ORDER_STATUS#, #TRACKING_NUMBER# are substituted automatically.
  • Bitrix24 CRM — if using the out-of-the-box Bitrix24, the provider appears in SMS campaign settings and business process robots. The CRM: Send SMS robot allows you to select the MTS provider.
  • Two-factor authentication — the security module can use SMS for login confirmation. The provider is connected in OTP settings.

Error handling and monitoring

MTS API returns HTTP 200 even with partial errors — the status of an individual message must be checked in the response body. Typical error codes:

Code Reason Action
1 Invalid phone format Validation on Bitrix side before sending
5 Limit exceeded Queue with retry via agent
10 Sender name not registered Check settings in MTS account
20 Insufficient funds Alert administrator via \CAdminNotify::Add()

For monitoring, implement an agent that checks the status of sent messages every hour via GET /sms/v1/messages/{id}/status and updates records in b_messageservice_message.

Implementation timeline

Scope Timeline Includes
Sale notifications only 3–4 days Provider, status templates, testing
Sale + CRM robots 5–7 days + business process setup, status mapping
Full integration + monitoring 1–2 weeks + status agent, alerts, logging, load testing

When connecting, keep in mind that MTS Belarus charges separately for transactional and promotional SMS. Promotional SMS requires subscriber consent (opt-in) — Bitrix should check the UF_SMS_CONSENT flag in the user profile before sending marketing messages.