Documentation

OnUpdateMessageCustom

OnUpdateMessageCustom updates messages from Open Channel. You must call the method sendStatusDelivery in response, otherwise the message will be indicated in the messenger as updated.

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 (
      'im' =>
      array (
        //Chat ID within bitrix24
        'chat_id' => '845',
        //Message ID within bitrix24
        'message_id' => '344029',
      ),
      'message' =>
      array (
        //Array of IDs for edited messages in the external system 
        //(sendStatusDelivery must return new IDs event if they are the same)
        //Foresee the case when only one value is returned!
        'id' =>
        array (
          0 => '99',
        ),
        //New message text
        'text' => '[b]John Smith:[/b][br] Text message #55',
      ),
      'chat' =>
      array (
        //Chat ID in the external system
        'id' => '2',
      ),
 );

Example

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

class Message
{
  function OnUpdateMessageCustomHandler(\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