Documentation

OnSendMessageCustom

OnSendMessageCustom new message from Open Channel. You must call the method sendStatusDelivery in response, otherwise the message will be deemed in the messenger as undelivered.

The event receives the following parameters:

Parameter Description
CONNECTOR Connector ID. Use it to check if the event relates to you.
LINE Open Channel ID
DATA Array containing other arrays describing the message:
array (
    //Array of parameters for communication (returned in the delivery message)
      'im' =>
      array (
      	//Chat ID within Bitrix24
        	'chat_id' => 845,
        	//Message ID within Bitrix24
        	'message_id' => 344029,
      ),
      'message' =>
      array (
//Message text
        	'text' => '[b]John Smith:[/b][br] Text message'
      ),
      'chat' =>
      array (
      	//External chat ID
       	 'id' => '2',
    ),
);

Example

\Bitrix\Main\EventManager::getInstance()->addEventHandler("imconnector", "OnSendMessageCustom", Array("Message", "OnSendMessageCustomHandler"));

class Message
{
  function OnSendMessageCustomHandler(\Bitrix\Main\Event $event)
  {
     $connector = $event->getParameter('CONNECTOR');
     $line = $event->getParameter('LINE');
     $data = $event->getParameter('DATA');

     foreach ($data as $message)
     {
        $statusDelivery[]= array(
           'im' => $message['im'],
           'message' => array(
              'id' => array(5),
           ),
           'chat' => array(
              'id' => $message['chat']['id']
           ),
        );
     }

     if(!empty($statusDelivery))
     {
        \Bitrix\ImConnector\CustomConnectors::sendStatusDelivery($connector, $line,
           $statusDelivery);
     }

           //test
                 define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
                 AddMessage2Log(var_export(array('$connector' => $connector, '$line' => $line,'$data' => $data),1), 'SendMessage');
                 //END test
  }
}


© «Bitrix24», 2001-2024
Up