MessageSender::send

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. MessageSender
  4. send
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/messagesender/messagesender.php
  • Класс: Bitrix\Crm\MessageSender\MessageSender
  • Вызов: MessageSender::send
static function send(array $sendersOptions, array $options = []): Result
{
	if (!$sendersOptions)
	{
		return (new Result())->addError(new Error('Sender options have not been specified'));
	}

	$currentSender = SenderPicker::getCurrentSender();
	if ($currentSender && isset($sendersOptions[$currentSender::getSenderCode()]))
	{
		$sender = $currentSender;
		$senderOptions = $sendersOptions[$sender::getSenderCode()];
	}
	else
	{
		$sender = SenderPicker::getSenderByCode(key($sendersOptions));
		$senderOptions = current($sendersOptions);
	}

	if (!$sender)
	{
		return (new Result())->addError(new Error('Sender has not been found'));
	}

	if (!$sender::canSendMessage())
	{
		return (new Result())->addError(new Error('Sender is not available'));
	}

	$result = $sender::sendMessage(
		$sender::makeMessageFields(
			$senderOptions,
			$options['COMMON_OPTIONS'] ?? []
		)
	);

	if ($result instanceof Result)
	{
		return $result;
	}

	return (new Result())->addError(new Error('Message has not been sent'));
}

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