Views: 2925
Last Modified: 24.06.2021
Handler registration
Event handler OnImConnectorBuildList for imconnector module is registered either in init.php, or when installing the module.
Handler example:
\Bitrix\Main\EventManager::getInstance()->addEventHandler("imconnector", "OnImConnectorBuildList", Array("MyClass", "OnImConnectorBuildListHandler"));
class MyClass
{
function OnImConnectorBuildListHandler()
{
return array(
//connector ID
'ID' => 'baseconnector',
//Connector name
'NAME' => 'Base connector',
//Icon description
'ICON' => array(
'DATA_IMAGE' => 'data:image/svg+xml;charset=US-ASCII,%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20viewBox%3D%220%200%2070%2071%22%20style%3D%22enable-background%3Anew%200%200%2070%2071%3B%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20fill%3D%22%230C99BA%22%20class%3D%22st0%22%20d%3D%22M34.7%2C64c-11.6%2C0-22-7.1-26.3-17.8C4%2C35.4%2C6.4%2C23%2C14.5%2C14.7c8.1-8.2%2C20.4-10.7%2C31-6.2%0A%09c12.5%2C5.4%2C19.6%2C18.8%2C17%2C32.2C60%2C54%2C48.3%2C63.8%2C34.7%2C64L34.7%2C64z%20M27.8%2C29c0.8-0.9%2C0.8-2.3%2C0-3.2l-1-1.2h19.3c1-0.1%2C1.7-0.9%2C1.7-1.8%0A%09v-0.9c0-1-0.7-1.8-1.7-1.8H26.8l1.1-1.2c0.8-0.9%2C0.8-2.3%2C0-3.2c-0.4-0.4-0.9-0.7-1.5-0.7s-1.1%2C0.2-1.5%2C0.7l-4.6%2C5.1%0A%09c-0.8%2C0.9-0.8%2C2.3%2C0%2C3.2l4.6%2C5.1c0.4%2C0.4%2C0.9%2C0.7%2C1.5%2C0.7C26.9%2C29.6%2C27.4%2C29.4%2C27.8%2C29L27.8%2C29z%20M44%2C41c-0.5-0.6-1.3-0.8-2-0.6%0A%09c-0.7%2C0.2-1.3%2C0.9-1.5%2C1.6c-0.2%2C0.8%2C0%2C1.6%2C0.5%2C2.2l1%2C1.2H22.8c-1%2C0.1-1.7%2C0.9-1.7%2C1.8v0.9c0%2C1%2C0.7%2C1.8%2C1.7%2C1.8h19.3l-1%2C1.2%0A%09c-0.5%2C0.6-0.7%2C1.4-0.5%2C2.2c0.2%2C0.8%2C0.7%2C1.4%2C1.5%2C1.6c0.7%2C0.2%2C1.5%2C0%2C2-0.6l4.6-5.1c0.8-0.9%2C0.8-2.3%2C0-3.2L44%2C41z%20M23.5%2C32.8%0A%09c-1%2C0.1-1.7%2C0.9-1.7%2C1.8v0.9c0%2C1%2C0.7%2C1.8%2C1.7%2C1.8h23.4c1-0.1%2C1.7-0.9%2C1.7-1.8v-0.9c0-1-0.7-1.8-1.7-1.9L23.5%2C32.8L23.5%2C32.8z%22/%3E%0A%3C/svg%3E%0A',
'COLOR' => '#1900ff',
//Possible
'SIZE' => '90%',
'POSITION' => 'center'
),
'ICON_DISABLED' => array(
'DATA_IMAGE' => 'data:image/svg+xml;charset=US-ASCII,%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20viewBox%3D%220%200%2070%2071%22%20style%3D%22enable-background%3Anew%200%200%2070%2071%3B%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20fill%3D%22%235c6470%22%20class%3D%22st0%22%20d%3D%22M34.7%2C64c-11.6%2C0-22-7.1-26.3-17.8C4%2C35.4%2C6.4%2C23%2C14.5%2C14.7c8.1-8.2%2C20.4-10.7%2C31-6.2%0A%09c12.5%2C5.4%2C19.6%2C18.8%2C17%2C32.2C60%2C54%2C48.3%2C63.8%2C34.7%2C64L34.7%2C64z%20M27.8%2C29c0.8-0.9%2C0.8-2.3%2C0-3.2l-1-1.2h19.3c1-0.1%2C1.7-0.9%2C1.7-1.8%0A%09v-0.9c0-1-0.7-1.8-1.7-1.8H26.8l1.1-1.2c0.8-0.9%2C0.8-2.3%2C0-3.2c-0.4-0.4-0.9-0.7-1.5-0.7s-1.1%2C0.2-1.5%2C0.7l-4.6%2C5.1%0A%09c-0.8%2C0.9-0.8%2C2.3%2C0%2C3.2l4.6%2C5.1c0.4%2C0.4%2C0.9%2C0.7%2C1.5%2C0.7C26.9%2C29.6%2C27.4%2C29.4%2C27.8%2C29L27.8%2C29z%20M44%2C41c-0.5-0.6-1.3-0.8-2-0.6%0A%09c-0.7%2C0.2-1.3%2C0.9-1.5%2C1.6c-0.2%2C0.8%2C0%2C1.6%2C0.5%2C2.2l1%2C1.2H22.8c-1%2C0.1-1.7%2C0.9-1.7%2C1.8v0.9c0%2C1%2C0.7%2C1.8%2C1.7%2C1.8h19.3l-1%2C1.2%0A%09c-0.5%2C0.6-0.7%2C1.4-0.5%2C2.2c0.2%2C0.8%2C0.7%2C1.4%2C1.5%2C1.6c0.7%2C0.2%2C1.5%2C0%2C2-0.6l4.6-5.1c0.8-0.9%2C0.8-2.3%2C0-3.2L44%2C41z%20M23.5%2C32.8%0A%09c-1%2C0.1-1.7%2C0.9-1.7%2C1.8v0.9c0%2C1%2C0.7%2C1.8%2C1.7%2C1.8h23.4c1-0.1%2C1.7-0.9%2C1.7-1.8v-0.9c0-1-0.7-1.8-1.7-1.9L23.5%2C32.8L23.5%2C32.8z%22/%3E%0A%3C/svg%3E%0A',
//'COLOR' => '#1900ff',
//Possible
'SIZE' => '90%',
'POSITION' => 'center'
),
//component ID
'COMPONENT' => 'bitrix:imconnector.baseconnector',
//Permission to delete received messages
'DEL_EXTERNAL_MESSAGES' => true,
//Permission to edit his/her messages
'EDIT_INTERNAL_MESSAGES' => true,
//Permission to delete his/her messages
'DEL_INTERNAL_MESSAGES' => true,
//Can channel be used for email campaign?
'NEWSLETTER' => true,
//Can system messages be sent to channel?
'NEED_SYSTEM_MESSAGES' => true,
//Can signature be sent to channel inside the message?
'NEED_SIGNATURE' => true,
//Is the chat is a group chat?
'CHAT_GROUP' => false,
);
}
}
Handler must return an array with the following parameters:
Returned parameters
|
Parameter | Description |
ID | Connector ID, unique for the complete system. Required parameter. It's better to add a custom prefix to avoid conflicting with current and possible future connector IDs. The following characters can be used: digits, letters and underscore. |
NAME | Displayed connector name. Required. |
ICON | Array with connector icon description. Required. Array key:
- DATA_IMAGE - DATA image for SVG icon. Service http://www.grumpicon.com/ can be used for conversion. Required
- COLOR - color
- SIZE - size
- POSITION - position svg
|
COMPONENT | Component ID with indicated component namespace title. Required. |
DEL_EXTERNAL_MESSAGES | Delete inbound messages? Default value: yes. |
EDIT_INTERNAL_MESSAGES | Edit you messages? Default value: yes. |
DEL_INTERNAL_MESSAGES | Delete your messages? Default value: yes. |
NEWSLETTER | Use channel for CRM newsletter? Default value: yes. |
NEED_SYSTEM_MESSAGES | Send system messages in channel? For example: greeting, closeout message and etc. Default value: yes. |
NEED_SIGNATURE | Send signature inside the message? Default value: yes. For example: string with operator name is added in front of the message. |
CHAT_GROUP | Is this channel chat is the group chat, accessible by external users? Default value: no. |
|
Channel setup:
Connector type works within a configured open channel. Save information about a configured open channel ID.
Module includes the component imconnector.baseconnector that may be used as basis for customization and creating its own settings component.
Custom component must operate in the AJAX mode without causing page reload. Also the component receives the parameter $this->arParams['LINE']
, with passed open channel ID.
System requires correct statuses indicated in the component. The class \Bitrix\ImConnector\Status
is responsible.
Get status object via the call:
$this->status = \Bitrix\ImConnector\Status::getInstance($this->connector, $this->arParams['LINE']);
$this->status->isStatus();
- method returns, if connector is ready for use.
$this->status->getActive()
- activates channel.
$this->status->getConnection()
- establishes connector.
$this->status->getRegister()
- successful registration.
$this->status->getError()
- operation error (blocking).
Channel is deemed as ready for use, if it's active for this Open Channel and test connection is successful and registered. No errors are registered as well.
You can activate the channel by calling $this->status->setActive(true);
Set successful connection status check: $this->status->setConnection(true);
Set successful registration status: $this->status->setRegister(true);
Error reset (for channel to renew operation) can be done via $this->status->setError(false);
.
When deleting (disabling) connector, call a static method:
\Bitrix\ImConnector\Status::delete($this->connector, $this->arParams['LINE']);
Upon any config updates, reset channel data cache:
$cache = \Bitrix\Main\Data\Cache::createInstance();
$cache->clean($this->arParams['LINE'], \Bitrix\ImConnector\Library::CACHE_DIR_INFO_CONNECTORS_LINE);
Or use the method cleanCache from the example in component.
Handling the messages
After setting up the channel, use the following methods for handling the messages CustomConnectors.
Also, use the events for creating and deleting new messages.