Documentation

OnBeforeSessionTransfer

Description and parameters

Event receives the object \Bitrix\Main\Event.

Input parameters can be retrieved via $eventParams = $event->getParameters();

Parameters

ParameterDescription
session Array with session data, forwarded to a new agent. Current agent from which conversation is to be removed - indicated in OPERATOR_ID element.
config Information about Open Channel to which session belongs.
chat Object Bitrix\ImOpenLines\Chat from which such session chat data can be retrieved.
reasonReturn Reason List of available reasons:

Attention! Current list of reasons can be viewed in the class \Bitrix\ImOpenLines\Queue.

\Bitrix\ImOpenLines\Queue::REASON_DEFAULT; //default
\Bitrix\ImOpenLines\Queue::REASON_OPERATOR_ABSENT = 'VACATION'; //vacation
\Bitrix\ImOpenLines\Queue::REASON_OPERATOR_DAY_PAUSE = 'NONWORKING'; //non-working time
\Bitrix\ImOpenLines\Queue::REASON_OPERATOR_DAY_END = 'NONWORKING'; //non-working time
\Bitrix\ImOpenLines\Queue::REASON_OPERATOR_DELETED = 'DISMISSAL'; //agent dismissed
\Bitrix\ImOpenLines\Queue::REASON_REMOVED_FROM_QUEUE = 'REMOVING'; //agent deleted
\Bitrix\ImOpenLines\Queue::REASON_OPERATOR_NOT_AVAILABLE = 'NOT_AVAILABLE'; //agent is unavailable
\Bitrix\ImOpenLines\Queue::REASON_OPERATOR_OFFLINE = 'OFFLINE'; //agent is offline
\Bitrix\ImOpenLines\Queue::REASON_QUEUE_TYPE_CHANGED = 'DEFAULT'; //default
for assigning new agent.
newOperatorQueue Array. The most important parameter to be returned in the event. When required, array elements can be updated and sorting logic modified.

Array elements:
  • RESULT - True or false. Bool type. Indicates, if agent (-s) were found (search includes the same current assigned agent).
  • OPERATOR_ID - Agent ID with assigned conversation. Type: int. Passing the value means that queue work is not "To everybody". Open Channel ID can be specified with indicated "queue" prefix. For example "queue55" for forwarding to Open Channel with ID 55.
  • OPERATOR_LIST - List of operators to forward the conversation to. Type: array. Passing the value means several agents, i. e. session doesn't have responsible users, but conversation is shown to several agents simultaneously. Do not use with OPERATOR_ID! simultaneously Forwarded conversation won't be automatically received, agent must accept such conversation first.
  • DATE_QUEUE - Date of next conversation distribution attempt. Pass either object Bitrix\Main\Type\DateTime, or false. When passing false, indicate 'OPERATOR_ID' or 'OPERATOR_LIST'.
  • QUEUE_HISTORY - Queue assignment history. Add an agent (if not added) at the end in the following format: array key - user id. Value: true.


Data verification


Data returned by the handler is verified. When something does not pass the verification, standard algorithm is triggered that removes the handler from equation.

Creates additional event OnErrorEventBeforeSessionTransfer.

You can subscribe it for debugging. Passes in parameters the array of errors and the object, returned by event handler.


Result example

array (
  'errors' => 
  array (
    0 => 'The result of the processing of the event returned with an error',
  ),
  'eventResult' => 
  Bitrix\Main\EventResult::__set_state(array(
     'moduleId' => NULL,
     'handler' => NULL,
     'type' => 0,
     'parameters' => 
    array (
      'RESULT' => 5,
    ),
  )),
)

This solution must significantly simplify debugging.


Code example


"Draft" events

$eventManager = \Bitrix\Main\EventManager::getInstance();

$eventManager->addEventHandler('imopenlines', 'OnBeforeSessionTransfer', 'onBeforeSessionTransfer');
$eventManager->addEventHandler('imopenlines', 'OnErrorEventBeforeSessionTransfer', 'onErrorEventBeforeSessionTransfer');

public static function onBeforeSessionTransfer(\Bitrix\Main\Event $event)
{
   $eventParams = $event->getParameters();
   //test
   define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
   AddMessage2Log(var_export($eventParams,1), 'onBeforeSessionTransfer');
   //END test
   $eventParams['newOperatorQueue'] = [
      'RESULT' => true,
      'OPERATOR_ID' => 1,
      'OPERATOR_LIST' =>
         [],
      'DATE_QUEUE' => false,
      'QUEUE_HISTORY' =>
         [
            1 => true,
         ],
   ];

   return new \Bitrix\Main\EventResult(
      \Bitrix\Main\EventResult::SUCCESS,
      $eventParams
   );
}

public static function onErrorEventBeforeSessionTransfer(\Bitrix\Main\Event $event)
{
   $eventParams = $event->getParameters();
   //test
   define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
   AddMessage2Log(var_export($eventParams,1), 'OnErrorEventBeforeSessionTransfer');
   //END test
}

© «Bitrix24», 2001-2024
Up