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;
50 $this->userId =
$USER->GetID();
55 $this->userId = $userId;
60 $this->chatType = self::GROUP_CHAT;
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'))
106 if (!Loader::includeModule(
'socialservices'))
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
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,
228 'duration' => self::DEFAULT_DURATION_MINUTES,
231 'waiting_room' =>
'false',
232 'participant_video' =>
'true',
233 'host_video' =>
'true',
234 'join_before_host' =>
'true',
235 'approval_type' =>
"2",
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);
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]',
328 'NAME' => $chatData[
'NAME'],
331 $attach->AddChat($richChatData);
332 $attach->AddDelimiter([
'SIZE' => 300,
'COLOR' =>
'#c6c6c6']);
346 $attach->AddMessage(Loc::getMessage(
'IM_ZOOM_MESSAGE_JOIN_LINK'));
347 $attach->AddLink([
'LINK' => $link]);
353 private function prepareZoomChatName($dialogId): string
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;
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)