• Модуль: imbot
  • Путь к файлу: ~/bitrix/modules/imbot/lib/bot/supportbox.php
  • Класс: BitrixImBotBotSupportBox
  • Вызов: SupportBox::activate
static function activate()
{
	if (self::checkPublicUrl() !== true)
	{
		return false;
	}

	$settings = self::getBotSettings();
	if (empty($settings))
	{
		return false;
	}
	if (!self::saveSettings($settings))
	{
		return false;
	}

	$botCode = self::getBotCode();
	if (empty($botCode))
	{
		return false;
	}

	// Stage II - convert into network bot

	$search = parent::search($botCode, true);
	if (!is_array($search) || empty($search))
	{
		$error = self::getError();
		if ($error->code === 'LINE_NOT_FOUND')
		{
			self::$lastError = new ImBotError(
				__METHOD__,
				$error->code,
				Loc::getMessage('IMBOT_NETWORK_ERROR_LINE_NOT_FOUND')
			);
		}
		return false;
	}

	$botId = parent::getNetworkBotId($botCode, true);
	if (!$botId)
	{
		$botId = parent::register([
			'CODE' => $botCode,
			'LINE_NAME' => self::getBotName(),
			'LINE_DESC' => self::getBotDesc(),
			'LINE_AVATAR' => self::getBotAvatar(),
			'CLASS' => __CLASS__,
			'TYPE' => ImBot::TYPE_NETWORK,
		]);

		if (!$botId)
		{
			return false;
		}
	}

	self::setBotId($botId);
	self::setActive(true);
	self::addAgent([
		'agent' => 'refreshAgent()', /** @see SupportBox::refreshAgent */
		'class' => __CLASS__,
		'regular' => false,
		'delay' => random_int(30, 360),
	]);

	return true;
}