BaseMessage::onMessageStatusUpdated

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. BaseMessage
  4. onMessageStatusUpdated
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/basemessage.php
  • Класс: Bitrix\Crm\Activity\Provider\BaseMessage
  • Вызов: BaseMessage::onMessageStatusUpdated
static function onMessageStatusUpdated(Event $event): void
{
	[$id, $statusId] = static::fetchEventParams($event);
	if ($id <= 0 || $statusId <= 0)
	{
		return;
	}

	$status = static::getMessageStatusCode($statusId, $event);
	if (is_null($status))
	{
		return;
	}

	// do not show error messages for WhatsApp (SMS will be sent after)
	if ($status === static::MESSAGE_FAILURE && static::isWhatsappMessage($event))
	{
		return;
	}

	$activity = static::fetchActivityByMessageId($id);
	if (empty($activity))
	{
		return;
	}

	$bindings = CCrmActivity::GetBindings($activity['ID']);
	if (!$bindings)
	{
		return;
	}

	$logMessageController = LogMessageController::getInstance();
	foreach ($bindings as $binding)
	{
		$logMessageController->onCreate(
			[
				'ENTITY_TYPE_ID' => $binding['OWNER_TYPE_ID'],
				'ENTITY_ID' => $binding['OWNER_ID'],
				'ASSOCIATED_ENTITY_TYPE_ID' => $activity['TYPE_ID'],
				'ASSOCIATED_ENTITY_ID' => $activity['ID'],
				'SETTINGS' => [
					'ACTIVITY_DATA' => [
						'STATUS' => $status,
					]
				]
			],
			LogMessageType::SMS_STATUS,
			$activity['AUTHOR_ID'] ?? null
		);
	}

	if (in_array($status, [static::MESSAGE_FAILURE, static::MESSAGE_SUCCESS], true))
	{
		ActivityController::getInstance()->notifyTimelinesAboutActivityUpdate(
			$activity,
			null,
			true
		);

		ProviderManager::syncBadgesOnActivityUpdate((int)$activity['ID'], $activity);

		if ($status === static::MESSAGE_FAILURE)
		{
			static::syncActivitySettings($id, $activity);
		}
	}
}

Добавить комментарий