11if (!CModule::IncludeModule(
'rest'))
22 'im.user.get' =>
array(__CLASS__,
'userGet'),
23 'im.user.list.get' =>
array(__CLASS__,
'userList'),
24 'im.user.business.list' =>
array(__CLASS__,
'userBusinessList'),
25 'im.user.business.get' =>
array(
'callback' =>
array(__CLASS__,
'userBusinessList'),
'options' =>
array(
'private' =>
true)),
27 'im.user.status.get' =>
array(__CLASS__,
'userStatusGet'),
28 'im.user.status.set' =>
array(__CLASS__,
'userStatusSet'),
29 'im.user.status.idle.start' =>
array(__CLASS__,
'userStatusIdleStart'),
30 'im.user.status.idle.end' =>
array(__CLASS__,
'userStatusIdleEnd'),
32 'im.recent.get' =>
array(__CLASS__,
'recentGet'),
33 'im.recent.list' =>
array(__CLASS__,
'recentList'),
34 'im.recent.pin' =>
array(__CLASS__,
'recentPin'),
35 'im.recent.hide' =>
array(__CLASS__,
'recentHide'),
36 'im.recent.unread' =>
array(__CLASS__,
'recentUnread'),
38 'im.department.get' =>
array(__CLASS__,
'departmentGet'),
39 'im.department.colleagues.list' =>
array(__CLASS__,
'departmentColleaguesList'),
40 'im.department.colleagues.get' =>
array(
'callback' =>
array(__CLASS__,
'departmentColleaguesList'),
'options' =>
array(
'private' =>
true)),
41 'im.department.managers.get' =>
array(__CLASS__,
'departmentManagersGet'),
42 'im.department.employees.get' =>
array(__CLASS__,
'departmentEmployeesGet'),
44 'im.chat.add' =>
array(__CLASS__,
'chatCreate'),
45 'im.chat.getEntityChat' =>
array(__CLASS__,
'chatGetEntityChat'),
46 'im.chat.get' =>
array(__CLASS__,
'chatGet'),
47 'im.chat.setOwner' =>
array(__CLASS__,
'chatSetOwner'),
48 'im.chat.setManager' =>
array(__CLASS__,
'chatSetManager'),
49 'im.chat.updateColor' =>
array(__CLASS__,
'chatUpdateColor'),
50 'im.chat.updateTitle' =>
array(__CLASS__,
'chatUpdateTitle'),
51 'im.chat.updateAvatar' =>
array(__CLASS__,
'chatUpdateAvatar'),
52 'im.chat.leave' =>
array(__CLASS__,
'chatUserDelete'),
53 'im.chat.user.add' =>
array(__CLASS__,
'chatUserAdd'),
54 'im.chat.user.delete' =>
array(__CLASS__,
'chatUserDelete'),
55 'im.chat.user.list' =>
array(__CLASS__,
'chatUserList'),
56 'im.chat.sendTyping' =>
array(
'callback' =>
array(__CLASS__,
'dialogWriting'),
'options' =>
array(
'private' =>
true)),
57 'im.chat.mute' =>
array(__CLASS__,
'chatMute'),
58 'im.chat.parent.join' =>
array(
'callback' =>
array(__CLASS__,
'chatParentJoin'),
'options' =>
array(
'private' =>
true)),
59 'im.chat.url.get' =>
array(
'callback' =>
array(__CLASS__,
'chatUrlGet'),
'options' =>
array(
'private' =>
true)),
60 'im.chat.url.delete' =>
array(
'callback' =>
array(__CLASS__,
'chatUrlDelete'),
'options' =>
array(
'private' =>
true)),
61 'im.chat.url.counter.get' =>
array(
'callback' =>
array(__CLASS__,
'chatUrlCounterGet'),
'options' =>
array(
'private' =>
true)),
62 'im.chat.file.get' =>
array(
'callback' =>
array(__CLASS__,
'chatFileGet'),
'options' =>
array(
'private' =>
true)),
63 'im.chat.file.collection.get' =>
array(
'callback' =>
array(__CLASS__,
'chatFileCollectionGet'),
'options' =>
array(
'private' =>
true)),
64 'im.chat.favorite.get' =>
array(
'callback' =>
array(__CLASS__,
'chatFavoriteGet'),
'options' =>
array(
'private' =>
true)),
65 'im.chat.favorite.add' =>
array(
'callback' =>
array(__CLASS__,
'chatFavoriteAdd'),
'options' =>
array(
'private' =>
true)),
66 'im.chat.favorite.delete' =>
array(
'callback' =>
array(__CLASS__,
'chatFavoriteDelete'),
'options' =>
array(
'private' =>
true)),
67 'im.chat.favorite.counter.get' =>
array(
'callback' =>
array(__CLASS__,
'chatFavoriteCounterGet'),
'options' =>
array(
'private' =>
true)),
68 'im.chat.task.get' =>
array(
'callback' =>
array(__CLASS__,
'chatTaskGet'),
'options' =>
array(
'private' =>
true)),
69 'im.chat.task.delete' =>
array(
'callback' =>
array(__CLASS__,
'chatTaskDelete'),
'options' =>
array(
'private' =>
true)),
70 'im.chat.task.prepare' =>
array(
'callback' =>
array(__CLASS__,
'chatTaskPrepare'),
'options' =>
array(
'private' =>
true)),
71 'im.chat.calendar.get' =>
array(
'callback' =>
array(__CLASS__,
'chatCalendarGet'),
'options' =>
array(
'private' =>
true)),
72 'im.chat.calendar.add' =>
array(
'callback' =>
array(__CLASS__,
'chatCalendarAdd'),
'options' =>
array(
'private' =>
true)),
73 'im.chat.calendar.delete' =>
array(
'callback' =>
array(__CLASS__,
'chatCalendarDelete'),
'options' =>
array(
'private' =>
true)),
74 'im.chat.calendar.prepare' =>
array(
'callback' =>
array(__CLASS__,
'chatCalendarPrepare'),
'options' =>
array(
'private' =>
true)),
75 'im.chat.sign.get' =>
array(
'callback' =>
array(__CLASS__,
'chatSignGet'),
'options' =>
array(
'private' =>
true)),
76 'im.chat.pin.get' =>
array(
'callback' =>
array(__CLASS__,
'chatPinGet'),
'options' =>
array(
'private' =>
true)),
77 'im.chat.pin.add' =>
array(
'callback' =>
array(__CLASS__,
'chatPinAdd'),
'options' =>
array(
'private' =>
true)),
78 'im.chat.pin.delete' =>
array(
'callback' =>
array(__CLASS__,
'chatPinDelete'),
'options' =>
array(
'private' =>
true)),
79 'im.chat.reminder.get' =>
array(
'callback' =>
array(__CLASS__,
'chatReminderGet'),
'options' =>
array(
'private' =>
true)),
80 'im.chat.reminder.add' =>
array(
'callback' =>
array(__CLASS__,
'chatReminderAdd'),
'options' =>
array(
'private' =>
true)),
81 'im.chat.reminder.delete' =>
array(
'callback' =>
array(__CLASS__,
'chatReminderDelete'),
'options' =>
array(
'private' =>
true)),
83 'im.dialog.get' =>
array(__CLASS__,
'dialogGet'),
84 'im.dialog.messages.get' =>
array(__CLASS__,
'dialogMessagesGet'),
85 'im.dialog.messages.search' =>
array(
'callback' =>
array(__CLASS__,
'dialogMessagesSearch'),
'options' =>
array(
'private' =>
true)),
86 'im.dialog.context.get' =>
array(
'callback' =>
array(__CLASS__,
'dialogContextGet'),
'options' =>
array(
'private' =>
true)),
87 'im.dialog.users.get' =>
array(
'callback' =>
array(__CLASS__,
'dialogUsersGet'),
'options' =>
array(
'private' =>
true)),
88 'im.dialog.users.list' =>
array(__CLASS__,
'dialogUsersList'),
89 'im.dialog.read' =>
array(__CLASS__,
'dialogRead'),
90 'im.dialog.readAll' =>
array(
'callback' =>
array(__CLASS__,
'dialogReadAll'),
'options' =>
array(
'private' =>
true)),
91 'im.dialog.read.all' =>
array(__CLASS__,
'dialogReadAll'),
92 'im.dialog.unread' =>
array(__CLASS__,
'dialogUnread'),
93 'im.dialog.writing' =>
array(__CLASS__,
'dialogWriting'),
95 'im.message.add' =>
array(__CLASS__,
'messageAdd'),
96 'im.message.delete' =>
array(__CLASS__,
'messageDelete'),
97 'im.message.update' =>
array(__CLASS__,
'messageUpdate'),
98 'im.message.like' =>
array(__CLASS__,
'messageLike'),
99 'im.message.command' =>
array(
'callback' =>
array(__CLASS__,
'messageCommand')),
100 'im.message.share' =>
array(
'callback' =>
array(__CLASS__,
'messageShare')),
101 'im.message.user.get' =>
array(
'callback' =>
array(__CLASS__,
'messageUserGet'),
'options' =>
array(
'private' =>
true)),
103 'im.notify' =>
array(
'callback' =>
array(__CLASS__,
'notifyAdd'),
'options' =>
array(
'private' =>
false)),
104 'im.notify.get' =>
array(
'callback' =>
array(__CLASS__,
'notifyGet'),
'options' =>
array(
'private' =>
true)),
105 'im.notify.personal.add' =>
array(__CLASS__,
'notifyAdd'),
106 'im.notify.system.add' =>
array(__CLASS__,
'notifyAdd'),
107 'im.notify.delete' =>
array(__CLASS__,
'notifyDelete'),
108 'im.notify.read' =>
array(__CLASS__,
'notifyRead'),
109 'im.notify.read.list' =>
array(__CLASS__,
'notifyReadList'),
110 'im.notify.read.all' =>
array(__CLASS__,
'notifyReadAll'),
111 'im.notify.confirm' =>
array(__CLASS__,
'notifyConfirm'),
112 'im.notify.answer' =>
array(__CLASS__,
'notifyAnswer'),
113 'im.notify.history.search' =>
array(
'callback' =>
array(__CLASS__,
'notifyHistorySearch'),
'options' =>
array(
'private' =>
true)),
114 'im.notify.schema.get' =>
array(
'callback' =>
array(__CLASS__,
'notifySchemaGet'),
'options' =>
array(
'private' =>
true)),
116 'im.disk.folder.list.get' =>
array(
'callback' =>
array(__CLASS__,
'diskFolderListGet'),
'options' =>
array(
'private' =>
true)),
117 'im.disk.folder.get' =>
array(__CLASS__,
'diskFolderGet'),
118 'im.disk.file.commit' =>
array(__CLASS__,
'diskFileCommit'),
119 'im.disk.file.delete' =>
array(__CLASS__,
'diskFileDelete'),
120 'im.disk.file.save' =>
array(__CLASS__,
'diskFileSave'),
121 'im.disk.record.share' =>
array(__CLASS__,
'diskRecordShare'),
123 'im.counters.get' =>
array(__CLASS__,
'counterGet'),
125 'im.search.user.list' =>
array(__CLASS__,
'searchUser'),
126 'im.search.user' =>
array(
'callback' =>
array(__CLASS__,
'searchUser'),
'options' =>
array(
'private' =>
true)),
127 'im.search.chat.list' =>
array(__CLASS__,
'searchChat'),
128 'im.search.chat' =>
array(
'callback' =>
array(__CLASS__,
'searchChat'),
'options' =>
array(
'private' =>
true)),
129 'im.search.department.list' =>
array(__CLASS__,
'searchDepartment'),
130 'im.search.department' =>
array(
'callback' =>
array(__CLASS__,
'searchDepartment'),
'options' =>
array(
'private' =>
true)),
132 'im.search.last.get' =>
array(__CLASS__,
'searchLastGet'),
133 'im.search.last.add' =>
array(__CLASS__,
'searchLastAdd'),
134 'im.search.last.delete' =>
array(__CLASS__,
'searchLastDelete'),
136 'im.promotion.get' =>
array(
'callback' =>
array(__CLASS__,
'promotionGet'),
'options' =>
array(
'private' =>
true)),
137 'im.promotion.read' =>
array(
'callback' =>
array(__CLASS__,
'promotionRead'),
'options' =>
array(
'private' =>
true)),
139 'im.mobile.config.get' =>
array(
'callback' =>
array(__CLASS__,
'mobileConfigGet'),
'options' =>
array(
'private' =>
true)),
141 'im.call.user.register' =>
array(
'callback' =>
array(__CLASS__,
'callUserRegister'),
'options' =>
array(
'private' =>
true)),
142 'im.call.user.update' =>
array(
'callback' =>
array(__CLASS__,
'callUserUpdate'),
'options' =>
array(
'private' =>
true)),
143 'im.call.user.force.rename' =>
array(
'callback' =>
array(__CLASS__,
'callUserForceRename'),
'options' =>
array(
'private' =>
true)),
144 'im.call.channel.public.list' =>
array(
'callback' =>
array(__CLASS__,
'callChannelPublicList'),
'options' =>
array(
'private' =>
true)),
146 'im.videoconf.share.change' =>
array(
'callback' =>
array(__CLASS__,
'videoconfShareChange'),
'options' =>
array(
'private' =>
true)),
147 'im.videoconf.password.check' =>
array(
'callback' =>
array(__CLASS__,
'videoconfPasswordCheck'),
'options' =>
array(
'private' =>
true)),
148 'im.videoconf.add' =>
array(
'callback' =>
array(__CLASS__,
'videoconfAdd'),
'options' =>
array(
'private' =>
true)),
149 'im.videoconf.update' =>
array(
'callback' =>
array(__CLASS__,
'videoconfUpdate'),
'options' =>
array(
'private' =>
true)),
151 'im.desktop.status.get' =>
array(
'callback' =>
array(__CLASS__,
'desktopStatusGet'),
'options' =>
array(
'private' =>
true)),
152 'im.desktop.page.open' =>
array(
'callback' =>
array(__CLASS__,
'desktopPageOpen'),
'options' =>
array(
'private' =>
true)),
155 'imbot.register' =>
array(__CLASS__,
'botRegister'),
156 'imbot.unregister' =>
array(__CLASS__,
'botUnRegister'),
157 'imbot.update' =>
array(__CLASS__,
'botUpdate'),
159 'imbot.dialog.get' =>
array(__CLASS__,
'dialogGet'),
160 'imbot.dialog.vote' =>
array(__CLASS__,
'dialogVote'),
162 'imbot.chat.add' =>
array(__CLASS__,
'chatCreate'),
163 'imbot.chat.get' =>
array(__CLASS__,
'chatGet'),
164 'imbot.chat.setOwner' =>
array(__CLASS__,
'chatSetOwner'),
165 'imbot.chat.setManager' =>
array(__CLASS__,
'chatSetManager'),
166 'imbot.chat.updateColor' =>
array(__CLASS__,
'chatUpdateColor'),
167 'imbot.chat.updateTitle' =>
array(__CLASS__,
'chatUpdateTitle'),
168 'imbot.chat.updateAvatar' =>
array(__CLASS__,
'chatUpdateAvatar'),
169 'imbot.chat.leave' =>
array(__CLASS__,
'chatUserDelete'),
170 'imbot.chat.user.add' =>
array(__CLASS__,
'chatUserAdd'),
171 'imbot.chat.user.delete' =>
array(__CLASS__,
'chatUserDelete'),
172 'imbot.chat.user.list' =>
array(__CLASS__,
'chatUserList'),
173 'imbot.chat.sendTyping' =>
array(__CLASS__,
'botSendTyping'),
174 'imbot.chat.updateTextFieldEnabled' =>
array(__CLASS__,
'botUpdateTextFieldEnabled'),
176 'imbot.bot.list' =>
array(__CLASS__,
'botList'),
178 'imbot.message.add' =>
array(__CLASS__,
'botMessageAdd'),
179 'imbot.message.delete' =>
array(__CLASS__,
'botMessageDelete'),
180 'imbot.message.update' =>
array(__CLASS__,
'botMessageUpdate'),
181 'imbot.message.like' =>
array(__CLASS__,
'botMessageLike'),
183 'imbot.sendTyping' =>
array(
'callback' =>
array(__CLASS__,
'botSendTyping'),
'options' =>
array(
'private' =>
true)),
185 'imbot.command.register' =>
array(__CLASS__,
'commandRegister'),
186 'imbot.command.unregister' =>
array(__CLASS__,
'commandUnRegister'),
187 'imbot.command.update' =>
array(__CLASS__,
'commandUpdate'),
188 'imbot.command.answer' =>
array(__CLASS__,
'commandAnswer'),
190 'imbot.app.register' =>
array(
'callback' =>
array(__CLASS__,
'appRegister'),
'options' =>
array(
'private' =>
false)),
191 'imbot.app.unregister' =>
array(
'callback' =>
array(__CLASS__,
'appUnRegister'),
'options' =>
array(
'private' =>
false)),
192 'imbot.app.update' =>
array(
'callback' =>
array(__CLASS__,
'appUpdate'),
'options' =>
array(
'private' =>
false)),
194 CRestUtil::EVENTS =>
array(
195 'OnImBotMessageAdd' =>
array(
'im',
'onImBotMessageAdd',
array(__CLASS__,
'onBotMessageAdd'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT,
"sendRefreshToken" =>
true)),
196 'OnImBotMessageUpdate' =>
array(
'im',
'onImBotMessageUpdate',
array(__CLASS__,
'onBotMessageUpdate'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT,
"sendRefreshToken" =>
true)),
197 'OnImBotMessageDelete' =>
array(
'im',
'onImBotMessageDelete',
array(__CLASS__,
'onBotMessageDelete'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT,
"sendRefreshToken" =>
true)),
198 'OnImBotJoinChat' =>
array(
'im',
'onImBotJoinChat',
array(__CLASS__,
'onBotJoinChat'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT)),
199 'OnImBotDelete' =>
array(
'im',
'onImBotDelete',
array(__CLASS__,
'onBotDelete'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT)),
200 'OnImBotContextGet' =>
array(
'im',
'onImBotContextGet',
array(__CLASS__,
'onBotContextGet'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT,
"sendRefreshToken" =>
true)),
201 'OnImCommandAdd' =>
array(
'im',
'onImCommandAdd',
array(__CLASS__,
'onCommandAdd'),
array(
"category" => \
Bitrix\Rest\Sqs::CATEGORY_BOT,
"sendRefreshToken" =>
true)),
209 if(!\
Bitrix\Main\Loader::includeModule(
'rest'))
216 $bots = \Bitrix\Im\Bot::getListCache();
217 foreach ($bots as $bot)
219 if ($bot[
'APP_ID'] ==
$result[
'CLIENT_ID'])
221 \Bitrix\Im\Bot::unRegister(Array(
'BOT_ID' => $bot[
'BOT_ID']));
243 if ($user->isExists())
255 if ($isExtranet && !\
Bitrix\Im\Integration\Socialnetwork\Extranet::isUserInGroup(
$userId, $currentUserId))
257 throw new Bitrix\Rest\RestException(
"You can request only users who consist of your extranet group",
"ACCESS_DENIED", CRestServer::STATUS_WRONG_REQUEST);
260 $result = $user->getArray(Array(
'JSON' =>
'Y',
'HR_PHOTO' => isset(
$arParams[
'AVATAR_HR']) &&
$arParams[
'AVATAR_HR'] ==
'Y'));
262 $result[
'desktop_last_date'] = \CIMMessenger::GetDesktopStatusOnline(
$userId);
263 $result[
'desktop_last_date'] =
$result[
'desktop_last_date']? date(
'c',
$result[
'desktop_last_date']):
false;
291 throw new Bitrix\Rest\RestException(
"A wrong format for the ID field is passed",
"INVALID_FORMAT", CRestServer::STATUS_WRONG_REQUEST);
297 $extranetUsers = Array($currentUserId);
305 foreach ($group[
'USERS'] as
$userId)
316 if ($isExtranet && !isset($extranetUsers[
$userId]))
325 if (mb_strtolower((
$arParams[
'RESULT_TYPE'] ??
'')) ===
'array')
337 $withUserData =
$arParams[
'USER_DATA'] ==
'Y';
378 if (!is_string(
$params[
'STATUS']))
383 if (!in_array(
$params[
'STATUS'], \CIMStatus::$AVAILABLE_STATUSES))
414 \CIMStatus::SetIdle(
$userId,
true, $ago);
423 \CIMStatus::SetIdle(
$userId,
false);
441 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
447 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
453 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
468 $arParams[
'DIALOG_ID'] =
'chat'.$arParams[
'CHAT_ID'];
478 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
485 if (!preg_match(
'/^\d{1,}$/i',
$arParams[
'FIRST_ID']))
493 if (!preg_match(
'/^\d{1,}$/i',
$arParams[
'LAST_ID']))
503 return \Bitrix\Im\Chat::getMessages($chatId,
null,
$options);
510 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
511 'SEARCH_MESSAGE' =>
$arParams[
'SEARCH_MESSAGE'] ??
null,
512 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
519 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC',
521 if (!isset(
$filter[
'CHAT_ID']))
523 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
529 if (!$chat->checkAccess()->isSuccess())
531 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
534 $startId = $chat->getStartId();
538 $filter[
'START_ID'] = $startId;
546 public static function dialogContextGet(
$arParams,
$n, CRestServer $server)
558 if (
$message->getMessageId() ===
null)
560 throw new \Bitrix\Rest\RestException(
'Message not found', \Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
563 if (!
$message->getChat()->checkAccess()->isSuccess())
565 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat', Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
570 throw new Bitrix\Rest\RestException(
'Range can`t be empty',
'RANGE_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
574 $range = ($range <= 50 && $range >= 0) ? $range : 50;
576 $result = (new \Bitrix\Im\V2\Message\MessageService(
$message))->getMessageContext($range);
582 throw new Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), CRestServer::STATUS_WRONG_REQUEST);
589 return (
new RestAdapter(
$messages))->toRestFormat();
598 $arParams[
'DIALOG_ID'] =
'chat'.$arParams[
'CHAT_ID'];
608 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
613 return \Bitrix\Im\Chat::getUsers($chatId, [
'JSON' =>
'Y']);
626 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
632 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
636 '=CHAT_ID' => $chatId,
637 '=USER.ACTIVE' =>
'Y',
640 isset(
$params[
'SKIP_EXTERNAL']) &&
$params[
'SKIP_EXTERNAL'] ===
'Y'
641 || isset(
$params[
'SKIP_EXTERNAL_EXCEPT_TYPES']))
644 $options[
'SKIP_EXTERNAL_EXCEPT_TYPES'] = array_map(
'trim', mb_split(
',',
$params[
'SKIP_EXTERNAL_EXCEPT_TYPES']));
646 $exceptType =
$options[
'SKIP_EXTERNAL_EXCEPT_TYPES'] ?? [];
657 return \Bitrix\Im\Chat::getUsers($chatId,
$options);
660 $counter = \Bitrix\Im\Model\RelationTable::getCount($countFilter);
698 $arParams[
'DIALOG_ID'] =
'chat'.$arParams[
'CHAT_ID'];
736 return \Bitrix\Im\Dialog::readAll();
746 throw new Bitrix\Rest\RestException(
"First unread message id can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
771 'FILTER' => Array(
'SEARCH' =>
$arParams[
'FIND']),
776 $params[
'FILTER'][
'BUSINESS'] =
'Y';
780 if (is_null($ormParams))
785 $ormParams[
'select'] =
array(
"CNT" =>
new \
Bitrix\Main\Entity\ExpressionField(
'CNT',
'COUNT(1)'));
819 'FILTER' => Array(
'SEARCH' =>
$arParams[
'FIND']),
821 'OFFSET' => intval($offset) > 0? $offset: (isset(
$arParams[
'OFFSET']) && intval(
$arParams[
'OFFSET']) > 0? intval(
$arParams[
'OFFSET']): 0),
824 'USER_DATA' =>
$arParams[
'USER_DATA'] ==
'Y'?
'Y':
'N',
849 'FILTER' => Array(
'SEARCH' =>
$arParams[
'FIND'] ??
null,
'SEARCH_OL' =>
$arParams[
'FIND_LINES'] ??
null),
854 if (is_null($ormParams))
859 $ormParams[
'select'] =
array(
"CNT" =>
new \
Bitrix\Main\Entity\ExpressionField(
'CNT',
'COUNT(1)'));
861 $counter = \Bitrix\Im\Model\ChatTable::getList($ormParams)->fetch();
868 $params[
'ORDER'] = Array(
'ID' =>
'DESC');
890 $config = Array(
'JSON' =>
'Y');
893 $config[
'SKIP_OPENLINES'] =
'Y';
904 return \Bitrix\Im\LastSearch::get(
null,
$config);
916 return \Bitrix\Im\LastSearch::add(
$arParams[
'DIALOG_ID'])?
true:
false;
928 return \Bitrix\Im\LastSearch::delete(
$arParams[
'DIALOG_ID']);
936 $config = Array(
'JSON' =>
'Y');
940 $config[
'ONLY_OPENLINES'] =
'Y';
944 $config[
'FORCE_OPENLINES'] =
'Y';
947 $config[
'SKIP_OPENLINES'] =
'Y';
967 $config[
'LAST_SYNC_DATE'] = new \Bitrix\Main\Type\DateTime(
$arParams[
'LAST_SYNC_DATE'], \DateTimeInterface::RFC3339);
969 catch (Exception $e){}
972 return \Bitrix\Im\Recent::get(
null,
$config);
979 $skipChatParam =
$arParams[
'SKIP_CHAT'] ??
null;
980 $skipDialogParam =
$arParams[
'SKIP_DIALOG'] ??
null;
981 $unreadOnly =
$arParams[
'UNREAD_ONLY'] ??
null;
982 $parseText =
$arParams[
'PARSE_TEXT'] ??
null;
984 $config = Array(
'JSON' =>
'Y');
987 $config[
'SKIP_OPENLINES'] =
'Y';
989 if (isset(
$arParams[
'SKIP_UNDISTRIBUTED_OPENLINES']) &&
$arParams[
'SKIP_UNDISTRIBUTED_OPENLINES'] ===
'Y')
991 $config[
'SKIP_UNDISTRIBUTED_OPENLINES'] =
'Y';
1001 if (isset(
$arParams[
'CAN_MANAGE_MESSAGES']) &&
$arParams[
'CAN_MANAGE_MESSAGES'] ===
'Y')
1003 $config[
'CAN_MANAGE_MESSAGES'] =
'Y';
1005 if ($skipChatParam ===
'Y')
1009 if ($skipDialogParam ===
'Y')
1013 if ($unreadOnly ===
'Y')
1019 $config[
'GET_ORIGINAL_TEXT'] =
'Y';
1023 $config[
'GET_ORIGINAL_TEXT'] =
'N';
1025 if ($parseText ===
'Y')
1034 $config[
'LAST_MESSAGE_DATE'] = new \Bitrix\Main\Type\DateTime(
$arParams[
'DATE_LAST_ACTIVITY'], \DateTimeInterface::RFC3339);
1036 catch (Exception $e){}
1043 $config[
'LAST_MESSAGE_DATE'] = new \Bitrix\Main\Type\DateTime(
$arParams[
'LAST_MESSAGE_DATE'], \DateTimeInterface::RFC3339);
1045 catch (Exception $e){}
1090 return \Bitrix\Im\Recent::hide(
$arParams[
'DIALOG_ID']);
1107 return \Bitrix\Im\Recent::unread(
$arParams[
'DIALOG_ID'],
$arParams[
'UNREAD'] !==
'N');
1117 if (in_array(
$arParams[
'DEVICE_TYPE'], \
Bitrix\Im\Promotion::getDeviceTypes(),
true))
1122 return \Bitrix\Im\Promotion::getActive($promoType);
1129 return \Bitrix\Im\Promotion::read(
$arParams[
'ID']);
1137 \
Bitrix\Im\User::getInstance()->isExtranet()
1138 || \
Bitrix\Im\User::getInstance()->isBot()
1141 throw new Bitrix\Rest\RestException(
"Only intranet users have access to this method.",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
1165 throw new Bitrix\Rest\RestException(
"A wrong format for the ID field is passed",
"INVALID_FORMAT", CRestServer::STATUS_WRONG_REQUEST);
1169 'FILTER' => Array(
'ID' => $ids),
1170 'USER_DATA' =>
$arParams[
'USER_DATA'] ==
'Y'?
'Y':
'N',
1181 \
Bitrix\Im\User::getInstance()->isExtranet()
1182 || \
Bitrix\Im\User::getInstance()->isBot()
1185 throw new Bitrix\Rest\RestException(
"Only intranet users have access to this method.",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
1190 $withUserData =
$arParams[
'USER_DATA'] ==
'Y';
1214 return \Bitrix\Im\Department::getManagers($ids,
array(
'JSON' =>
'Y',
'USER_DATA' => $withUserData?
'Y':
'N'));
1220 \
Bitrix\Im\User::getInstance()->isExtranet()
1221 || \
Bitrix\Im\User::getInstance()->isBot()
1224 throw new Bitrix\Rest\RestException(
"Only intranet users have access to this method.",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
1229 $withUserData =
$arParams[
'USER_DATA'] ==
'Y';
1253 return \Bitrix\Im\Department::getEmployees($ids,
array(
'JSON' =>
'Y',
'USER_DATA' => $withUserData?
'Y':
'N'));
1259 \
Bitrix\Im\User::getInstance()->isExtranet()
1260 || \
Bitrix\Im\User::getInstance()->isBot()
1263 throw new Bitrix\Rest\RestException(
"Only intranet users have access to this method.",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
1268 $withUserData =
$arParams[
'USER_DATA'] ==
'Y';
1315 if (!is_integer(
$uid) && !is_string(
$uid))
1317 throw new Bitrix\Rest\RestException(
"Parameter USERS has wrong type",
"INVALID_FORMAT", CRestServer::STATUS_WRONG_REQUEST);
1327 'TYPE' =>
$arParams[
'TYPE'] ==
'OPEN' ? Chat::TYPE_OPEN : Chat::TYPE_GROUP,
1349 $add[
'DESCRIPTION'] =
$arParams[
'DESCRIPTION'];
1352 if (\
Bitrix\Im\User::getInstance()->isExtranet())
1360 $add[
'ENTITY_TYPE'] =
$arParams[
'ENTITY_TYPE'];
1364 $add[
'ENTITY_ID'] =
$arParams[
'ENTITY_ID'];
1368 if (isset(
$arParams[
'COPILOT_MAIN_ROLE']))
1370 $add[
'CHAT_PARAMS'][] = [
1372 'PARAM_VALUE' =>
$arParams[
'COPILOT_MAIN_ROLE']
1378 if ($server->
getMethod() ==
"imbot.chat.add")
1384 $chatId = $CIMChat->Add($add);
1396 if (!
$USER->IsAuthorized())
1398 throw new \Bitrix\Rest\RestException(
"Method not available for guest session.",
"AUTHORIZE_ERROR", \CRestServer::STATUS_FORBIDDEN);
1412 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
1418 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
1424 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
1436 $chatData = \Bitrix\Im\Model\ChatTable::getList(Array(
1439 '=ENTITY_TYPE' =>
$arParams[
'ENTITY_TYPE'],
1446 'ID' => (
int)$chatData[
'ID']
1486 if ($server->
getMethod() == mb_strtolower(
"imbot.chat.setOwner"))
1491 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'])
1500 throw new Bitrix\Rest\RestException(
"Change owner can only owner and user must be member in chat",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
1539 if ($server->
getMethod() == mb_strtolower(
"imbot.chat.setManager"))
1548 throw new Bitrix\Rest\RestException(
"Change manager can only owner and user must be member in chat",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
1580 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'] && !CIMChat::CanSendMessageToGeneralChat(
$userId))
1587 throw new Bitrix\Rest\RestException(
"This color currently unavailable",
"WRONG_COLOR", CRestServer::STATUS_WRONG_REQUEST);
1591 if ($server->
getMethod() == mb_strtolower(
"imbot.chat.updateColor"))
1601 throw new Bitrix\Rest\RestException(
"This color currently set or chat isn't exists",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
1638 if ($server->
getMethod() == mb_strtolower(
"imbot.chat.updateTitle"))
1643 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'] && !CIMChat::CanSendMessageToGeneralChat(
$userId))
1648 if (!Chat::isActionAllowed(
'chat' .
$arParams[
'CHAT_ID'],
'RENAME'))
1684 $chat = \Bitrix\Im\Model\ChatTable::getById(
$arParams[
'CHAT_ID'])->fetch();
1685 $chatRelation = \CIMChat::GetRelationById(
$arParams[
'CHAT_ID'],
false,
true,
false);
1687 if (!CIMChat::canDo($chat, $chatRelation, \
Bitrix\Im\V2\Permission\Action::ChangeAvatar))
1693 if ($server->
getMethod() == mb_strtolower(
"imbot.chat.updateAvatar"))
1698 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'] && !CIMChat::CanSendMessageToGeneralChat(
$userId))
1703 if (!Chat::isActionAllowed(
'chat' .
$arParams[
'CHAT_ID'],
'AVATAR'))
1705 throw new Bitrix\Rest\RestException(
'The avatar of this chat cannot be changed',
'ACCESS_ERROR', CRestServer::STATUS_FORBIDDEN);
1714 $imageCheck = (new \Bitrix\Main\File\Image(
$arParams[
'AVATAR'][
"tmp_name"]))->getInfo();
1717 || !$imageCheck->getWidth()
1718 || $imageCheck->getWidth() > 5000
1719 || !$imageCheck->getHeight()
1720 || $imageCheck->getHeight() > 5000
1723 throw new Bitrix\Rest\RestException(
"Avatar incorrect size (max 5000x5000)",
"AVATAR_ERROR", CRestServer::STATUS_WRONG_REQUEST);
1762 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'])
1767 if (!Chat::isActionAllowed(
'chat' .
$arParams[
'CHAT_ID'],
'EXTEND'))
1769 throw new Bitrix\Rest\RestException(
'It is forbidden to add users to this chat',
'ACCESS_ERROR', CRestServer::STATUS_FORBIDDEN);
1773 if ($server->
getMethod() ==
"imbot.chat.user.add")
1778 $hideHistory =
null;
1783 $hideHistory =
false;
1787 $hideHistory = (bool)
$arParams[
'HIDE_HISTORY'];
1799 throw new Bitrix\Rest\RestException(
"User IDs must be passed in array format",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
1808 throw new Bitrix\Rest\RestException(
"You don't have access or user already member in chat",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
1840 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'])
1845 if (!Chat::isActionAllowed(
'chat' .
$arParams[
'CHAT_ID'],
'LEAVE'))
1847 throw new Bitrix\Rest\RestException(
'It is forbidden to delete users of this chat',
'ACCESS_ERROR', CRestServer::STATUS_FORBIDDEN);
1851 if (in_array($server->
getMethod(), Array(
"imbot.chat.leave",
"imbot.chat.user.delete")))
1856 if (in_array($server->
getMethod(), Array(
"im.chat.user.delete",
"imbot.chat.user.delete")) &&
$arParams[
'USER_ID'] <= 0)
1866 if (
$error->GetID() ===
'LEAVE_OWNER_FORBIDDEN')
1871 throw new Bitrix\Rest\RestException(
"You don't have access or user isn't member in chat",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
1902 if (CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID'])
1908 if ($server->
getMethod() ==
"imbot.chat.user.list")
1913 $arChat = CIMChat::GetChatData(
array(
1919 return isset($arChat[
'userInChat'][
$arParams[
'CHAT_ID']])? $arChat[
'userInChat'][
$arParams[
'CHAT_ID']]: Array();
1944 if (!Chat::isActionAllowed(
'chat' .
$arParams[
'CHAT_ID'],
'MUTE'))
1982 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
1999 'SEARCH_URL' =>
$arParams[
'SEARCH_URL'] ??
null,
2000 'USER_ID' =>
$arParams[
'USER_ID'] ??
null,
2001 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2008 'MESSAGE_ID' =>
$arParams[
'ORDER'][
'MESSAGE_ID'] ??
'DESC'
2010 if (!isset(
$filter[
'CHAT_ID']))
2012 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2018 if (!$chat->checkAccess()->isSuccess())
2020 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2023 $startId = $chat->getStartId();
2027 $filter[
'START_ID'] = $startId;
2041 throw new \Bitrix\Rest\RestException(
'LINK_ID can`t be empty',
'LINK_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2045 $url = new \Bitrix\Im\V2\Link\Url\UrlItem($linkId);
2046 if (
$url->getId() ===
null)
2048 throw new \Bitrix\Rest\RestException(
'Url not found', \
Bitrix\Im\V2\Entity\Url\UrlError::NOT_FOUND, \CRestServer::STATUS_NOT_FOUND);
2051 $chatId =
$url->getChatId();
2054 if (!$chat->checkAccess()->isSuccess())
2056 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2064 throw new \Bitrix\Rest\RestException(
'You do not have access to delete this url', \
Bitrix\Im\V2\Entity\Url\UrlError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2067 $urls = new \Bitrix\Im\V2\Link\Url\UrlCollection();
2070 $deleteResult = (new \Bitrix\Im\V2\Link\Url\UrlService())->deleteUrls($urls);
2072 if (!$deleteResult->isSuccess())
2074 throw new \Bitrix\Rest\RestException(
'Failed to delete url', \
Bitrix\Im\V2\Entity\Url\UrlError::DELETE_ERROR, \CRestServer::STATUS_INTERNAL);
2085 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2091 if (!$chat->checkAccess()->isSuccess())
2093 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2096 $startId = $chat->getStartId();
2099 'counter' => (new \Bitrix\Im\V2\Link\Url\UrlService())->getCount($chatId, $startId)
2107 'SEARCH_FILE_NAME' =>
$arParams[
'SEARCH_FILE_NAME'] ??
null,
2108 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
2109 'SUBTYPE' =>
$arParams[
'SUBTYPE'] ??
null,
2110 'USER_ID' =>
$arParams[
'USER_ID'] ??
null,
2111 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2118 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC',
2120 if (!isset(
$filter[
'CHAT_ID']))
2122 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2128 if (!$chat->checkAccess()->isSuccess())
2130 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2133 if (isset(
$filter[
'SUBTYPE']))
2135 $filter[
'SUBTYPE'] = FileItem::normalizeFilterFromJsonFormat(
$filter[
'SUBTYPE']);
2139 $filter[
'GROUP'] = FileItem::normalizeFilterFromJsonFormat(
$filter[
'GROUP']);
2142 $startId = $chat->getStartId();
2146 $filter[
'START_ID'] = $startId;
2149 $files = FileCollection::find(
$filter,
$order, $limit,
new \
Bitrix\Im\V2\Service\Context());
2158 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2161 if (!isset(
$filter[
'CHAT_ID']))
2163 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2169 if (!$chat->checkAccess()->isSuccess())
2171 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2174 $startId = $chat->getStartId();
2178 $filter[
'START_ID'] = $startId;
2183 foreach (SubtypeGroup::cases() as $subtypeGroup)
2185 $filter[
'GROUP'] = $subtypeGroup->value;
2186 $filesBySubtype = FileCollection::find(
$filter, [], $limit);
2188 foreach ($filesBySubtype as $fileBySubtype)
2190 $files[] = $fileBySubtype;
2201 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
2202 'SEARCH_MESSAGE' =>
$arParams[
'SEARCH_MESSAGE'] ??
null,
2203 'USER_ID' =>
$arParams[
'USER_ID'] ??
null,
2204 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2210 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC',
2212 if (!isset(
$filter[
'CHAT_ID']))
2214 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2220 if (!$chat->checkAccess()->isSuccess())
2222 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2227 return (
new RestAdapter($favoriteMessage))->toRestFormat();
2235 throw new \Bitrix\Rest\RestException(
'MESSAGE_ID can`t be empty',
'MESSAGE_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2242 if (
$message->getMessageId() ===
null)
2244 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2249 if (!$chat->checkAccess()->isSuccess())
2251 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2256 throw new \Bitrix\Rest\RestException(
'You do not have access to this message', \
Bitrix\Im\V2\Message\MessageError::ACCESS_DENIED, \CRestServer::STATUS_FORBIDDEN);
2259 $markResult =
$message->markAsFavorite();
2260 if (!$markResult->isSuccess())
2262 $error = $markResult->getErrors()[0];
2265 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2269 return $markResult->isSuccess();
2277 throw new \Bitrix\Rest\RestException(
'MESSAGE_ID can`t be empty',
'MESSAGE_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2284 if (
$message->getMessageId() ===
null)
2286 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2289 $unmarkResult =
$message->unmarkAsFavorite();
2290 if (!$unmarkResult->isSuccess())
2292 $error = $unmarkResult->getErrors()[0];
2295 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2299 return $unmarkResult->isSuccess();
2307 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2313 if (!$chat->checkAccess()->isSuccess())
2315 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2319 'counter' => (new \Bitrix\Im\V2\Link\Favorite\FavoriteService())->getCount($chatId)
2327 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2328 'USER_ID' =>
$arParams[
'USER_ID'] ??
null,
2331 'SEARCH_TASK_NAME' =>
$arParams[
'SEARCH_TASK_NAME'] ??
null,
2332 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
2336 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC'
2338 if (!isset(
$filter[
'CHAT_ID']))
2340 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2346 if (!$chat->checkAccess()->isSuccess())
2348 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2362 throw new \Bitrix\Rest\RestException(
'LINK_ID can`t be empty',
'LINK_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2366 $task = new \Bitrix\Im\V2\Link\Task\TaskItem($linkId);
2367 if ($task->getId() ===
null)
2369 throw new \Bitrix\Rest\RestException(
'Task not found', \
Bitrix\Im\V2\Entity\Task\TaskError::NOT_FOUND, \CRestServer::STATUS_NOT_FOUND);
2372 $chatId = $task->getChatId();
2375 if (!$chat->checkAccess()->isSuccess() || !$chat->canDo(\
Bitrix\Im\V2\Permission\Action::CreateTask))
2377 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2383 if (
$userId !== $task->getAuthorId() && !
$USER->IsAdmin())
2385 throw new \Bitrix\Rest\RestException(
'You do not have access to delete this task', \
Bitrix\Im\V2\Entity\Task\TaskError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2388 $deleteResult = (new \Bitrix\Im\V2\Link\Task\TaskService())->unregisterTask($task,
false);
2390 if (!$deleteResult->isSuccess())
2392 throw new \Bitrix\Rest\RestException(
'Failed to delete task', \
Bitrix\Im\V2\Entity\Task\TaskError::DELETE_ERROR, \CRestServer::STATUS_INTERNAL);
2401 if ($server->
getAuthType() !== \
Bitrix\Rest\SessionAuth\Auth::AUTH_TYPE && !self::isDebugEnabled())
2403 throw new \Bitrix\Rest\RestException(
'This method is available only with session auth type',
'WRONG_AUTH_TYPE', \CRestServer::STATUS_WRONG_REQUEST);
2415 if (
$message->getMessageId() ===
null)
2417 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2430 throw new Bitrix\Rest\RestException(
'Message ID and chat ID can`t be empty together',
'CHAT_ID_MESSAGE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
2433 if (!$chat->checkAccess()->isSuccess())
2435 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2440 throw new \Bitrix\Rest\RestException(
'You do not have access to this message', \
Bitrix\Im\V2\Message\MessageError::ACCESS_DENIED, \CRestServer::STATUS_FORBIDDEN);
2443 $taskService = new \Bitrix\Im\V2\Link\Task\TaskService();
2457 'link' =>
$data[
'LINK'],
2458 'params' =>
$data[
'PARAMS']
2466 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2467 'USER_ID' =>
$arParams[
'USER_ID'] ??
null,
2470 'CALENDAR_DATE_FROM' =>
$arParams[
'CALENDAR_DATE_FROM'] ?
new DateTime(
$arParams[
'CALENDAR_DATE_FROM'], DateTimeInterface::RFC3339) :
null,
2471 'CALENDAR_DATE_TO' =>
$arParams[
'CALENDAR_DATE_TO'] ?
new DateTime(
$arParams[
'CALENDAR_DATE_TO'], DateTimeInterface::RFC3339) :
null,
2472 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
2473 'SEARCH_TITLE' =>
$arParams[
'SEARCH_TITLE'] ??
null,
2477 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC'
2479 if (!isset(
$filter[
'CHAT_ID']))
2481 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2487 if (!$chat->checkAccess()->isSuccess())
2489 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2492 $startId = $chat->getStartId();
2496 $filter[
'START_ID'] = $startId;
2501 return (
new RestAdapter($calendars))->toRestFormat();
2517 if (
$message->getMessageId() ===
null)
2519 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2532 throw new Bitrix\Rest\RestException(
'Message ID and chat ID can`t be empty together',
'CHAT_ID_MESSAGE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
2537 throw new \Bitrix\Rest\RestException(
'CALENDAR_ID can`t be empty',
'CALENDAR_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2540 if (!$chat->checkAccess()->isSuccess() || !$chat->canDo(\
Bitrix\Im\V2\Permission\Action::CreateMeeting))
2542 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2547 $startId = $chat->getStartId();
2551 throw new \Bitrix\Rest\RestException(
'You do not have access to this message', \
Bitrix\Im\V2\Message\MessageError::ACCESS_DENIED, \CRestServer::STATUS_FORBIDDEN);
2555 $chatId = $chat->getChatId();
2559 $calendarService = new \Bitrix\Im\V2\Link\Calendar\CalendarService();
2564 if (
$userId !== $calendar->getCreatedBy())
2566 throw new \Bitrix\Rest\RestException(
'You do not have access to this calendar event',
Bitrix\Im\V2\Entity\Calendar\CalendarError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2569 $saveResult = $calendarService->registerCalendar($chatId,
$messageId, $calendar);
2570 if (!$saveResult->isSuccess())
2572 $error = $saveResult->getErrors()[0];
2575 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2579 return $saveResult->isSuccess();
2588 throw new \Bitrix\Rest\RestException(
'LINK_ID can`t be empty',
'LINK_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2592 $calendar = new \Bitrix\Im\V2\Link\Calendar\CalendarItem($linkId);
2593 if ($calendar->getId() ===
null)
2595 throw new \Bitrix\Rest\RestException(
'Calendar event not found', \
Bitrix\Im\V2\Entity\Calendar\CalendarError::NOT_FOUND, \CRestServer::STATUS_NOT_FOUND);
2598 $chatId = $calendar->getChatId();
2601 if (!$chat->checkAccess()->isSuccess() || !$chat->canDo(\
Bitrix\Im\V2\Permission\Action::CreateMeeting))
2603 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2609 if (
$userId !== $calendar->getAuthorId() && !
$USER->IsAdmin())
2611 throw new \Bitrix\Rest\RestException(
'You do not have access to delete this calendar event', \
Bitrix\Im\V2\Entity\Calendar\CalendarError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2614 $deleteResult = (new \Bitrix\Im\V2\Link\Calendar\CalendarService())->unregisterCalendar($calendar);
2616 if (!$deleteResult->isSuccess())
2618 throw new \Bitrix\Rest\RestException(
'Failed to delete calendar event', \
Bitrix\Im\V2\Entity\Calendar\CalendarError::DELETE_ERROR, \CRestServer::STATUS_INTERNAL);
2627 if ($server->
getAuthType() !== \
Bitrix\Rest\SessionAuth\Auth::AUTH_TYPE && !self::isDebugEnabled())
2629 throw new \Bitrix\Rest\RestException(
'This method is available only with session auth type',
'WRONG_AUTH_TYPE', \CRestServer::STATUS_WRONG_REQUEST);
2641 if (
$message->getMessageId() ===
null)
2643 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2656 throw new Bitrix\Rest\RestException(
'Message ID and chat ID can`t be empty together',
'CHAT_ID_MESSAGE_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
2659 if (!$chat->checkAccess()->isSuccess())
2661 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2666 $startId = $chat->getStartId();
2670 throw new \Bitrix\Rest\RestException(
'You do not have access to this message', \
Bitrix\Im\V2\Message\MessageError::ACCESS_DENIED, \CRestServer::STATUS_FORBIDDEN);
2674 $calendarService = new \Bitrix\Im\V2\Link\Calendar\CalendarService();
2675 $result = $calendarService->prepareDataForCreateSlider($chat,
$message);
2695 'messageId' => 2345,
2698 'dateCreate' =>
'2022-08-22T12:37:10+02:00',
2701 'title' =>
'Important document #1',
2702 'status' =>
'signed',
2704 'company' =>
'Bitrix',
2712 'detail' =>
'https://...'
2718 'messageId' => 2346,
2721 'dateCreate' =>
'2022-08-24T12:37:10+02:00',
2724 'title' =>
'Important document #2',
2725 'status' =>
'signed',
2727 'company' =>
'Bitrix',
2735 'detail' =>
'https://...'
2748 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
2749 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2753 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC',
2755 if (!isset(
$filter[
'CHAT_ID']))
2757 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2763 if (!$chat->checkAccess()->isSuccess())
2765 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2768 $startId = $chat->getStartId();
2772 $filter[
'START_ID'] = $startId;
2785 throw new \Bitrix\Rest\RestException(
'MESSAGE_ID can`t be empty',
'MESSAGE_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2792 if (
$message->getMessageId() ===
null)
2794 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2799 if (!$chat->checkAccess()->isSuccess())
2801 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2806 throw new \Bitrix\Rest\RestException(
'You do not have access to this message', \
Bitrix\Im\V2\Message\MessageError::ACCESS_DENIED, \CRestServer::STATUS_FORBIDDEN);
2810 if (!$pinResult->isSuccess())
2812 $error = $pinResult->getErrors()[0];
2815 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2819 return $pinResult->isSuccess();
2827 throw new \Bitrix\Rest\RestException(
'MESSAGE_ID can`t be empty',
'MESSAGE_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2834 if (
$message->getMessageId() ===
null)
2836 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2841 if (!$chat->checkAccess()->isSuccess())
2843 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2847 if (!$unpinResult->isSuccess())
2849 $error = $unpinResult->getErrors()[0];
2852 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2856 return $unpinResult->isSuccess();
2863 'LAST_ID' =>
$arParams[
'LAST_ID'] ??
null,
2864 'SEARCH_MESSAGE' =>
$arParams[
'SEARCH_MESSAGE'] ??
null,
2865 'USER_ID' =>
$arParams[
'USER_ID'] ??
null,
2866 'CHAT_ID' =>
$arParams[
'CHAT_ID'] ??
null,
2872 $filter[
'IS_REMINDED'] =
true;
2876 $filter[
'IS_REMINDED'] =
false;
2880 'ID' =>
$arParams[
'ORDER'][
'ID'] ??
'DESC',
2882 if (!isset(
$filter[
'CHAT_ID']))
2884 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2890 if (!$chat->checkAccess()->isSuccess())
2892 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2897 return (
new RestAdapter($reminders))->toRestFormat();
2906 throw new \Bitrix\Rest\RestException(
'DATE_REMIND can`t be empty', \
Bitrix\Im\V2\Link\Reminder\ReminderError::DATE_REMIND_EMPTY, \CRestServer::STATUS_FORBIDDEN);
2909 $dateRemind =
new DateTime(
$arParams[
'DATE_REMIND'], DateTimeInterface::RFC3339);
2913 throw new \Bitrix\Rest\RestException(
'MESSAGE_ID can`t be empty',
'MESSAGE_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2920 if (
$message->getMessageId() ===
null)
2922 throw new \Bitrix\Rest\RestException(
'Message not found', \
Bitrix\Im\V2\Message\MessageError::MESSAGE_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2927 if (!$chat->checkAccess()->isSuccess())
2929 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
2934 throw new \Bitrix\Rest\RestException(
'You do not have access to this message', \
Bitrix\Im\V2\Message\MessageError::ACCESS_DENIED, \CRestServer::STATUS_FORBIDDEN);
2937 $addResult =
$message->addToReminder($dateRemind);
2938 if (!$addResult->isSuccess())
2940 $error = $addResult->getErrors()[0];
2943 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2947 return $addResult->isSuccess();
2955 throw new \Bitrix\Rest\RestException(
'REMINDER_ID can`t be empty',
'REMINDER_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
2958 $reminderId = (int)
$arParams[
'REMINDER_ID'];
2960 $reminder = new \Bitrix\Im\V2\Link\Reminder\ReminderItem($reminderId);
2964 throw new \Bitrix\Rest\RestException(
'Reminder not found', \
Bitrix\Im\V2\Link\Reminder\ReminderError::REMINDER_NOT_FOUND, \CRestServer::STATUS_WRONG_REQUEST);
2967 $deleteResult = (new \Bitrix\Im\V2\Link\Reminder\ReminderService())->deleteReminder(
$reminder);
2968 if (!$deleteResult->isSuccess())
2970 $error = $deleteResult->getErrors()[0];
2973 throw new \Bitrix\Rest\RestException(
$error->getMessage(),
$error->getCode(), \CRestServer::STATUS_WRONG_REQUEST);
2977 return $deleteResult->isSuccess();
2984 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
2987 $list = \Bitrix\Im\Bot::getListCache();
2988 foreach ($list as $botId => $botData)
2990 if ($botData[
'TYPE'] == \
Bitrix\Im\Bot::TYPE_NETWORK)
2995 'NAME' => \
Bitrix\Im\User::getInstance($botId)->getFullName(),
2996 'CODE' => $botData[
'CODE'],
2997 'OPENLINE' => $botData[
'OPENLINE'],
3013 && is_string(
$arParams[
'PLATFORM_CONTEXT'])
3017 \Bitrix\Im\Bot::setPlatformContext(
$arParams[
'PLATFORM_CONTEXT']);
3065 $arMessageFields = Array(
3067 "FROM_USER_ID" =>
$arParams[
'FROM_USER_ID'],
3080 CIMChat::GetGeneralChatId() ==
$arParams[
'CHAT_ID']
3081 && !CIMChat::CanSendMessageToGeneralChat(
$arParams[
'FROM_USER_ID'])
3087 if (!Chat::isActionAllowed(
'chat' .
$arParams[
'CHAT_ID'],
'SEND'))
3089 throw new Bitrix\Rest\RestException(
'It is forbidden to send messages to this chat',
'ACCESS_ERROR', CRestServer::STATUS_FORBIDDEN);
3097 $result = \Bitrix\Rest\AppTable::getList(
3105 'APP_NAME_DEFAULT' =>
'LANG_DEFAULT.MENU_NAME',
3110 $moduleName = !empty(
$result[
'APP_NAME'])
3112 : (!empty(
$result[
'APP_NAME_DEFAULT'])
3122 $arMessageFields = Array(
3124 "FROM_USER_ID" =>
$arParams[
'FROM_USER_ID'],
3125 "DIALOG_ID" =>
'chat'.
$arParams[
'CHAT_ID'],
3135 $arMessageFields[
"MESSAGE"] =
$arParams[
'MESSAGE'];
3138 $attach = CIMMessageParamAttach::GetAttachByJson(
$arParams[
'ATTACH']);
3141 if ($attach->IsAllowSize())
3143 $arMessageFields[
'ATTACH'] = $attach;
3147 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of attach",
"ATTACH_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
3157 $keyboard = Array();
3162 if (!isset(
$arParams[
'KEYBOARD'][
'BUTTONS']))
3164 $keyboard[
'BUTTONS'] =
$arParams[
'KEYBOARD'];
3170 $keyboard[
'BOT_ID'] =
$arParams[
'BOT_ID'];
3175 $arMessageFields[
'KEYBOARD'] = $keyboard;
3203 $arMessageFields[
'MENU'] = $menu;
3214 && \
Bitrix\Im\Dialog::hasAccess($arMessageFields[
'DIALOG_ID'])
3215 && !\
Bitrix\Im\User::getInstance()->isExtranet()
3218 $arMessageFields[
'SYSTEM'] =
'Y';
3223 $arMessageFields[
'URL_PREVIEW'] =
'N';
3225 if (isset(
$arParams[
'SKIP_CONNECTOR']) && mb_strtoupper(
$arParams[
'SKIP_CONNECTOR']) ==
'Y')
3227 $arMessageFields[
'SKIP_CONNECTOR'] =
'Y';
3228 $arMessageFields[
'SILENT_CONNECTOR'] =
'Y';
3232 $arMessageFields[
'TEMPLATE_ID'] = mb_substr((
string)
$arParams[
'TEMPLATE_ID'], 0, 255);
3237 if (!
$message->checkAccess()->isSuccess())
3241 if (
$message->getChat()->getDialogId() !== (
string)$arMessageFields[
'DIALOG_ID'])
3243 throw new Bitrix\Rest\RestException(
"You can only reply to a message within the same chat",
"REPLY_FROM_OTHER_CHAT_ERROR", CRestServer::STATUS_FORBIDDEN);
3245 $arMessageFields[
'PARAMS'][
'REPLY_ID'] =
$message->getId();
3248 $arMessageFields[
'WAIT_FULL_EXECUTION'] =
'N';
3250 $id = CIMMessenger::Add($arMessageFields);
3272 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3278 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
3291 && is_string(
$arParams[
'PLATFORM_CONTEXT'])
3295 \Bitrix\Im\Bot::setPlatformContext(
$arParams[
'PLATFORM_CONTEXT']);
3306 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3316 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
3321 CIMMessageParam::Set(
$arParams[
'ID'], Array(
'IS_EDITED' =>
$arParams[
'IS_EDITED'],
'ATTACH' => Array()));
3325 $attach = CIMMessageParamAttach::GetAttachByJson(
$arParams[
'ATTACH']);
3328 if ($attach->IsAllowSize())
3330 CIMMessageParam::Set(
$arParams[
'ID'], Array(
'IS_EDITED' =>
$arParams[
'IS_EDITED'],
'ATTACH' => $attach));
3334 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of attach",
"ATTACH_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
3352 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
3357 CIMMessageParam::Set(
$arParams[
'ID'], Array(
'KEYBOARD' =>
'N'));
3361 $keyboard = Array();
3366 if (!isset(
$arParams[
'KEYBOARD'][
'BUTTONS']))
3368 $keyboard[
'BUTTONS'] =
$arParams[
'KEYBOARD'];
3374 $keyboard[
'BOT_ID'] =
$arParams[
'BOT_ID'];
3379 if ($keyboard->isAllowSize())
3381 CIMMessageParam::Set(
$arParams[
'ID'], Array(
'KEYBOARD' => $keyboard));
3385 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of keyboard",
"KEYBOARD_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
3403 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
3408 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'MENU' =>
'N'));
3430 if ($menu->isAllowSize())
3432 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'MENU' => $menu));
3436 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of menu",
"MENU_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
3448 $urlPreview = isset(
$arParams[
'URL_PREVIEW']) &&
$arParams[
'URL_PREVIEW'] ==
"N"?
false:
true;
3453 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
3456 CIMMessageParam::SendPull(
$arParams[
'ID'], Array(
'KEYBOARD',
'ATTACH',
'MENU'));
3473 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3477 if (!in_array(
$arParams[
'ACTION'], Array(
'auto',
'plus',
'minus')))
3485 throw new Bitrix\Rest\RestException(
"Action completed without changes",
"WITHOUT_CHANGES", CRestServer::STATUS_WRONG_REQUEST);
3503 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3539 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3549 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
3555 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3573 && !self::isDebugEnabled()
3576 throw new \Bitrix\Rest\RestException(
"Access for this method allowed only by OAuth authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_WRONG_REQUEST);
3609 || \
Bitrix\Main\Loader::includeModule(
'bitrix24') && CBitrix24::IsPortalAdmin(
$userId)
3613 $forUser = intval(
$arParams[
'USER_ID']);
3618 throw new Bitrix\Rest\RestException(
"You don't have access to this user",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3622 return \Bitrix\Im\User::getMessages($forUser,
$options);
3631 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
3646 if ($server->
getMethod() ==
"im.notify.personal.add")
3650 else if ($server->
getMethod() ==
"im.notify.system.add")
3654 else if (!isset(
$arParams[
'TYPE']) || !in_array(
$arParams[
'TYPE'], Array(
'USER',
'SYSTEM')))
3685 $moduleName = !empty(
$result[
'APP_NAME'])
3687 : (!empty(
$result[
'APP_NAME_DEFAULT'])
3696 $messageOut = $moduleName.
"#BR#".
$arParams[
'MESSAGE_OUT'];
3706 $fromUserId =
$USER->GetID();
3715 $arMessageFields =
array(
3717 "FROM_USER_ID" => $fromUserId,
3718 "NOTIFY_TYPE" => $notifyType,
3719 "NOTIFY_MODULE" =>
"rest",
3720 "NOTIFY_EVENT" =>
"rest_notify",
3722 "NOTIFY_MESSAGE_OUT" => $messageOut,
3730 $appKey = mb_substr(md5($server->
getClientId()), 0, 5);
3731 $arMessageFields[
'NOTIFY_TAG'] =
'MP|'.$appKey.
'|'.
$arParams[
'TAG'];
3735 $appKey = mb_substr(md5($server->
getClientId()), 0, 5);
3736 $arMessageFields[
'NOTIFY_SUB_TAG'] =
'MP|'.$appKey.
'|'.
$arParams[
'SUB_TAG'];
3740 $attach = CIMMessageParamAttach::GetAttachByJson(
$arParams[
'ATTACH']);
3743 if ($attach->IsAllowSize())
3745 $arMessageFields[
'ATTACH'] = $attach;
3749 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of attach",
"ATTACH_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
3757 return CIMNotify::Add($arMessageFields);
3770 "Parameters LAST_ID and LAST_TYPE should be used together.",
3771 "LAST_ID_AND_LAST_TYPE",
3772 CRestServer::STATUS_WRONG_REQUEST
3778 if (!preg_match(
'/^\d+$/',
$arParams[
'LAST_ID']))
3781 "Last notification ID can't be string",
3783 CRestServer::STATUS_WRONG_REQUEST
3812 return $CIMNotify->DeleteWithCheck(
$arParams[
'ID']);
3825 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
3829 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
3835 $appKey = mb_substr(md5(
$clientId), 0, 5);
3840 $appKey = mb_substr(md5(
$clientId), 0, 5);
3841 $result = CIMNotify::DeleteBySubTag(
'MP|'.$appKey.
'|'.
$arParams[
'SUB_TAG']);
3864 $onlyCurrent =
$arParams[
'ONLY_CURRENT'] ??
null;
3865 $readAllFromId = $onlyCurrent !==
'Y';
3868 $CIMNotify->MarkNotifyRead(
$arParams[
'ID'], $readAllFromId);
3872 $CIMNotify->MarkNotifyUnRead(
$arParams[
'ID'], $readAllFromId);
3890 throw new Bitrix\Rest\RestException(
"No IDS param or it is not an array",
"PARAMS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3894 foreach (
$arParams[
'IDS'] as $notificationId)
3896 $notificationId = (int)$notificationId;
3897 if ($notificationId <= 0)
3904 $CIMNotify->MarkNotifyRead($notificationId);
3908 $CIMNotify->MarkNotifyUnRead($notificationId);
3917 $notify = new \CIMNotify();
3918 $notify->MarkNotifyRead(0,
true);
3944 throw new Bitrix\Rest\RestException(
"Notification Value can't be empty",
"NOTIFY_VALUE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3976 throw new Bitrix\Rest\RestException(
"ANSWER_TEXT can't be empty",
"ANSWER_TEXT_ERROR", CRestServer::STATUS_WRONG_REQUEST);
3994 && mb_strlen(trim(
$arParams[
'SEARCH_TEXT'])) < 3
3997 throw new Bitrix\Rest\RestException(
"SEARCH_TEXT can't be less then 3 symbols",
"SEARCH_TEXT_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4014 if (!preg_match(
'/^\d+$/',
$arParams[
'LAST_ID']))
4017 "Last notification ID can't be string",
4019 CRestServer::STATUS_WRONG_REQUEST
4038 $notify = new \Bitrix\Im\Notify(
$options);
4040 return $notify->search();
4047 foreach ($schema as
$moduleId => $notifyTypes)
4050 foreach ($notifyTypes[
'NOTIFY'] as $notifyId => $notify)
4054 'NAME' => $notify[
'NAME']
4058 if ($notifyTypes[
'NAME'] ===
'')
4060 $module = CModule::CreateModuleObject(
$moduleId);
4061 $moduleName = $module->MODULE_NAME;
4065 $moduleName = $notifyTypes[
'NAME'];
4069 'NAME' => $moduleName,
4075 return $schemaResult;
4086 throw new \Bitrix\Rest\RestException(
'CHAT_ID can`t be empty',
'CHAT_ID_EMPTY', \CRestServer::STATUS_WRONG_REQUEST);
4092 if (!$chat->checkAccess()->isSuccess())
4094 throw new \Bitrix\Rest\RestException(
'You do not have access to this chat',
Bitrix\Im\V2\Rest\RestError::ACCESS_ERROR, \CRestServer::STATUS_FORBIDDEN);
4097 $files = (new \Bitrix\Im\V2\Link\File\FileService())->getFilesBeforeMigrationFinished($chatId, $limit,
$lastId,
$fileName);
4115 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
4121 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4133 if (!\
Bitrix\Im\Dialog::hasAccess(
'chat'.$chatId))
4135 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
4146 'ID' => (
int)$folderModel->getId()
4183 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4187 CIMChat::GetGeneralChatId() == $chatId
4188 && !CIMChat::CanSendMessageToGeneralChat()
4201 foreach (
$arParams[
'FILE_ID'] as $fileId)
4203 $files[$fileId] =
'disk'.$fileId;
4212 foreach (
$arParams[
'DISK_ID'] as $fileId)
4214 $files[$fileId] =
'disk'.$fileId;
4228 foreach (
$arParams[
'UPLOAD_ID'] as $fileId)
4230 $files[$fileId] =
'upload'.$fileId;
4236 throw new Bitrix\Rest\RestException(
"List of files in not specified",
"FILES_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4246 $arParams[
'FILE_TEMPLATE_ID'] = mb_substr((
string)
$arParams[
'FILE_TEMPLATE_ID'], 0, 255);
4250 'LINES_SILENT_MODE' =>
$arParams[
'SILENT_MODE'],
4251 'TEMPLATE_ID' =>
$arParams[
'TEMPLATE_ID']?:
'',
4252 'FILE_TEMPLATE_ID' =>
$arParams[
'FILE_TEMPLATE_ID']?:
'',
4253 'SYMLINK' =>
$arParams[
'SYMLINK']?:
false,
4254 'AS_FILE' =>
$arParams[
'AS_FILE'] ??
'N',
4255 'WAIT_FULL_EXECUTION' =>
'N',
4259 throw new Bitrix\Rest\RestException(
"Error during saving file to chat",
"SAVE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4270 if (!\
Bitrix\Im\Common::isDialogId($dialogId))
4275 if (!\
Bitrix\Im\Dialog::hasAccess($dialogId))
4277 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4339 'id' => (int)
$result[
'FOLDER']->getId(),
4340 'name' =>
$result[
'FOLDER']->getName()
4343 'id' => (int)
$result[
'FILE']->getId(),
4344 'name' =>
$result[
'FILE']->getName()
4353 $onlyCounterParam =
$arParams[
'ONLY_COUNTER'] ??
null;
4356 if ($onlyCounterParam)
4361 if ($jsonParam ===
'Y')
4380 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
4385 $customClientId =
false;
4391 $customClientId =
true;
4392 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
4396 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
4400 if ($customClientId)
4402 $arApp = [
'ID' =>
'',
'CLIENT_ID' =>
$arParams[
'CLIENT_ID']];
4407 $arApp =
$dbRes->fetch();
4417 if ($customClientId)
4432 throw new Bitrix\Rest\RestException(
"Handler for \"Message add\" event isn't specified",
"EVENT_MESSAGE_ADD_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4435 if (isset(
$arParams[
'EVENT_MESSAGE_UPDATE']) && !empty(
$arParams[
'EVENT_MESSAGE_UPDATE']))
4437 if ($customClientId)
4439 $arParams[
'EVENT_MESSAGE_UPDATE'] =
$arParams[
'EVENT_MESSAGE_UPDATE'].(mb_strpos(
$arParams[
'EVENT_MESSAGE_UPDATE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4451 if (isset(
$arParams[
'EVENT_MESSAGE_DELETE']) && !empty(
$arParams[
'EVENT_MESSAGE_DELETE']))
4453 if ($customClientId)
4455 $arParams[
'EVENT_MESSAGE_DELETE'] =
$arParams[
'EVENT_MESSAGE_DELETE'].(mb_strpos(
$arParams[
'EVENT_MESSAGE_DELETE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4469 if ($customClientId)
4471 $arParams[
'EVENT_CONTEXT_GET'] .= (mb_strpos(
$arParams[
'EVENT_CONTEXT_GET'],
'?') ===
false ?
'?' :
'&') .
'CLIENT_ID=' .
$arParams[
'CLIENT_ID'];
4483 if (isset(
$arParams[
'EVENT_WELCOME_MESSAGE']) && !empty(
$arParams[
'EVENT_WELCOME_MESSAGE']))
4485 if ($customClientId)
4487 $arParams[
'EVENT_WELCOME_MESSAGE'] =
$arParams[
'EVENT_WELCOME_MESSAGE'].(mb_strpos(
$arParams[
'EVENT_WELCOME_MESSAGE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4495 throw new Bitrix\Rest\RestException($e->getMessage(),
"EVENT_WELCOME_MESSAGE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4500 throw new Bitrix\Rest\RestException(
"Handler for \"Welcome message\" event isn't specified",
"EVENT_WELCOME_MESSAGE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4505 if ($customClientId)
4520 throw new Bitrix\Rest\RestException(
"Handler for \"Bot delete\" event isn't specified",
"EVENT_BOT_DELETE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4528 if (CModule::IncludeModule(
'bitrix24'))
4531 $restRegisterLimit = \Bitrix\Bitrix24\Feature::getVariable(
'imbot_rest_register_limit')?: 5;
4533 if (
$counter >= $restRegisterLimit)
4535 throw new Bitrix\Rest\RestException(
"Has reached the maximum number of bots for application (max: $restRegisterLimit)",
"MAX_COUNT_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4544 unset(
$arParams[
'EVENT_MESSAGE_UPDATE']);
4545 unset(
$arParams[
'EVENT_MESSAGE_DELETE']);
4548 $properties = Array();
4549 if (isset(
$arParams[
'PROPERTIES'][
'NAME']))
4551 $properties[
'NAME'] =
$arParams[
'PROPERTIES'][
'NAME'];
4553 if (isset(
$arParams[
'PROPERTIES'][
'LAST_NAME']))
4555 $properties[
'LAST_NAME'] =
$arParams[
'PROPERTIES'][
'LAST_NAME'];
4557 if (!(isset($properties[
'NAME']) || isset($properties[
'LAST_NAME'])))
4562 if (isset(
$arParams[
'PROPERTIES'][
'COLOR']))
4564 $properties[
'COLOR'] =
$arParams[
'PROPERTIES'][
'COLOR'];
4566 if (isset(
$arParams[
'PROPERTIES'][
'EMAIL']))
4568 $properties[
'EMAIL'] =
$arParams[
'PROPERTIES'][
'EMAIL'];
4570 if (isset(
$arParams[
'PROPERTIES'][
'PERSONAL_BIRTHDAY']))
4572 $birthday = new \Bitrix\Main\Type\DateTime(
$arParams[
'PROPERTIES'][
'PERSONAL_BIRTHDAY'].
' 19:45:00',
'Y-m-d H:i:s');
4573 $birthday = $birthday->format(\
Bitrix\Main\Type\Date::convertFormatToPhp(\CSite::GetDateFormat(
'SHORT')));
4575 $properties[
'PERSONAL_BIRTHDAY'] = $birthday;
4577 if (isset(
$arParams[
'PROPERTIES'][
'WORK_POSITION']))
4579 $properties[
'WORK_POSITION'] =
$arParams[
'PROPERTIES'][
'WORK_POSITION'];
4581 if (isset(
$arParams[
'PROPERTIES'][
'PERSONAL_WWW']))
4583 $properties[
'PERSONAL_WWW'] =
$arParams[
'PROPERTIES'][
'PERSONAL_WWW'];
4585 if (isset(
$arParams[
'PROPERTIES'][
'PERSONAL_GENDER']))
4587 $properties[
'PERSONAL_GENDER'] =
$arParams[
'PROPERTIES'][
'PERSONAL_GENDER'];
4589 if (isset(
$arParams[
'PROPERTIES'][
'PERSONAL_PHOTO']))
4591 $avatar = \CRestUtil::saveFile(
$arParams[
'PROPERTIES'][
'PERSONAL_PHOTO'],
$arParams[
'CODE'].
'.png');
4592 $imageCheck = (new \Bitrix\Main\File\Image($avatar[
"tmp_name"]))->getInfo();
4595 || !$imageCheck->getWidth()
4596 || $imageCheck->getWidth() > 5000
4597 || !$imageCheck->getHeight()
4598 || $imageCheck->getHeight() > 5000
4604 if (isset($avatar) && mb_strpos($avatar[
'type'],
"image/") === 0)
4606 $avatar[
'MODULE_ID'] =
'imbot';
4607 $properties[
'PERSONAL_PHOTO'] = $avatar;
4611 $botId = \Bitrix\Im\Bot::register(Array(
4616 'MODULE_ID' =>
'rest',
4617 'PROPERTIES' => $properties
4621 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageAdd',
'OnImBotMessageAdd',
true);
4622 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageAdd',
'OnImBotMessageAdd',
$arParams[
'EVENT_MESSAGE_ADD']);
4626 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageUpdate',
'OnImBotMessageUpdate',
true);
4627 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageUpdate',
'OnImBotMessageUpdate',
$arParams[
'EVENT_MESSAGE_UPDATE']);
4632 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageDelete',
'OnImBotMessageDelete',
true);
4633 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageDelete',
'OnImBotMessageDelete',
$arParams[
'EVENT_MESSAGE_DELETE']);
4638 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotContextGet',
'OnImBotContextGet',
true);
4639 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotContextGet',
'OnImBotContextGet',
$arParams[
'EVENT_CONTEXT_GET']);
4642 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotJoinChat',
'OnImBotJoinChat',
true);
4643 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotJoinChat',
'OnImBotJoinChat',
$arParams[
'EVENT_WELCOME_MESSAGE']);
4645 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotDelete',
'OnImBotDelete',
true);
4646 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotDelete',
'OnImBotDelete',
$arParams[
'EVENT_BOT_DELETE']);
4660 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
4665 $customClientId =
false;
4671 $customClientId =
true;
4672 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
4676 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
4680 $bots = \Bitrix\Im\Bot::getListCache();
4687 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4690 $result = \Bitrix\Im\Bot::unRegister(Array(
'BOT_ID' =>
$arParams[
'BOT_ID']));
4696 if ($customClientId)
4698 self::unbindEvent(
"",
$arParams[
'CLIENT_ID'],
'im',
'onImBotMessageAdd',
'OnImBotMessageAdd',
true);
4699 self::unbindEvent(
"",
$arParams[
'CLIENT_ID'],
'im',
'onImBotMessageUpdate',
'OnImBotMessageUpdate',
true);
4700 self::unbindEvent(
"",
$arParams[
'CLIENT_ID'],
'im',
'onImBotMessageDelete',
'OnImBotMessageDelete',
true);
4701 self::unbindEvent(
"",
$arParams[
'CLIENT_ID'],
'im',
'onImBotJoinChat',
'OnImBotJoinChat',
true);
4702 self::unbindEvent(
"",
$arParams[
'CLIENT_ID'],
'im',
'onImBotDelete',
'OnImBotDelete',
true);
4703 self::unbindEvent(
"",
$arParams[
'CLIENT_ID'],
'im',
'onImBotContextGet',
'OnImBotContextGet',
true);
4713 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
4718 $customClientId =
false;
4723 $customClientId =
true;
4724 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
4728 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
4732 $bots = \Bitrix\Im\Bot::getListCache();
4739 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4742 if ($customClientId)
4744 $arApp = [
'ID' =>
'',
'CLIENT_ID' =>
$arParams[
'CLIENT_ID']];
4749 $arApp =
$dbRes->fetch();
4752 $updateEvents = Array();
4754 if (isset(
$arParams[
'FIELDS'][
'EVENT_HANDLER']) && !empty(
$arParams[
'FIELDS'][
'EVENT_HANDLER']))
4759 if (isset(
$arParams[
'FIELDS'][
'EVENT_MESSAGE_ADD']) && !empty(
$arParams[
'FIELDS'][
'EVENT_MESSAGE_ADD']))
4761 $updateEvents[
'EVENT_MESSAGE_ADD'] =
$arParams[
'FIELDS'][
'EVENT_MESSAGE_ADD'];
4762 if ($customClientId)
4764 $updateEvents[
'EVENT_MESSAGE_ADD'] = $updateEvents[
'EVENT_MESSAGE_ADD'].(mb_strpos($updateEvents[
'EVENT_MESSAGE_ADD'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4776 if (isset(
$arParams[
'FIELDS'][
'EVENT_MESSAGE_UPDATE']) && !empty(
$arParams[
'FIELDS'][
'EVENT_MESSAGE_UPDATE']))
4778 $updateEvents[
'EVENT_MESSAGE_UPDATE'] =
$arParams[
'FIELDS'][
'EVENT_MESSAGE_UPDATE'];
4779 if ($customClientId)
4781 $updateEvents[
'EVENT_MESSAGE_UPDATE'] = $updateEvents[
'EVENT_MESSAGE_UPDATE'].(mb_strpos($updateEvents[
'EVENT_MESSAGE_UPDATE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4793 if (isset(
$arParams[
'FIELDS'][
'EVENT_MESSAGE_DELETE']) && !empty(
$arParams[
'FIELDS'][
'EVENT_MESSAGE_DELETE']))
4795 $updateEvents[
'EVENT_MESSAGE_DELETE'] =
$arParams[
'FIELDS'][
'EVENT_MESSAGE_DELETE'];
4796 if ($customClientId)
4798 $updateEvents[
'EVENT_MESSAGE_DELETE'] = $updateEvents[
'EVENT_MESSAGE_DELETE'].(mb_strpos($updateEvents[
'EVENT_MESSAGE_DELETE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4810 if (!empty(
$arParams[
'FIELDS'][
'EVENT_CONTEXT_GET']))
4812 $updateEvents[
'EVENT_CONTEXT_GET'] =
$arParams[
'FIELDS'][
'EVENT_CONTEXT_GET'];
4813 if ($customClientId)
4815 $updateEvents[
'EVENT_CONTEXT_GET'] .= (mb_strpos($updateEvents[
'EVENT_CONTEXT_GET'],
'?') ===
false ?
'?' :
'&') .
'CLIENT_ID=' .
$arParams[
'CLIENT_ID'];
4827 if (isset(
$arParams[
'FIELDS'][
'EVENT_WELCOME_MESSAGE']) && !empty(
$arParams[
'FIELDS'][
'EVENT_WELCOME_MESSAGE']))
4829 $updateEvents[
'EVENT_WELCOME_MESSAGE'] =
$arParams[
'FIELDS'][
'EVENT_WELCOME_MESSAGE'];
4830 if ($customClientId)
4832 $updateEvents[
'EVENT_WELCOME_MESSAGE'] = $updateEvents[
'EVENT_WELCOME_MESSAGE'].(mb_strpos($updateEvents[
'EVENT_WELCOME_MESSAGE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4840 throw new Bitrix\Rest\RestException($e->getMessage(),
"EVENT_WELCOME_MESSAGE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
4844 if (isset(
$arParams[
'FIELDS'][
'EVENT_BOT_DELETE']) && !empty(
$arParams[
'FIELDS'][
'EVENT_BOT_DELETE']))
4846 $updateEvents[
'EVENT_BOT_DELETE'] =
$arParams[
'FIELDS'][
'EVENT_BOT_DELETE'];
4847 if ($customClientId)
4849 $updateEvents[
'EVENT_BOT_DELETE'] = $updateEvents[
'EVENT_BOT_DELETE'].(mb_strpos($updateEvents[
'EVENT_BOT_DELETE'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
4861 $updateFields = Array();
4865 $updateFields[
'CODE'] =
$arParams[
'FIELDS'][
'CODE'];
4868 if (isset(
$arParams[
'FIELDS'][
'TYPE']) && !empty(
$arParams[
'FIELDS'][
'TYPE']) && in_array(
$arParams[
'TYPE'], Array(
'O',
'B',
'H')))
4870 $updateFields[
'TYPE'] =
$arParams[
'FIELDS'][
'TYPE'];
4873 if (isset(
$arParams[
'FIELDS'][
'OPENLINE']) && !empty(
$arParams[
'FIELDS'][
'OPENLINE']))
4875 $updateFields[
'OPENLINE'] =
$arParams[
'FIELDS'][
'OPENLINE'];
4878 $properties = Array();
4879 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'NAME']))
4881 $properties[
'NAME'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'NAME'];
4883 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'LAST_NAME']))
4885 $properties[
'LAST_NAME'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'LAST_NAME'];
4888 if (isset($properties[
'NAME']) && empty($properties[
'NAME']) && isset($properties[
'LAST_NAME']) && empty($properties[
'LAST_NAME']))
4893 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'COLOR']))
4895 $properties[
'COLOR'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'COLOR'];
4897 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'EMAIL']))
4899 $properties[
'EMAIL'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'EMAIL'];
4901 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_BIRTHDAY']))
4903 $birthday = new \Bitrix\Main\Type\DateTime(
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_BIRTHDAY'].
' 19:45:00',
'Y-m-d H:i:s');
4904 $birthday = $birthday->format(\
Bitrix\Main\Type\Date::convertFormatToPhp(\CSite::GetDateFormat(
'SHORT')));
4906 $properties[
'PERSONAL_BIRTHDAY'] = $birthday;
4908 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'WORK_POSITION']))
4910 $properties[
'WORK_POSITION'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'WORK_POSITION'];
4912 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_WWW']))
4914 $properties[
'PERSONAL_WWW'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_WWW'];
4916 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_GENDER']))
4918 $properties[
'PERSONAL_GENDER'] =
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_GENDER'];
4920 if (isset(
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_PHOTO']))
4922 $avatar = \CRestUtil::saveFile(
$arParams[
'FIELDS'][
'PROPERTIES'][
'PERSONAL_PHOTO'], $bots[
$arParams[
'BOT_ID']][
'CODE'].
'.png');
4923 $imageCheck = (new \Bitrix\Main\File\Image($avatar[
"tmp_name"]))->getInfo();
4926 || !$imageCheck->getWidth()
4927 || $imageCheck->getWidth() > 5000
4928 || !$imageCheck->getHeight()
4929 || $imageCheck->getHeight() > 5000
4935 if ($avatar && mb_strpos($avatar[
'type'],
"image/") === 0)
4937 $avatar[
'MODULE_ID'] =
'imbot';
4938 $properties[
'PERSONAL_PHOTO'] = $avatar;
4942 if (!empty($properties))
4944 $updateFields[
'PROPERTIES'] = $properties;
4947 if (empty($updateFields))
4949 if (empty($updateEvents))
4951 throw new Bitrix\Rest\RestException(
"Update fields can't be empty",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
4956 $result = \Bitrix\Im\Bot::update(Array(
'BOT_ID' =>
$arParams[
'BOT_ID']), $updateFields);
4963 if (isset($updateEvents[
'EVENT_MESSAGE_ADD']))
4965 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageAdd',
'OnImBotMessageAdd',
true);
4966 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageAdd',
'OnImBotMessageAdd', $updateEvents[
'EVENT_MESSAGE_ADD']);
4968 if (isset($updateEvents[
'EVENT_MESSAGE_UPDATE']))
4970 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageUpdate',
'OnImBotMessageUpdate',
true);
4971 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageUpdate',
'OnImBotMessageUpdate', $updateEvents[
'EVENT_MESSAGE_UPDATE']);
4973 if (isset($updateEvents[
'EVENT_MESSAGE_DELETE']))
4975 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageDelete',
'OnImBotMessageDelete',
true);
4976 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotMessageDelete',
'OnImBotMessageDelete', $updateEvents[
'EVENT_MESSAGE_DELETE']);
4978 if (isset($updateEvents[
'EVENT_WELCOME_MESSAGE']))
4980 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotJoinChat',
'OnImBotJoinChat',
true);
4981 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotJoinChat',
'OnImBotJoinChat', $updateEvents[
'EVENT_WELCOME_MESSAGE']);
4983 if (isset($updateEvents[
'EVENT_BOT_DELETE']))
4985 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotDelete',
'OnImBotDelete',
true);
4986 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotDelete',
'OnImBotDelete', $updateEvents[
'EVENT_BOT_DELETE']);
4988 if (isset($updateEvents[
'EVENT_CONTEXT_GET']))
4990 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotContextGet',
'OnImBotContextGet',
true);
4991 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImBotContextGet',
'OnImBotContextGet', $updateEvents[
'EVENT_CONTEXT_GET']);
5006 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
5010 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
5014 $bots = \Bitrix\Im\Bot::getListCache();
5023 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5029 foreach ($bots as $bot)
5044 $arMessageFields = Array();
5049 $arMessageFields[
'FROM_USER_ID'] = intval(
$arParams[
'FROM_USER_ID']);
5050 $arMessageFields[
'TO_USER_ID'] = intval(
$arParams[
'TO_USER_ID']);
5054 $arMessageFields[
'DIALOG_ID'] =
$arParams[
'DIALOG_ID'];
5055 if (!\
Bitrix\Im\Common::isDialogId($arMessageFields[
'DIALOG_ID']))
5061 $arMessageFields[
'MESSAGE'] = isset(
$arParams[
'MESSAGE']) && is_string(
$arParams[
'MESSAGE'])
5065 if ($arMessageFields[
'MESSAGE'] ==
'')
5072 $attach = CIMMessageParamAttach::GetAttachByJson(
$arParams[
'ATTACH']);
5075 if ($attach->IsAllowSize())
5077 $arMessageFields[
'ATTACH'] = $attach;
5081 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of attach",
"ATTACH_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
5092 $keyboard = Array();
5097 if (!isset(
$arParams[
'KEYBOARD'][
'BUTTONS']))
5099 $keyboard[
'BUTTONS'] =
$arParams[
'KEYBOARD'];
5105 $keyboard[
'BOT_ID'] =
$arParams[
'BOT_ID'];
5110 $arMessageFields[
'KEYBOARD'] = $keyboard;
5138 $arMessageFields[
'MENU'] = $menu;
5148 $arMessageFields[
'SYSTEM'] =
'Y';
5153 $arMessageFields[
'URL_PREVIEW'] =
'N';
5156 if (isset(
$arParams[
'SKIP_CONNECTOR']) && mb_strtoupper(
$arParams[
'SKIP_CONNECTOR']) ==
'Y')
5158 $arMessageFields[
'SKIP_CONNECTOR'] =
'Y';
5159 $arMessageFields[
'SILENT_CONNECTOR'] =
'Y';
5162 $id = \Bitrix\Im\Bot::addMessage(
array(
'BOT_ID' =>
$arParams[
'BOT_ID']), $arMessageFields);
5181 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
5185 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
5189 $bots = \Bitrix\Im\Bot::getListCache();
5198 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5204 foreach ($bots as $bot)
5222 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5231 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
5236 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'ATTACH' => Array()));
5240 $attach = CIMMessageParamAttach::GetAttachByJson(
$arParams[
'ATTACH']);
5243 if ($attach->IsAllowSize())
5245 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'ATTACH' => $attach));
5249 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of attach",
"ATTACH_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
5268 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
5273 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'KEYBOARD' =>
'N'));
5277 $keyboard = Array();
5282 if (!isset(
$arParams[
'KEYBOARD'][
'BUTTONS']))
5284 $keyboard[
'BUTTONS'] =
$arParams[
'KEYBOARD'];
5290 $keyboard[
'BOT_ID'] =
$arParams[
'BOT_ID'];
5295 if ($keyboard->isAllowSize())
5297 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'KEYBOARD' => $keyboard));
5301 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of keyboard",
"KEYBOARD_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
5319 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
5324 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'MENU' =>
'N'));
5346 if ($menu->isAllowSize())
5348 CIMMessageParam::Set(
$arParams[
'MESSAGE_ID'], Array(
'MENU' => $menu));
5352 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of menu",
"MENU_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
5364 $urlPreview = isset(
$arParams[
'URL_PREVIEW']) &&
$arParams[
'URL_PREVIEW'] ==
"N"?
false:
true;
5365 $skipConnector = isset(
$arParams[
'SKIP_CONNECTOR']) && mb_strtoupper(
$arParams[
'SKIP_CONNECTOR']) ==
"Y"?
true:
false;
5370 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
5374 CIMMessageParam::SendPull(
$arParams[
'MESSAGE_ID'], Array(
'KEYBOARD',
'ATTACH',
'MENU'));
5388 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
5392 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
5396 $bots = \Bitrix\Im\Bot::getListCache();
5405 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5411 foreach ($bots as $bot)
5429 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5435 throw new Bitrix\Rest\RestException(
"Time has expired for modification or you don't have access",
"CANT_EDIT_MESSAGE", CRestServer::STATUS_FORBIDDEN);
5450 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
5454 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
5458 $bots = \Bitrix\Im\Bot::getListCache();
5467 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5473 foreach ($bots as $bot)
5491 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5495 if (!in_array(
$arParams[
'ACTION'], Array(
'auto',
'plus',
'minus')))
5503 throw new Bitrix\Rest\RestException(
"Action completed without changes",
"WITHOUT_CHANGES", CRestServer::STATUS_WRONG_REQUEST);
5518 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
5522 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
5526 $bots = \Bitrix\Im\Bot::getListCache();
5535 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5541 foreach ($bots as $bot)
5561 \Bitrix\Im\Bot::startWriting(Array(
'BOT_ID' =>
$arParams[
'BOT_ID']),
$arParams[
'DIALOG_ID']);
5589 if (!isset(
$arParams[
'TEXT_FIELD_ENABLED']))
5591 throw new Bitrix\Rest\RestException(
" text field enabled can't be empty",
"TEXT_FIELD_ENABLED_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
5596 $botId = self::getBotId(
$arParams, $server);
5599 if (!$chat->withContextUser((
int)$botId)->checkAccess()->isSuccess())
5601 throw new Bitrix\Rest\RestException(
"Bot don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
5604 (new \Bitrix\Im\V2\Chat\TextField\TextFieldEnabled($chat->getChatId()))->
set(
$arParams[
'TEXT_FIELD_ENABLED']);
5615 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
5625 throw new Bitrix\Rest\RestException(
"You do not have access to the specified dialog",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
5637 throw new Bitrix\Rest\RestException(
"Action completed without changes",
"WITHOUT_CHANGES", CRestServer::STATUS_WRONG_REQUEST);
5647 if (!$arHandler[
'APP_CODE'])
5649 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
5650 parse_str($parts[
'query'],
$query);
5655 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
5659 if (!$arHandler[
'APP_CODE'])
5661 throw new Exception(
'Event is intended for another application');
5664 $bot = \Bitrix\Im\Bot::getListCache();
5666 $commandId = Array();
5669 if ($commandData[
'APP_ID'] == $arHandler[
'APP_CODE'] && $commandData[
'BOT_ID'] > 0)
5671 $sendBotData = self::getAccessToken($arHandler[
'APP_ID'], $commandData[
'BOT_ID']);
5672 $sendBotData[
'AUTH'] = $sendBotData;
5673 $sendBotData[
'BOT_ID'] = $commandData[
'BOT_ID'];
5674 $sendBotData[
'BOT_CODE'] = $bot[$commandData[
'BOT_ID']][
'CODE'];
5675 $sendBotData[
'COMMAND'] = $commandData[
'COMMAND'];
5676 $sendBotData[
'COMMAND_ID'] = $commandData[
'ID'];
5677 $sendBotData[
'COMMAND_PARAMS'] = $commandData[
'EXEC_PARAMS'];
5678 $sendBotData[
'COMMAND_CONTEXT'] = $commandData[
'CONTEXT'];
5679 $sendBotData[
'MESSAGE_ID'] =
$arParams[1];
5680 $commandId[$sendBotData[
'COMMAND_ID']] = $sendBotData;
5681 if ($commandData[
'CONTEXT'] !=
'KEYBOARD')
5685 $arParams[2][
'FROM_USER_ID'] == $commandData[
'BOT_ID'] ||
5686 $arParams[2][
'TO_USER_ID'] == $commandData[
'BOT_ID']
5689 \Bitrix\Im\Bot::startWriting(Array(
'BOT_ID' => $commandData[
'BOT_ID']),
$arParams[2][
'DIALOG_ID']);
5694 if (empty($commandId))
5696 throw new Exception(
'Event is intended for another application');
5700 $arParams[2][
'LANGUAGE'] = \Bitrix\Im\Bot::getDefaultLanguage();
5707 'ID' => $fromUser[
'id'],
5708 'NAME' => $fromUser[
'name'],
5709 'FIRST_NAME' => $fromUser[
'first_name'],
5710 'LAST_NAME' => $fromUser[
'last_name'],
5711 'WORK_POSITION' => $fromUser[
'work_position'],
5712 'GENDER' => $fromUser[
'gender'],
5721 'COMMAND' => $commandId,
5731 if (!$arHandler[
'APP_CODE'])
5733 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
5734 parse_str($parts[
'query'],
$query);
5739 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
5743 if (!$arHandler[
'APP_CODE'])
5745 throw new Exception(
'Event is intended for another application');
5751 if ($botData[
'APP_ID'] == $arHandler[
'APP_CODE'])
5753 $sendBotData = self::getAccessToken($arHandler[
'APP_ID'], $botData[
'BOT_ID']);
5754 $sendBotData[
'AUTH'] = $sendBotData;
5755 $sendBotData[
'BOT_ID'] = $botData[
'BOT_ID'];
5756 $sendBotData[
'BOT_CODE'] = $botData[
'CODE'];
5757 $bots[$botData[
'BOT_ID']] = $sendBotData;
5759 if (
$arParams[2][
'CHAT_ENTITY_TYPE'] !=
'LINES' && $botData[
'TYPE'] != \
Bitrix\Im\Bot::TYPE_SUPERVISOR)
5761 \Bitrix\Im\Bot::startWriting(Array(
'BOT_ID' => $botData[
'BOT_ID']),
$arParams[2][
'DIALOG_ID']);
5768 throw new Exception(
'Event is intended for another application');
5772 $arParams[2][
'LANGUAGE'] = \Bitrix\Im\Bot::getDefaultLanguage();
5779 'ID' => $fromUser[
'id'],
5780 'NAME' => $fromUser[
'name'],
5781 'FIRST_NAME' => $fromUser[
'first_name'],
5782 'LAST_NAME' => $fromUser[
'last_name'],
5783 'WORK_POSITION' => $fromUser[
'work_position'],
5784 'GENDER' => $fromUser[
'gender'],
5785 'IS_BOT' => $fromUser[
'bot']?
'Y':
'N',
5786 'IS_CONNECTOR' => $fromUser[
'connector']?
'Y':
'N',
5787 'IS_NETWORK' => $fromUser[
'network']?
'Y':
'N',
5788 'IS_EXTRANET' => $fromUser[
'extranet']?
'Y':
'N',
5807 if (!$arHandler[
'APP_CODE'])
5809 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
5810 parse_str($parts[
'query'],
$query);
5815 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
5819 if (!$arHandler[
'APP_CODE'])
5821 throw new Exception(
'Event is intended for another application');
5827 if ($botData[
'APP_ID'] == $arHandler[
'APP_CODE'])
5829 $sendBotData = self::getAccessToken($arHandler[
'APP_ID'], $botData[
'BOT_ID']);
5830 $sendBotData[
'AUTH'] = $sendBotData;
5831 $sendBotData[
'BOT_ID'] = $botData[
'BOT_ID'];
5832 $sendBotData[
'BOT_CODE'] = $botData[
'CODE'];
5833 $bots[$botData[
'BOT_ID']] = $sendBotData;
5839 throw new Exception(
'Event is intended for another application');
5844 $arParams[2][
'LANGUAGE'] = \Bitrix\Im\Bot::getDefaultLanguage();
5851 'ID' => $fromUser[
'id'],
5852 'NAME' => $fromUser[
'name'],
5853 'FIRST_NAME' => $fromUser[
'first_name'],
5854 'LAST_NAME' => $fromUser[
'last_name'],
5855 'WORK_POSITION' => $fromUser[
'work_position'],
5856 'GENDER' => $fromUser[
'gender'],
5857 'IS_BOT' => $fromUser[
'bot']?
'Y':
'N',
5858 'IS_CONNECTOR' => $fromUser[
'connector']?
'Y':
'N',
5859 'IS_NETWORK' => $fromUser[
'network']?
'Y':
'N',
5860 'IS_EXTRANET' => $fromUser[
'extranet']?
'Y':
'N',
5879 if (!$arHandler[
'APP_CODE'])
5881 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
5882 parse_str($parts[
'query'],
$query);
5887 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
5891 if (!$arHandler[
'APP_CODE'])
5893 throw new Exception(
'Event is intended for another application');
5899 if ($botData[
'APP_ID'] == $arHandler[
'APP_CODE'])
5901 $sendBotData = self::getAccessToken($arHandler[
'APP_ID'], $botData[
'BOT_ID']);
5902 $sendBotData[
'AUTH'] = $sendBotData;
5903 $sendBotData[
'BOT_ID'] = $botData[
'BOT_ID'];
5904 $sendBotData[
'BOT_CODE'] = $botData[
'CODE'];
5905 $bots[$botData[
'BOT_ID']] = $sendBotData;
5911 throw new Exception(
'Event is intended for another application');
5916 $arParams[2][
'LANGUAGE'] = \Bitrix\Im\Bot::getDefaultLanguage();
5923 'ID' => $fromUser[
'id'],
5924 'NAME' => $fromUser[
'name'],
5925 'FIRST_NAME' => $fromUser[
'first_name'],
5926 'LAST_NAME' => $fromUser[
'last_name'],
5927 'WORK_POSITION' => $fromUser[
'work_position'],
5928 'GENDER' => $fromUser[
'gender'],
5929 'IS_BOT' => $fromUser[
'bot']?
'Y':
'N',
5930 'IS_CONNECTOR' => $fromUser[
'connector']?
'Y':
'N',
5931 'IS_NETWORK' => $fromUser[
'network']?
'Y':
'N',
5932 'IS_EXTRANET' => $fromUser[
'extranet']?
'Y':
'N',
5951 if (!$arHandler[
'APP_CODE'])
5953 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
5954 parse_str($parts[
'query'],
$query);
5958 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
5962 if (!$arHandler[
'APP_CODE'])
5964 throw new Exception(
'Event is intended for another application');
5968 if (
$arParams[0][
'APP_ID'] == $arHandler[
'APP_CODE'])
5970 $sendBotData = self::getAccessToken($arHandler[
'APP_ID'],
$arParams[0][
'BOT_ID']);
5971 $sendBotData[
'AUTH'] = $sendBotData;
5972 $sendBotData[
'BOT_ID'] =
$arParams[0][
'BOT_ID'];
5973 $sendBotData[
'BOT_CODE'] =
$arParams[0][
'CODE'];
5974 $bots[
$arParams[0][
'BOT_ID']] = $sendBotData;
5979 throw new Exception(
'Event is intended for another application');
5984 $params[
'LANGUAGE'] = \Bitrix\Im\Bot::getDefaultLanguage();
5991 'ID' => $fromUser[
'id'],
5992 'NAME' => $fromUser[
'name'],
5993 'FIRST_NAME' => $fromUser[
'first_name'],
5994 'LAST_NAME' => $fromUser[
'last_name'],
5995 'WORK_POSITION' => $fromUser[
'work_position'],
5996 'GENDER' => $fromUser[
'gender'],
6006 \Bitrix\Im\Bot::startWriting(Array(
'BOT_ID' =>
$params[
'BOT_ID']),
$params[
'DIALOG_ID']);
6020 if (!$arHandler[
'APP_CODE'])
6022 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
6023 parse_str($parts[
'query'],
$query);
6027 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
6031 if (!$arHandler[
'APP_CODE'])
6033 throw new Exception(
'Event is intended for another application');
6037 if (
$arParams[0][
'APP_ID'] == $arHandler[
'APP_CODE'])
6044 throw new Exception(
'Event is intended for another application');
6049 $result = self::unbindEvent($arHandler[
'APP_ID'], $arHandler[
'APP_CODE'],
'im',
'onImBotMessageAdd',
'OnImBotMessageAdd');
6052 self::unbindEvent($arHandler[
'APP_ID'], $arHandler[
'APP_CODE'],
'im',
'onImBotJoinChat',
'OnImBotJoinChat');
6053 self::unbindEvent($arHandler[
'APP_ID'], $arHandler[
'APP_CODE'],
'im',
'onImBotDelete',
'OnImBotDelete');
6058 'BOT_CODE' => $botCode
6066 if (!$arHandler[
'APP_CODE'])
6068 $parts = parse_url($arHandler[
'EVENT_HANDLER']);
6069 parse_str($parts[
'query'],
$query);
6073 $arHandler[
'APP_CODE'] =
'custom'.$query[
'CLIENT_ID'];
6077 if (!$arHandler[
'APP_CODE'])
6079 throw new Exception(
'Event is intended for another application');
6086 if ($botData[
'APP_ID'] == $arHandler[
'APP_CODE'])
6088 $sendBotData = self::getAccessToken($arHandler[
'APP_ID'], $botData[
'BOT_ID']);
6089 $sendBotData[
'AUTH'] = $sendBotData;
6090 $sendBotData[
'BOT_ID'] = $botData[
'BOT_ID'];
6091 $sendBotData[
'BOT_CODE'] = $botData[
'CODE'];
6092 $bots[$botData[
'BOT_ID']] = $sendBotData;
6098 throw new Exception(
'Event is intended for another application');
6103 $params[
'LANGUAGE'] = \Bitrix\Im\Bot::getDefaultLanguage();
6111 'ID' => $fromUser[
'id'],
6112 'NAME' => $fromUser[
'name'],
6113 'FIRST_NAME' => $fromUser[
'first_name'],
6114 'LAST_NAME' => $fromUser[
'last_name'],
6115 'WORK_POSITION' => $fromUser[
'work_position'],
6116 'GENDER' => $fromUser[
'gender'],
6131 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6135 $customClientId =
false;
6141 $customClientId =
true;
6142 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6146 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6150 if ($customClientId)
6152 $arApp = [
'ID' =>
'',
'CLIENT_ID' =>
$arParams[
'CLIENT_ID']];
6157 $arApp =
$dbRes->fetch();
6162 if ($customClientId)
6177 throw new Bitrix\Rest\RestException(
"Handler for \"Command add\" event isn't specified",
"EVENT_COMMAND_ADD_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6188 $bots = \Bitrix\Im\Bot::getListCache();
6195 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6217 'SONET_SUPPORT' =>
$arParams[
'SONET_SUPPORT'],
6218 'EXTRANET_SUPPORT' =>
$arParams[
'EXTRANET_SUPPORT'],
6219 'MODULE_ID' =>
'rest',
6224 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImCommandAdd',
'onImCommandAdd',
true);
6225 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImCommandAdd',
'onImCommandAdd',
$arParams[
'EVENT_COMMAND_ADD']);
6239 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6248 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6252 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6257 if (!isset($commands[
$arParams[
'COMMAND_ID']]))
6263 throw new Bitrix\Rest\RestException(
"Command was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6279 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6284 $customClientId =
false;
6289 $customClientId =
true;
6290 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6294 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6299 if (!isset($bots[
$arParams[
'COMMAND_ID']]))
6305 throw new Bitrix\Rest\RestException(
"Command was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6308 if ($customClientId)
6310 $arApp = [
'ID' =>
'',
'CLIENT_ID' =>
$arParams[
'CLIENT_ID']];
6315 $arApp =
$dbRes->fetch();
6318 $updateEvents = Array();
6319 if (isset(
$arParams[
'FIELDS'][
'EVENT_COMMAND_ADD']) && !empty(
$arParams[
'FIELDS'][
'EVENT_COMMAND_ADD']))
6321 $updateEvents[
'EVENT_COMMAND_ADD'] =
$arParams[
'FIELDS'][
'EVENT_COMMAND_ADD'];
6322 if ($customClientId)
6324 $updateEvents[
'EVENT_COMMAND_ADD'] = $updateEvents[
'EVENT_COMMAND_ADD'].(mb_strpos($updateEvents[
'EVENT_COMMAND_ADD'],
'?') ===
false?
'?':
'&').
'CLIENT_ID='.
$arParams[
'CLIENT_ID'];
6336 $updateFields = Array();
6340 $updateFields[
'COMMAND'] =
$arParams[
'FIELDS'][
'COMMAND'];
6345 $updateFields[
'HIDDEN'] =
$arParams[
'FIELDS'][
'HIDDEN'] ==
'Y'?
'Y':
'N';
6348 if (isset(
$arParams[
'FIELDS'][
'EXTRANET_SUPPORT']) && !empty(
$arParams[
'FIELDS'][
'EXTRANET_SUPPORT']))
6350 $updateFields[
'EXTRANET_SUPPORT'] =
$arParams[
'FIELDS'][
'EXTRANET_SUPPORT'] ==
'Y'?
'Y':
'N';
6355 $updateFields[
'LANG'] =
$arParams[
'FIELDS'][
'LANG'];
6358 if (empty($updateFields))
6360 if (empty($updateEvents))
6362 throw new Bitrix\Rest\RestException(
"Update fields can't be empty",
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
6374 if (isset($updateEvents[
'EVENT_COMMAND_ADD']))
6376 self::unbindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImCommandAdd',
'onImCommandAdd',
true);
6377 self::bindEvent($arApp[
'ID'], $arApp[
'CLIENT_ID'],
'im',
'onImCommandAdd',
'onImCommandAdd', $updateEvents[
'EVENT_COMMAND_ADD']);
6387 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6396 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6400 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6407 if (!isset($commands[
$arParams[
'COMMAND_ID']]))
6413 throw new Bitrix\Rest\RestException(
"Command was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6418 $commandFound =
false;
6419 foreach ($commands as $command)
6423 $commandFound =
true;
6424 $arParams[
'COMMAND_ID'] = $command[
'COMMAND_ID'];
6433 $botId = intval($commands[
$arParams[
'COMMAND_ID']][
'BOT_ID']);
6435 $arMessageFields = Array();
6440 throw new Bitrix\Rest\RestException(
"Message ID can't be empty",
"MESSAGE_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
6443 $arMessageFields[
'MESSAGE'] = trim(
$arParams[
'MESSAGE']);
6444 if ($arMessageFields[
'MESSAGE'] ==
'')
6449 $attach = CIMMessageParamAttach::GetAttachByJson(
$arParams[
'ATTACH']);
6452 if ($attach->IsAllowSize())
6454 $arMessageFields[
'ATTACH'] = $attach;
6458 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of attach",
"ATTACH_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
6468 $keyboard = Array();
6473 if (!isset(
$arParams[
'KEYBOARD'][
'BUTTONS']))
6475 $keyboard[
'BUTTONS'] =
$arParams[
'KEYBOARD'];
6481 $keyboard[
'BOT_ID'] = $botId;
6486 if ($keyboard->isAllowSize())
6488 $arMessageFields[
'KEYBOARD'] = $keyboard;
6492 throw new Bitrix\Rest\RestException(
"You have exceeded the maximum allowable size of keyboard",
"KEYBOARD_OVERSIZE", CRestServer::STATUS_WRONG_REQUEST);
6521 $arMessageFields[
'MENU'] = $menu;
6531 $arMessageFields[
'SYSTEM'] =
'Y';
6536 $arMessageFields[
'URL_PREVIEW'] =
'N';
6540 'MESSAGE_ID' =>
$arParams[
'MESSAGE_ID'],
6542 ), $arMessageFields);
6557 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6566 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6570 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6587 isset(
$arParams[
'JS_METHOD']) && in_array(
$arParams[
'JS_METHOD'], Array(
'PUT',
'SEND',
'CALL',
'SUPPORT')) &&
6593 if (preg_match(
'/\/([a-zA-Z0-9\-\_\+]+)((\s)?([a-zA-Z0-9\-\_\+]+))+/im',
$arParams[
'JS_PARAM'],
$matches))
6595 $js =
"BXIM.sendMessage('".$matches[0].
"');";
6598 else if (
$arParams[
'JS_METHOD'] ==
'PUT')
6600 if (preg_match(
'/\/([a-zA-Z0-9\-\_\+]+)((\s)?([a-zA-Z0-9\-\_\+]+))+/im',
$arParams[
'JS_PARAM'],
$matches))
6602 $js =
"BXIM.putMessage('".$matches[0].
"');";
6605 else if (
$arParams[
'JS_METHOD'] ==
'CALL')
6609 $js =
"BXIM.phoneTo('".$matches[0].
"');";
6612 else if (
$arParams[
'JS_METHOD'] ==
'SUPPORT')
6616 $js =
"BXIM.openMessenger('networkLines".$matches[0].
"');";
6622 $check = parse_url(
$arParams[
'IFRAME']);
6623 if (!isset($check[
'scheme']) && !isset($check[
'host']))
6625 throw new Bitrix\Rest\RestException(
"Iframe params must be HTTPS site",
"IFRAME_HTTPS", CRestServer::STATUS_WRONG_REQUEST);
6627 else if ($check[
'scheme'] !=
'https' || empty($check[
'host']))
6629 throw new Bitrix\Rest\RestException(
"Iframe params must be HTTPS site",
"IFRAME_HTTPS", CRestServer::STATUS_WRONG_REQUEST);
6635 $iframeWidth = intval(
$arParams[
'IFRAME_WIDTH']) > 250?
$arParams[
'IFRAME_WIDTH']: 250;
6637 $iframeHeight = 250;
6640 $iframeHeight = intval(
$arParams[
'IFRAME_HEIGHT']) > 50?
$arParams[
'IFRAME_HEIGHT']: 50;
6642 $iframePopup = isset(
$arParams[
'IFRAME_POPUP']) &&
$arParams[
'IFRAME_POPUP'] ==
'Y'?
'Y':
'N';
6651 if (!$iframe && !$js)
6653 throw new Bitrix\Rest\RestException(
"Iframe or JS method isn't specified",
"PARAMS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6659 $iconFile = \CRestUtil::saveFile(
$arParams[
'ICON_FILE']);
6660 $imageCheck = (new \Bitrix\Main\File\Image($iconFile[
"tmp_name"]))->getInfo();
6663 || !$imageCheck->getWidth()
6664 || $imageCheck->getWidth() > 5000
6665 || !$imageCheck->getHeight()
6666 || $imageCheck->getHeight() > 5000
6671 if ($iconFile && mb_strpos($iconFile[
'type'],
"image/") === 0)
6673 $iconFile[
'MODULE_ID'] =
'imbot';
6674 $iconId = \CFile::saveFile($iconFile,
'imbot');
6681 $extranetSupport = isset(
$arParams[
'EXTRANET_SUPPORT']) &&
$arParams[
'EXTRANET_SUPPORT'] ==
'Y'?
'Y':
'N';
6682 $livechatSupport = isset(
$arParams[
'LIVECHAT_SUPPORT']) &&
$arParams[
'LIVECHAT_SUPPORT'] ==
'Y'?
'Y':
'N';
6687 $bots = \Bitrix\Im\Bot::getListCache();
6694 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6711 'ICON_ID' => $iconId,
6714 'HIDDEN' => $hidden,
6715 'REGISTERED' =>
'Y',
6717 'IFRAME' => $iframe,
6718 'IFRAME_HEIGHT' => $iframeHeight,
6719 'IFRAME_WIDTH' => $iframeWidth,
6720 'IFRAME_POPUP' => $iframePopup,
6721 'EXTRANET_SUPPORT' => $extranetSupport,
6722 'LIVECHAT_SUPPORT' => $livechatSupport,
6723 'MODULE_ID' =>
'rest',
6732 'ICON_ID' => $iconId,
6735 'HIDDEN' => $hidden,
6737 'IFRAME' => $iframe,
6738 'IFRAME_HEIGHT' => $iframeHeight,
6739 'IFRAME_WIDTH' => $iframeWidth,
6740 'IFRAME_POPUP' => $iframePopup,
6741 'EXTRANET_SUPPORT' => $extranetSupport,
6742 'LIVECHAT_SUPPORT' => $livechatSupport,
6743 'MODULE_ID' =>
'rest',
6745 ),1),
"WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
6755 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6764 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6768 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6779 throw new Bitrix\Rest\RestException(
"App was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6795 throw new \Bitrix\Rest\RestException(
"Access for this method not allowed by session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
6804 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
6808 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
6819 throw new Bitrix\Rest\RestException(
"App was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
6822 $updateFields = Array();
6826 $updateFields[
'CONTEXT'] =
$arParams[
'FIELDS'][
'CONTEXT'];
6830 $updateFields[
'HASH'] =
$arParams[
'FIELDS'][
'HASH'];
6834 isset(
$arParams[
'FIELDS'][
'JS_METHOD']) && in_array(
$arParams[
'FIELDS'][
'JS_METHOD'], Array(
'PUT',
'SEND',
'CALL',
'SUPPORT')) &&
6838 if (
$arParams[
'FIELDS'][
'JS_METHOD'] ==
'SEND')
6840 if (preg_match(
'/\/([a-zA-Z0-9\-\_\+]+)((\s)?([a-zA-Z0-9\-\_\+]+))+/im',
$arParams[
'FIELDS'][
'JS_PARAM'],
$matches))
6842 $updateFields[
'JS'] =
"BXIM.sendMessage('".$matches[0].
"');";
6845 else if (
$arParams[
'FIELDS'][
'JS_METHOD'] ==
'PUT')
6847 if (preg_match(
'/\/([a-zA-Z0-9\-\_\+]+)((\s)?([a-zA-Z0-9\-\_\+]+))+/im',
$arParams[
'FIELDS'][
'JS_PARAM'],
$matches))
6849 $updateFields[
'JS'] =
"BXIM.putMessage('".$matches[0].
"');";
6852 else if (
$arParams[
'FIELDS'][
'JS_METHOD'] ==
'CALL')
6854 if (preg_match(
'/\+?[ \-\d+\(\)\#]+$/im',
$arParams[
'FIELDS'][
'JS_PARAM'],
$matches))
6856 $updateFields[
'JS'] =
"BXIM.phoneTo('".$matches[0].
"');";
6859 else if (
$arParams[
'FIELDS'][
'JS_METHOD'] ==
'SUPPORT')
6863 $updateFields[
'JS'] =
"BXIM.openMessenger('networkLines".$matches[0].
"');";
6866 if (isset($updateFields[
'JS']))
6868 $updateFields[
'IFRAME'] =
'';
6871 else if (isset(
$arParams[
'FIELDS'][
'IFRAME']) && !empty(
$arParams[
'FIELDS'][
'IFRAME']))
6873 $check = parse_url(
$arParams[
'FIELDS'][
'IFRAME']);
6874 if (!isset($check[
'scheme']) && !isset($check[
'host']))
6876 throw new Bitrix\Rest\RestException(
"Iframe params must be HTTPS site",
"IFRAME_HTTPS", CRestServer::STATUS_WRONG_REQUEST);
6878 else if ($check[
'scheme'] !=
'https' || empty($check[
'host']))
6880 throw new Bitrix\Rest\RestException(
"Iframe params must be HTTPS site",
"IFRAME_HTTPS", CRestServer::STATUS_WRONG_REQUEST);
6882 $updateFields[
'IFRAME'] =
$arParams[
'FIELDS'][
'IFRAME'];
6883 $updateFields[
'JS'] =
'';
6886 if (isset(
$arParams[
'FIELDS'][
'IFRAME_WIDTH']))
6888 $updateFields[
'IFRAME_WIDTH'] = intval(
$arParams[
'FIELDS'][
'IFRAME_WIDTH']);
6890 if (isset(
$arParams[
'FIELDS'][
'IFRAME_HEIGHT']))
6892 $updateFields[
'IFRAME_HEIGHT'] = intval(
$arParams[
'FIELDS'][
'IFRAME_HEIGHT']);
6894 if (isset(
$arParams[
'FIELDS'][
'IFRAME_POPUP']) && !empty(
$arParams[
'FIELDS'][
'IFRAME_POPUP']))
6896 $updateFields[
'IFRAME_POPUP'] =
$arParams[
'FIELDS'][
'IFRAME_POPUP'] ==
'Y'?
'Y':
'N';
6901 $updateFields[
'HIDDEN'] =
$arParams[
'FIELDS'][
'HIDDEN'] ==
'Y'?
'Y':
'N';
6904 if (isset(
$arParams[
'FIELDS'][
'EXTRANET_SUPPORT']) && !empty(
$arParams[
'FIELDS'][
'EXTRANET_SUPPORT']))
6906 $updateFields[
'EXTRANET_SUPPORT'] =
$arParams[
'FIELDS'][
'EXTRANET_SUPPORT'] ==
'Y'?
'Y':
'N';
6909 if (isset(
$arParams[
'FIELDS'][
'LIVECHAT_SUPPORT']) && !empty(
$arParams[
'FIELDS'][
'LIVECHAT_SUPPORT']))
6911 $updateFields[
'LIVECHAT_SUPPORT'] =
$arParams[
'FIELDS'][
'LIVECHAT_SUPPORT'] ==
'Y'?
'Y':
'N';
6916 $updateFields[
'LANG'] =
$arParams[
'FIELDS'][
'LANG'];
6919 if (isset(
$arParams[
'FIELDS'][
'ICON_FILE']))
6921 $iconFile = \CRestUtil::saveFile(
$arParams[
'FIELDS'][
'ICON_FILE']);
6922 $imageCheck = (new \Bitrix\Main\File\Image($iconFile[
"tmp_name"]))->getInfo();
6925 || !$imageCheck->getWidth()
6926 || $imageCheck->getWidth() > 5000
6927 || !$imageCheck->getHeight()
6928 || $imageCheck->getHeight() > 5000
6933 if ($iconFile && mb_strpos($iconFile[
'type'],
"image/") === 0)
6935 $iconFile[
'MODULE_ID'] =
'imbot';
6936 $updateFields[
'ICON_FILE_ID'] = \CFile::saveFile($iconFile,
'imbot');
6940 if (!empty($updateFields))
6954 private static function getAccessToken($appId,
$userId)
6961 $auth = \Bitrix\Rest\Event\Sender::getAuth(
6964 array(
'EVENT_SESSION' => $session),
6966 'sendRefreshToken' => 1,
6973 private static function bindEvent($appId, $appCode, $bitrixEventModule, $bitrixEventName, $restEventName, $restEventHandler)
6975 $res = \Bitrix\Rest\EventTable::getList(
array(
6977 '=EVENT_NAME' => mb_strtoupper($restEventName),
6978 '=APPLICATION_TOKEN' => $appCode,
6979 '=APP_ID' => $appId,
6981 'select' =>
array(
'ID')
6984 if ($handler =
$res->fetch())
6991 'EVENT_NAME' => mb_strtoupper($restEventName),
6992 'EVENT_HANDLER' => $restEventHandler,
6993 'APPLICATION_TOKEN' => $appCode,
7000 \Bitrix\Rest\EventTable::merge($insertFields, $updateFields);
7001 \Bitrix\Rest\Event\Sender::bind($bitrixEventModule, $bitrixEventName);
7006 private static function unbindEvent($appId, $appCode, $bitrixEventModule, $bitrixEventName, $restEventName, $skipCheck =
false)
7010 $res = \Bitrix\Im\Model\BotTable::getList(
array(
7012 '=APP_ID' => $appCode,
7014 'select' =>
array(
'BOT_ID')
7016 if ($handler =
$res->fetch())
7022 $res = \Bitrix\Rest\EventTable::getList(
array(
7024 '=EVENT_NAME' => mb_strtoupper($restEventName),
7025 '=APP_ID' => $appId,
7026 '=APPLICATION_TOKEN' => $appCode,
7028 'select' =>
array(
'ID',
'EVENT_HANDLER')
7030 while($handler =
$res->fetch())
7032 \Bitrix\Rest\EventTable::delete($handler[
'ID']);
7042 && !self::isDebugEnabled()
7045 throw new \Bitrix\Rest\RestException(
"Get access to browser const available only for session authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
7057 $arUsers = CIMContactList::GetUserData(
array(
7059 'DEPARTMENT' =>
'N',
7061 'SHOW_ONLINE' =>
'N'
7068 $config[
"PATH_TO_USER_PROFILE_TEMPLATE"] =
SITE_DIR.
'mobile/users/?user_id=#user_id#&FROM_DIALOG=Y';
7072 return \CIMMessenger::GetMobileDialogTemplateJS([],
$config);
7081 throw new \Bitrix\Rest\RestException(
"Access for this method allowed only by call authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
7088 isset($_SESSION[
'CALL'][
'REGISTER'])
7089 && $_SESSION[
'CALL'][
'REGISTER']
7094 && preg_match(
"/^[a-fA-F0-9]{32}$/i",
$params[
'USER_HASH'])
7098 $params[
'USER_HASH'] = $_SESSION[
'CALL'][
'REGISTER'][
'hash'];
7103 'NAME' =>
$params[
'NAME'] ??
'',
7104 'LAST_NAME' =>
$params[
'LAST_NAME'] ??
'',
7105 'AVATAR' =>
$params[
'AVATAR'] ??
'',
7106 'EMAIL' =>
$params[
'EMAIL'] ??
'',
7107 'PERSONAL_WWW' =>
$params[
'WWW'] ??
'',
7108 'PERSONAL_GENDER' =>
$params[
'GENDER'] ??
'',
7109 'WORK_POSITION' =>
$params[
'POSITION'] ??
'',
7110 'USER_HASH' =>
$params[
'USER_HASH'] ??
'',
7114 throw new \Bitrix\Rest\RestException(
7115 \
Bitrix\Im\Call\User::getError()->msg,
7116 \
Bitrix\Im\Call\User::getError()->code,
7117 \CRestServer::STATUS_WRONG_REQUEST
7124 throw new \Bitrix\Rest\RestException(
"Wrong alias.",
"WRONG_ALIAS", \CRestServer::STATUS_FORBIDDEN);
7133 chatId: $aliasData[
'ENTITY_ID'],
7134 userId: $userData[
'ID'],
7141 if ($exception->GetID() !==
'NOTHING_TO_ADD')
7144 "You don't have access",
7146 CRestServer::STATUS_WRONG_REQUEST
7154 'id' => (int)$userData[
'ID'],
7155 'hash' => $userData[
'HASH'],
7156 'created' => $userData[
'CREATED'],
7157 'userToken' => \
Bitrix\Call\JwtCall::getUserJwt(),
7160 $_SESSION[
'CALL'][
'REGISTER'] =
$result;
7163 $chatData = CIMChat::GetChatData([
'ID' => $aliasData[
'ENTITY_ID']]);
7164 $chatTitle = $chatData[
'chat'][$aliasData[
'ENTITY_ID']][
'name'];
7165 $chatOwnerId = $chatData[
'chat'][$aliasData[
'ENTITY_ID']][
'owner'];
7167 $publicLink = $aliasData[
'LINK'];
7170 'TO_USER_ID' => $chatOwnerId,
7171 'MESSAGE' => fn (?
string $languageId =
null) => Loc::getMessage(
7172 "IM_VIDEOCONF_NEW_GUEST",
7173 [
'#CHAT_TITLE#' => $chatTitle],
7175 ) .
"[br]" .
"<a href='{$publicLink}'>" . Loc::getMessage(
"IM_VIDEOCONF_JOIN_LINK",
null, $languageId) .
"</a>",
7182 public static function callUserUpdate(
$params,
$n, \CRestServer $server)
7186 throw new \Bitrix\Rest\RestException(
7187 "Access for this method allowed only by call authorization.",
7189 \CRestServer::STATUS_FORBIDDEN
7196 throw new Bitrix\Rest\RestException(
"User NAME can't be empty",
"USER_NAME_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
7207 $userManager = new \CUser;
7208 $userManager->Update(
$USER->GetID(), [
7212 $relations = \Bitrix\Im\Chat::getRelation(
$params[
'CHAT_ID'], [
'WITHOUT_COUNTERS' =>
'Y']);
7214 if (\CModule::IncludeModule(
"pull"))
7216 \Bitrix\Pull\Event::add(array_keys($relations), [
7217 'module_id' =>
'im',
7218 'command' =>
'callUserNameUpdate',
7220 'userId' =>
$USER->GetID(),
7223 'extra' => \Bitrix\Im\Common::getPullExtra()
7246 $chat = \Bitrix\Im\Model\ChatTable::getRowById(
$params[
'CHAT_ID']);
7251 $owner = (int)$chat[
'AUTHOR_ID'];
7252 if ((
int)
$USER->GetID() !== $owner)
7254 throw new Bitrix\Rest\RestException(
"You cannot perform this operation",
"NO_ACCESS", CRestServer::STATUS_WRONG_REQUEST);
7263 $externalAuth = $userToRename->getExternalAuthId();
7264 if ($externalAuth !==
'call')
7266 throw new Bitrix\Rest\RestException(
"You cannot rename this user",
"WRONG_USER_AUTH_TYPE", CRestServer::STATUS_WRONG_REQUEST);
7269 $userManager = new \CUser;
7270 $userManager->Update(
$params[
'USER_ID'], [
7276 if (\CModule::IncludeModule(
"pull"))
7279 'module_id' =>
'im',
7280 'command' =>
'callUserNameUpdate',
7282 'userId' =>
$params[
'USER_ID'],
7285 'extra' => \
Bitrix\Im\Common::getPullExtra()
7295 if (
$params[
'APPLICATION'] ==
'Y')
7300 throw new \Bitrix\Rest\RestException(
"Get application public channel available only for application authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_WRONG_REQUEST);
7306 if (is_string(
$params[
'USERS']))
7310 if (is_array(
$params[
'USERS']))
7324 throw new \Bitrix\Rest\RestException(
"A wrong format for the USERS field is passed",
"INVALID_FORMAT", \CRestServer::STATUS_WRONG_REQUEST);
7327 $chatId = (int)
$params[
'CALL_CHAT_ID'];
7331 throw new \Bitrix\Rest\RestException(
"No chat id",
"INVALID_FORMAT", \CRestServer::STATUS_WRONG_REQUEST);
7334 $configParams = Array();
7335 $configParams[
'TYPE'] =
$type;
7336 $configParams[
'USERS'] = $users;
7337 $configParams[
'JSON'] =
true;
7342 throw new \Bitrix\Rest\RestException(
"Push & Pull server is not configured",
"SERVER_ERROR", \CRestServer::STATUS_INTERNAL);
7363 if (
$USER->GetID() != $chatData[
'OWNER'])
7365 throw new Bitrix\Rest\RestException(
"You don't have access to this chat",
"ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
7373 foreach($chatUsers as $user)
7375 if (in_array($user[
'external_auth_id'], $externalTypes,
true))
7377 $chat->DeleteUser($chatId, $user[
'id']);
7387 'ALIAS' => $newCode,
7388 'ENTITY_TYPE' =>
'VIDEOCONF',
7389 'ENTITY_ID' => $chatId
7409 CIMChat::AddMessage(
7411 "TO_CHAT_ID" => $chatId,
7413 "FROM_USER_ID" =>
$USER->GetID(),
7414 "MESSAGE" =>
GetMessage(
"IM_VIDEOCONF_LINK_TITLE"),
7422 if (\CModule::IncludeModule(
"pull"))
7425 'module_id' =>
'im',
7426 'command' =>
'videoconfShareUpdate',
7428 'newCode' => $newCode,
7429 'newLink' => $newLink,
7430 'dialogId' =>
$params[
'DIALOG_ID']
7432 'extra' => \
Bitrix\Im\Common::getPullExtra()
7454 if ($conference && $conference->getPassword() ===
$params[
'PASSWORD'])
7462 $isUserInChat = Chat::isUserInChat($conference->getChatId());
7463 if ($currentUserId && !$isUserInChat)
7465 $chat = new \CIMChat(0);
7466 $addingResult = $chat->AddUser(
7467 chatId: $conference->getChatId(),
7468 userId: $currentUserId,
7475 throw new Bitrix\Rest\RestException(
"Error during adding user to chat",
"ADDING_TO_CHAT_ERROR", CRestServer::STATUS_WRONG_REQUEST);
7487 throw new \Bitrix\Rest\RestException(
'This method is not available',
'METHOD_NOT_AVAILABLE', CRestServer::STATUS_WRONG_REQUEST);
7492 \
Bitrix\Im\User::getInstance()->isExtranet()
7493 || \
Bitrix\Im\User::getInstance()->isBot()
7496 throw new Bitrix\Rest\RestException(
"Only intranet users have access to this method.",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
7503 if (!$createResult->isSuccess())
7505 $error = $createResult->getErrors()[0];
7510 'chatId' => $createResult->getData()[
'CHAT_ID'],
7511 'alias' => $createResult->getData()[
'ALIAS_DATA'][
'ALIAS'],
7512 'link' => $createResult->getData()[
'ALIAS_DATA'][
'LINK']
7518 throw new \Bitrix\Rest\RestException(
'This method is not available',
'METHOD_NOT_AVAILABLE', CRestServer::STATUS_WRONG_REQUEST);
7523 \
Bitrix\Im\User::getInstance()->isExtranet()
7524 || \
Bitrix\Im\User::getInstance()->isBot()
7527 throw new Bitrix\Rest\RestException(
"Only intranet users have access to this method.",
"ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
7534 throw new Bitrix\Rest\RestException(
"Conference ID can't be empty",
"CONFERENCE_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
7541 throw new Bitrix\Rest\RestException(
"Conference with such id not found.",
"CONFERENCE_NOT_FOUND", CRestServer::STATUS_WRONG_REQUEST);
7544 if (!$conference->canUserEdit(\
Bitrix\Main\Engine\CurrentUser::get()->getId()))
7549 $updateResult = $conference->update(
$arParams);
7551 if (!$updateResult->isSuccess())
7553 $error = $updateResult->getErrors()[0];
7557 return $updateResult->isSuccess();
7563 'isOnline' => CIMMessenger::CheckDesktopStatusOnline(),
7564 'version' => CIMMessenger::GetDesktopVersion()
7572 if (CIMMessenger::GetDesktopVersion() === 0)
7577 if (!CIMMessenger::CheckDesktopStatusOnline())
7582 if (\CModule::IncludeModule(
"pull"))
7591 'module_id' =>
'im',
7592 'command' =>
'desktopOpenPage',
7596 'extra' => \
Bitrix\Im\Common::getPullExtra()
7603 private static function getBotId(
$arParams, \CRestServer $server)
7612 $clientId =
'custom'.$arParams[
'CLIENT_ID'];
7616 throw new \Bitrix\Rest\AccessException(
"Client ID not specified");
7620 $bots = \Bitrix\Im\Bot::getListCache();
7625 throw new Bitrix\Rest\RestException(
"Bot not found",
"BOT_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
7629 throw new Bitrix\Rest\RestException(
"Bot was installed by another rest application",
"APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
7635 foreach ($bots as $bot)
7646 throw new Bitrix\Rest\RestException(
"Bot not found",
"BOT_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
7653 private static function getLimit(
$options = [])
7677 private static function getOffset(
int $offset,
$options = [])
7692 private static function getRawParam(
string $paramName)
7694 $context = \Bitrix\Main\Context::getCurrent();
7701 $paramName = mb_strtoupper($paramName);
7703 $postRawData = array_change_key_case(
$request->getPostList()->toArrayRaw() ?? [], CASE_UPPER);
7704 $getRawData = array_change_key_case(
$request->getQueryList()->toArrayRaw() ?? [], CASE_UPPER);
7706 return $postRawData[$paramName] ??
$getRawData[$paramName] ??
null;
7712 if (!is_array(
$options[
'IMAGE_FIELD']))
7714 $options[
'IMAGE_FIELD'] = [
'AVATAR',
'AVATAR_HR'];
7718 if (is_array(
$data))
7723 if (is_array($value))
7729 $value = date(
'c', $value->getTimestamp());
7731 else if (is_string(
$key) && in_array(
$key,
$options[
'IMAGE_FIELD']) && is_string($value) && $value && mb_strpos($value,
'http') !== 0)
7736 $key = str_replace(
'_',
'', lcfirst(ucwords(mb_strtolower(
$key),
'_')));
7756 return (\
Bitrix\Main\Context::getCurrent()->getRequest()->isHttps() ?
"https" :
"http").
"://".
$_SERVER[
'SERVER_NAME'].(in_array(
$_SERVER[
'SERVER_PORT'], Array(80, 443))?
'':
':'.
$_SERVER[
'SERVER_PORT']);
7763 return $settings[
'rest_debug'] ===
true;
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static update($id, $fields)
static getByEntity($entityType, $entityId)
static register(array $fields)
static update(array $app, array $updateFields)
static getListCache($lang=LANGUAGE_ID)
static unRegister(array $app)
static getKeyboardByJson($params, $textReplace=array(), $options=Array())
static authorizeById($userId, $setCookie=null, $skipAuthorizeCheck=false)
static add(array $fields=[])
static getByAlias(string $alias)
static register($userFields=[])
static getUsers($chatId, $options=[])
static getById($id, $params=array())
static getListParams($params)
static getList($params=array())
static getRelation($chatId, $params=[])
static register(array $fields)
static addMessage(array $access, array $messageFields)
static update(array $command, array $updateFields)
static getListCache($lang=LANGUAGE_ID)
static unRegister(array $command)
static toJson($array, $camelCase=true)
static getUserId($userId=null)
static get($userId=null, $options=[])
static getColleagues($userId=null, $options=array())
static getStructure($options=array())
static getChatId($dialogId, $userId=null)
static unread($dialogId, $messageId=null, $userId=null)
static read($dialogId, $messageId=null, $userId=null)
static filterExternalUserTypes(array $skipTypes=[])
static getList($userId=null, $options=[])
static getInstance($userId=null)
static getListParams($params)
static getBusiness($userId=null, $options=array())
static initById(int $id, ?Context $context=null)
static find(array $filter, array $order, ?int $limit=null, ?Context $context=null)
static find(array $filter=[], array $order=['ID'=> 'DESC'], ?int $limit=null, ?Context $context=null)
static find(array $filter, array $order=['ID'=> 'DESC'], ?int $limit=null, ?Context $context=null)
static find(array $filter, array $order, ?int $limit=null, ?Context $context=null)
static find(array $filter, array $order=['ID'=> 'DESC'], ?int $limit=null, ?Context $context=null)
static find(array $filter, array $order=['MESSAGE_ID'=> 'DESC'], ?int $limit=null, ?Context $context=null, ?int $offset=null)
static find(array $filter, array $order, ?int $limit=null, ?Context $context=null, array $select=[])
static get($moduleId, $name, $default="", $siteId=false)
static includeModule($moduleName)
static getList(array $parameters=array())
static getExternalUserTypes()
static getPublicIds($params=[])
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static checkCallback($handlerUrl, $appInfo=array(), $checkInstallUrl=true)
static RecordShare(int $chatId, int $fileId, ?int $userId=null)
static GetFolderModel($chatId, $createFolder=true)
static SaveToLocalDisk($fileId)
static UploadFileFromDisk($chatId, $files, $text='', $options=[], $robot=false)
static DeleteFile($chatId, $fileId)
static UpdateAvatarId($chatId, $fileId, $userId=null)
static chatFileCollectionGet($arParams, $n, CRestServer $server)
static userStatusIdleEnd($params, $n, \CRestServer $server)
static chatTaskPrepare($arParams, $n, CRestServer $server)
static userStatusIdleStart($params, $n, \CRestServer $server)
static commandAnswer($arParams, $n, CRestServer $server)
static botMessageUpdate($arParams, $n, CRestServer $server)
static botUpdate($arParams, $n, CRestServer $server)
static onBotJoinChat($arParams, $arHandler)
static dialogUsersList($params, $offset, CRestServer $server)
static videoconfAdd($arParams, $n, CRestServer $server)
static diskFolderGet($arParams, $n, CRestServer $server)
static recentGet($arParams, $n, CRestServer $server)
static dialogMessagesGet($arParams, $offset, CRestServer $server)
static appUnRegister($arParams, $n, CRestServer $server)
static recentHide($arParams, $n, CRestServer $server)
static dialogMessagesSearch($arParams, $n, CRestServer $server)
static notImplemented($arParams, $n, CRestServer $server)
static chatGet($arParams, $n, CRestServer $server)
static notifyConfirm($arParams, $n, CRestServer $server)
static notifyDelete($arParams, $n, CRestServer $server)
static onBotMessageDelete($arParams, $arHandler)
static departmentManagersGet($arParams, $n, CRestServer $server)
static chatReminderDelete($arParams, $n, CRestServer $server)
static notifyAdd($arParams, $n, CRestServer $server)
static searchChat($arParams, $offset, CRestServer $server)
static getServerAddress()
static chatPinDelete($arParams, $n, CRestServer $server)
static botMessageAdd($arParams, $n, CRestServer $server)
static searchLastGet($arParams, $n, CRestServer $server)
static notifyRead($arParams, $n, CRestServer $server)
static chatCalendarGet($arParams, $n, CRestServer $server)
static chatFileGet($arParams, $n, CRestServer $server)
static recentList($arParams, $offset, CRestServer $server)
static dialogReadAll($arParams, $n, CRestServer $server)
static commandUpdate($arParams, $n, CRestServer $server)
static messageDelete($arParams, $n, CRestServer $server)
static videoconfUpdate($arParams, $n, CRestServer $server)
static dialogRead($arParams, $n, CRestServer $server)
static onBotContextGet($arParams, $arHandler)
static botMessageDelete($arParams, $n, CRestServer $server)
static desktopPageOpen($params, $n, \CRestServer $server)
static chatFavoriteGet($arParams, $n, CRestServer $server)
static chatCalendarPrepare($arParams, $n, CRestServer $server)
static searchDepartment($arParams, $offset, CRestServer $server)
static chatSignGet($arParams, $n, CRestServer $server)
static messageUpdate($arParams, $n, CRestServer $server)
static chatUrlDelete($arParams, $n, CRestServer $server)
static dialogUsersGet($arParams, $n, CRestServer $server)
static chatPinGet($arParams, $n, CRestServer $server)
static chatSetManager($arParams, $n, CRestServer $server)
static recentUnread($arParams, $n, CRestServer $server)
static dialogGet($arParams, $offset, CRestServer $server)
static messageCommand($arParams, $n, CRestServer $server)
static botUnRegister($arParams, $n, CRestServer $server)
static chatUpdateAvatar($arParams, $n, CRestServer $server)
static videoconfShareChange($params, $n, \CRestServer $server)
static messageUserGet($arParams, $offset, CRestServer $server)
static notifySchemaGet($arParams, $n, CRestServer $server)
static desktopStatusGet($params, $n, \CRestServer $server)
static userStatusSet($params, $n, \CRestServer $server)
static botList($arParams, $n, CRestServer $server)
static chatTaskGet($arParams, $n, CRestServer $server)
static OnRestServiceBuildDescription()
static departmentEmployeesGet($arParams, $n, CRestServer $server)
static diskFileSave($arParams, $n, CRestServer $server)
static onCommandAdd($arParams, $arHandler)
static onBotMessageUpdate($arParams, $arHandler)
static notifyReadList($arParams, $n, CRestServer $server)
static chatTaskDelete($arParams, $n, CRestServer $server)
static onBotDelete($arParams, $arHandler)
static chatMute($arParams, $n, CRestServer $server)
static diskFileDelete($arParams, $n, CRestServer $server)
static notifyHistorySearch($arParams, $n, CRestServer $server)
static messageAdd($arParams, $n, CRestServer $server)
static chatFavoriteCounterGet($arParams, $n, CRestServer $server)
static searchLastAdd($arParams, $n, CRestServer $server)
static chatCalendarDelete($arParams, $n, CRestServer $server)
static promotionRead($arParams, $n, CRestServer $server)
static notifyAnswer($arParams, $n, CRestServer $server)
static userBusinessList($arParams, $offset, CRestServer $server)
static chatReminderAdd($arParams, $n, CRestServer $server)
static userList($arParams, $offset, CRestServer $server)
static chatReminderGet($arParams, $n, CRestServer $server)
static commandUnRegister($arParams, $n, CRestServer $server)
static chatPinAdd($arParams, $n, CRestServer $server)
static chatCalendarAdd($arParams, $n, CRestServer $server)
static commandRegister($arParams, $n, CRestServer $server)
static botMessageLike($arParams, $n, CRestServer $server)
static chatFavoriteDelete($arParams, $n, CRestServer $server)
static chatFavoriteAdd($arParams, $n, CRestServer $server)
static onBotMessageAdd($arParams, $arHandler)
static callUserRegister($params, $n, \CRestServer $server)
static mobileConfigGet($params, $n, \CRestServer $server)
static chatCreate($arParams, $n, CRestServer $server)
static diskFileCommit($arParams, $n, CRestServer $server)
static botSendTyping($arParams, $n, CRestServer $server)
static chatUrlGet($arParams, $n, CRestServer $server)
static chatParentJoin($arParams, $n, CRestServer $server)
static botUpdateTextFieldEnabled($arParams, $n, CRestServer $server)
static OnRestAppDelete($arParams)
static counterGet($arParams, $n, CRestServer $server)
static diskFolderListGet($arParams, $n, CRestServer $server)
static chatUpdateTitle($arParams, $n, CRestServer $server)
static callUserForceRename($params, $n, \CRestServer $server)
static promotionGet($arParams, $n, CRestServer $server)
static callChannelPublicList($params, $n, \CRestServer $server)
static departmentGet($arParams, $offset, CRestServer $server)
static chatSetOwner($arParams, $n, CRestServer $server)
static chatUpdateColor($arParams, $n, CRestServer $server)
static notifyGet($arParams, $n, CRestServer $server)
static departmentColleaguesList($arParams, $offset, CRestServer $server)
static videoconfPasswordCheck($params, $n, \CRestServer $server)
static messageShare($arParams, $n, CRestServer $server)
static objectEncode($data, $options=[])
static userStatusGet($params, $n, \CRestServer $server)
static recentPin($arParams, $n, CRestServer $server)
static chatUserDelete($arParams, $n, CRestServer $server)
static dialogVote($arParams, $offset, CRestServer $server)
static notifyReadAll($arParams, $n, CRestServer $server)
static chatUrlCounterGet($arParams, $n, CRestServer $server)
static appUpdate($arParams, $n, CRestServer $server)
static dialogWriting($arParams, $n, CRestServer $server)
static botRegister($arParams, $n, CRestServer $server)
static dialogUnread($arParams, $n, CRestServer $server)
static searchLastDelete($arParams, $n, CRestServer $server)
static chatUserAdd($arParams, $n, CRestServer $server)
static messageLike($arParams, $n, CRestServer $server)
static userGet($arParams, $n, CRestServer $server)
static searchUser($arParams, $offset, CRestServer $server)
static appRegister($arParams, $n, CRestServer $server)
static diskRecordShare($arParams, $n, CRestServer $server)
static chatUserList($arParams, $n, CRestServer $server)
static SetSetting($type, $value, $userId=false)
static Get($userId=false)
static setNavData($result, $dbRes)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
const SITE_DIR(!defined('LANG'))
htmlspecialcharsback($str)
GetMessage($name, $aReplace=null)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if(empty($decryptedData)) $storage
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
$GLOBALS['_____370096793']