• Модуль: imbot
  • Путь к файлу: ~/bitrix/modules/imbot/lib/bot/network.php
  • Класс: BitrixImBotBotNetwork
  • Вызов: Network::registerApps
static function registerApps(?int $botId = null): bool
{
	$botId = $botId ?: static::getBotId();
	if (!$botId)
	{
		return false;
	}

	if (!MainLoader::includeModule('im'))
	{
		return false;
	}

	$appList = [];
	$res = ImModelAppTable::getList([
		'filter' => [
			'=MODULE_ID' => static::MODULE_ID,
			'=BOT_ID' => $botId,
			'=CLASS' => static::class,
		]
	]);
	while ($row = $res->fetch())
	{
		$appList[$row['CODE']] = $row;
	}

	ImApp::clearCache();
	foreach (static::getAppList() as $appParam)
	{
		if (!isset($appList[$appParam['command']]))
		{
			$iconId = '';
			if (MainIOFile::isFileExists(MainApplication::getDocumentRoot() . $appParam['icon']))
			{
				$iconId = MainApplication::getDocumentRoot() . $appParam['icon'];
			}
			if ($iconId)
			{
				$icon = CFile::makeFileArray($iconId);
				$icon['MODULE_ID'] = static::MODULE_ID;
				$iconId = CFile::saveFile($icon, static::MODULE_ID);
			}
			ImApp::register([
				'MODULE_ID' => static::MODULE_ID,
				'BOT_ID' => $botId,
				'CODE' => $appParam['command'],
				'ICON_ID' => $iconId,
				'JS' => $appParam['js'] ?? '',
				'CONTEXT' => $appParam['context'],
				'CLASS' => $appParam['class'] ?? static::class,
				'METHOD_LANG_GET' => $appParam['lang'] ?? 'onAppLang',
			]);
		}
		unset($appList[$appParam['command']]);
	}
	foreach ($appList as $appParam)
	{
		ImApp::unRegister(['ID' => $appParam['ID']]);
	}

	return true;
}