The capability to send SMS is integrated into several scenarios within Bitrix24, ranging from manual initiation through a CRM entity form, automated initiation through a CRM automation rule or business process action, to utilization of the CRM marketing tool.
Notably, SMS is not the sole channel for delivering messages to clients; messages may be sent to any channel that can identify the recipient by phone number.
Integration with SMS provider
To proceed, click the "New Application" button and select the main region for the future solution. Then, hit the "Create" button and specify the "Use REST API" type in the solution form. Ensure that the "Message Service" scope has been added to the list.
Download the attached example in the tutorial and upload it to your server using the same procedure as in the lessons on local integrations.
Insert the path to the uploaded application in the version form and copy the values from the client_id and client_secret fields into the corresponding constants in the settings.php file.
Accessibility from an external network
It is crucial to note that the address of the uploaded example must be accessible from the external network, free of localhost, self-signed SSL certificates, and similar restrictions. Verify the URL's availability through third-party services, rather than relying solely on browser access.
Examine the example code and begin with the install.php file. Here, we call the installApp method, familiar from previous lessons, to save the authorization tokens in a file for future use.
We then immediately use these tokens to execute the messageservice.sender.add method, utilizing only four parameters:
- CODE - the symbol code of our provider, which distinguishes it from other potential providers installed in Bitrix24.
- TYPE - the provider type, set to SMS, for Bitrix24 to understand in which scenarios the provider will be available.
- HANDLER - a reference to the handler that will receive a POST request from Bitrix24 containing the data about the message to be sent.
- NAME - the provider's name, visible to users in the Bitrix24 interface.
Finally, return to the Developer area.
The present page facilitates the installation of the app to your Bitrix24 portal, allowing you to test it prior to its publication on Bitrix24.Market.
Enter the address of your Bitrix24 portal, where you hold administrative privileges, and click the "Install" button.
This will redirect you to the portal and activate the app installation interface. Upon publishing the application in Bitrix24.Market, with descriptions and screenshots provided, the installation process will appear more polished, however, for now it is vital to ensure its technical functionality.
Upon completion of the installation, Bitrix24 will automatically launch the app, as it features a user interface.
The first step in the main app interface is to introduce a mechanism for user authorization in the SMS provider service, as well as enabling the user to specify the requisite API keys and settings.
To confirm the registration of our provider, navigate to the CRM contacts and select a contact with a phone number.
Click the "SMS/WhatsApp" button. Bitrix24 will prompt you to send a message through the installed provider, which can be verified by clicking on the "More" link. Type your message, e.g. "[Good afternoon John, we have a special offer for you]", and send it.
Then, return to the code to observe what Bitrix24 sent to our handler.
The resulting array has a straightforward structure, displaying which Bitrix24 tool was utilized for sending, the binding of the message to a specific CRM client, and several other parameters. The most significant values for sending are the recipient's phone number, message text, and Bitrix24's internal message identifier.
These data can be utilized for API calls to the SMS provider to send the message from the app.
Note the variable "message_id". If the provider, integrated within the app in Bitrix24, can inform about the message delivery status, "message_id" will facilitate the "messageservice.message.status.update" REST method to update the message status in the Bitrix24 interface.
You may access the CRM automation rule settings in deals and verify that your provider is also available in Bitrix24 automation tools. Add the "Send SMS" automation rule and locate your provider on the list.
By registering just one handler, the app's provider is made available in all Bitrix24 scenarios involving sending messages.