21 private const CONFERENCE_INSTANT_TYPE = 1;
22 private const CONFERENCE_SCHEDULED_TYPE = 2;
23 private const DEFAULT_DURATION_MINUTES =
"30";
25 private const PERSONAL_CHAT =
'dialog';
26 private const GROUP_CHAT =
'chat';
32 private $zoomChatName;
48 if(is_object($USER) && $USER->IsAuthorized())
50 $this->userId = $USER->GetID();
55 $this->userId = $userId;
60 $this->chatType = self::GROUP_CHAT;
61 $this->chatId = \Bitrix\Im\Dialog::getChatId($chatId);
65 $this->chatType = self::PERSONAL_CHAT;
66 $this->chatId = $chatId;
69 $this->zoomChatName = $this->prepareZoomChatName($chatId);
74 $this->accessToken = $accessToken;
86 if (Loader::includeModule(
'socialservices'))
88 return (
new \CSocServAuthManager())->isActiveAuthService(
'zoom');
106 if (!Loader::includeModule(
'socialservices'))
111 if (\CZoomInterface::isConnected($userId))
127 if (!Loader::includeModule(
'bitrix24'))
132 return \Bitrix\Bitrix24\Feature::isFeatureEnabled(
"im_zoom_integration");
143 if (!Loader::includeModule(
'socialservices'))
148 $this->zoomSocServ = new \CSocServZoom($this->userId);
149 $this->zoomSocServ->getUrl(
'');
150 $accessToken = $this->zoomSocServ->getStorageToken();
152 if (!empty($accessToken))
168 $existedConf = $this->getExistedChatConference();
170 if (!is_array($existedConf) || (!empty($this->accessToken) && $this->isConferenceExpired($existedConf)))
172 $newConfResult = $this->requestNewChatConference();
173 if ($newConfResult->isSuccess())
175 $newConferenceData = $newConfResult->getData();
177 $confUrl = $newConferenceData[
'join_url'];
180 elseif (is_array($existedConf))
182 $confUrl = $existedConf[
'CONFERENCE_URL'];
188 private function getExistedChatConference(): ?array
190 if (Loader::includeModule(
'socialservices'))
192 $conf = ZoomMeetingTable::getList(array(
194 '=ENTITY_ID' => $this->chatId,
195 '=ENTITY_TYPE_ID' => $this->chatType,
197 'select' => [
'CONFERENCE_URL',
'CONFERENCE_EXTERNAL_ID'],
210 private function requestNewChatConference(): Result
212 $result =
new Result();
214 $startTime = (
new DateTime())
215 ->setTimeZone(
new \DateTimeZone(
'UTC'))
219 $randomSequence = new \Bitrix\Main\Type\RandomSequence($this->zoomChatName.$startTime);
220 $password = $randomSequence->randString(10);
223 'ENTITY_ID' => $this->chatId,
224 'ENTITY_TYPE_ID' => $this->chatType,
225 'topic' => $this->zoomChatName,
226 'type' => self::CONFERENCE_SCHEDULED_TYPE,
227 'start_time' => $startTime,
228 'duration' => self::DEFAULT_DURATION_MINUTES,
229 'password' => $password,
231 'waiting_room' =>
'false',
232 'participant_video' =>
'true',
233 'host_video' =>
'true',
234 'join_before_host' =>
'true',
235 'approval_type' =>
"2",
239 if ($this->zoomSocServ instanceof \CSocServZoom)
241 $createResult = $this->zoomSocServ->createConference($requestParams);
242 if (!$createResult->isSuccess())
244 return $result->addErrors($createResult->getErrors());
246 $conferenceData = $createResult->getData();
251 return $result->addError(
new Error(
'Could not create zoom instance'));
254 return $result->setData($conferenceData);
266 if ($this->zoomSocServ instanceof \CSocServZoom)
268 $conference = $this->zoomSocServ->getConferenceById($confId);
274 private function isConferenceExpired(array $confData): bool
276 $confId = $confData[
'CONFERENCE_EXTERNAL_ID'];
279 if (is_array($conference))
284 $meeting = ZoomMeetingTable::getRow([
286 '=CONFERENCE_EXTERNAL_ID' => $confId,
287 '=ENTITY_TYPE_ID' => $this->chatType,
292 if ($meeting !==
null)
294 ZoomMeetingTable::delete($meeting[
'ID']);
315 $attach = new \CIMMessageParamAttach(
null, \CIMMessageParamAttach::CHAT);
319 'URL_PREVIEW' =>
'N',
320 'MESSAGE' =>
'[B]'.Loc::getMessage(
'IM_ZOOM_MESSAGE_CONFERENCE_CREATED').
'[/B]',
326 $chatData = \Bitrix\Im\Chat::getById($chatId);
328 'NAME' => $chatData[
'NAME'],
331 $attach->AddChat($richChatData);
332 $attach->AddDelimiter([
'SIZE' => 300,
'COLOR' =>
'#c6c6c6']);
334 $messageFields[
'FROM_USER_ID'] = 0;
335 $messageFields[
'DIALOG_ID'] = $dialogId;
336 $messageFields[
'MESSAGE_TYPE'] = IM_MESSAGE_CHAT;
340 $messageFields[
'FROM_USER_ID'] = $userId;
341 $messageFields[
'TO_USER_ID'] = $dialogId;
342 $messageFields[
'TO_CHAT_ID'] = $chatId;
343 $messageFields[
'MESSAGE_TYPE'] = IM_MESSAGE_PRIVATE;
347 $attach->AddLink([
'LINK' => $link]);
348 $messageFields[
'ATTACH'] = $attach;
350 return $messageFields;
353 private function prepareZoomChatName($dialogId): string
358 $chatInfo = \Bitrix\Im\Chat::getById($this->chatId);
359 $zoomChatName =
"Bitrix24: " . $chatInfo[
'NAME'];
364 foreach ($chatUsers as $chatUser)
366 $usersLastNames[] = $chatUser[
"last_name"];
369 if (isset($usersLastNames))
371 $usersLastNames = implode(
" <-> ", $usersLastNames);
372 $zoomChatName =
"Bitrix24: ".$usersLastNames;
376 $zoomChatName =
"Bitrix24";
380 return $zoomChatName;
static getMessage($code, $replace=null, $language=null)