- Модуль: pull
- Путь к файлу: ~/bitrix/modules/pull/lib/rest.php
- Класс: BitrixPullRest
- Вызов: Rest::applicationPushAdd
static function applicationPushAdd($params, $n, CRestServer $server)
{
$params = array_change_key_case($params, CASE_UPPER);
$clientId = $server->getClientId();
if (!$clientId)
{
throw new BitrixRestRestException("Send push notifications available only for application authorization.", "WRONG_AUTH_TYPE", CRestServer::STATUS_FORBIDDEN);
}
if (!self::isAdmin())
{
throw new BitrixRestRestException("You do not have access to send push notifications", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$users = Array();
if (is_string($params['USER_ID']))
{
$params['USER_ID'] = CUtil::JsObjectToPhp($params['USER_ID']);
}
if (is_array($params['USER_ID']))
{
foreach ($params['USER_ID'] as $userId)
{
$userId = intval($userId);
if ($userId > 0)
{
$users[$userId] = $userId;
}
}
$users = array_values($users);
}
else
{
$users = (int)$params['USER_ID'];
}
if (!$params['TEXT'] || $params['TEXT'] == '')
{
throw new BitrixRestRestException("Text can't be empty", "TEXT_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$result = BitrixRestAppTable::getList(
array(
'filter' => array(
'=CLIENT_ID' => $clientId
),
'select' => array(
'CODE',
'APP_NAME',
'APP_NAME_DEFAULT' => 'LANG_DEFAULT.MENU_NAME',
)
)
)->fetch();
if (empty($result['APP_NAME']))
{
throw new BitrixRestRestException("For send push-notification application name can't be empty", "EMPTY_APP_NAME", CRestServer::STATUS_WRONG_REQUEST);
}
$appName = $result['APP_NAME'];
$text = $params['TEXT'];
$avatar = '';
if ($params['AVATAR'])
{
$parsedUrl = new MainWebUri($params['AVATAR']);
$params['AVATAR'] = $parsedUrl->getUri();
if ($params['AVATAR'])
{
$avatar = $params['AVATAR'];
}
}
Push::add($users,
[
'module_id' => 'im',
'push' =>
[
'message' => $text,
'advanced_params' =>
[
"group"=> $clientId,
"avatarUrl"=> $avatar,
"senderName" => $appName,
"senderMessage" => $text,
],
]
]);
return true;
}