3namespace Bitrix\Calendar\Sharing\Notification;
5use Bitrix\Calendar\Sharing;
7use Bitrix\Notifications;
8use Bitrix\Main\PhoneNumber;
12 private const ALLOWED_COUNTRY_CODES = [
'ru'];
14 private const TEMPLATE_Q =
'SHARING_EVENT_INVITE';
15 private const TEMPLATE_Y =
'SHARING_EVENT_ACCEPTED';
16 private const TEMPLATE_N =
'SHARING_EVENT_DECLINED';
17 private const TEMPLATE_N_NO_LINK =
'SHARING_EVENT_DECLINED_2';
18 private const TEMPLATE_CRM_SHARING_AUTO_ACCEPTED =
'CRM_SHARING_AUTO_ACCEPTED';
29 if (\CCalendar::IsBitrix24() && in_array(\CBitrix24::getPortalZone(), self::ALLOWED_COUNTRY_CODES))
34 if (!Loader::includeModule(
'notifications'))
39 return Notifications\Account::isServiceAvailable() && Notifications\Account::isConnected();
48 if ($this->initiatorId === $this->eventLink->getHostId())
56 if ($templateCode === self::TEMPLATE_N)
59 if (is_null($calendarLink))
61 $templateCode = self::TEMPLATE_N_NO_LINK;
64 $placeholders = $this->
getPlaceholders($templateCode, $owner, $calendarLink);
66 return $this->
sendMessage($to, $templateCode, $placeholders);
92 return $this->
sendMessage($to, self::TEMPLATE_CRM_SHARING_AUTO_ACCEPTED, $placeholders);
101 protected function sendMessage(
string $phoneNumber,
string $templateCode,
array $placeholders): bool
103 if (!self::includeNotificationsModule())
109 $countryCode = mb_strtolower($parsedPhone->getCountry());
110 if (!$parsedPhone->isValid() || in_array($countryCode, self::ALLOWED_COUNTRY_CODES,
true))
116 return Notifications\Model\Message::create([
117 'PHONE_NUMBER' => $phoneNumberE164,
118 'TEMPLATE_CODE' => $templateCode,
119 'LANGUAGE_ID' => LANGUAGE_ID,
120 'PLACEHOLDERS' => $placeholders,
121 ])->enqueue()->isSuccess();
130 $templateCode = self::TEMPLATE_Q;
132 if ($owner[
'STATUS'] ===
'Y')
134 $templateCode = self::TEMPLATE_Y;
137 if ($owner[
'STATUS'] ===
'N')
139 $templateCode = self::TEMPLATE_N;
142 return $templateCode;
155 $calendarOwner = $owner[
'NAME'];
158 if ($templateCode === self::TEMPLATE_Q)
161 'EVENT_NAME' => $eventName,
162 'DATE' => $eventDateTime,
163 'NAME' => $calendarOwner,
168 if ($templateCode === self::TEMPLATE_Y)
171 'EVENT_NAME' => $eventName,
172 'DATE' => $eventDateTime,
173 'NAME' => $calendarOwner,
178 if ($templateCode === self::TEMPLATE_N)
181 'EVENT_NAME' => $eventName,
182 'DATE' => $eventDateTime,
183 'NAME' => $calendarOwner,
184 'URL' => $calendarLink,
188 if ($templateCode === self::TEMPLATE_N_NO_LINK)
191 'EVENT_NAME' => $eventName,
192 'DATE' => $eventDateTime,
193 'NAME' => $calendarOwner,
206 if (!is_null($calendarLink))
static formatDate(Date $date)
static getOwnerInfo(int $id)
static formatDateShort(Date $date)
static getShortUrl(string $url)
static getPersonFullNameLoc(?string $name, ?string $lastName)
sendCrmSharingAutoAccepted(string $to)
sendMessage(string $phoneNumber, string $templateCode, array $placeholders)
notifyAboutSharingEventEdit(string $to)
getPlaceholders(string $templateCode, array $owner, ?string $calendarLink)
notifyAboutMeetingStatus(string $to)
getTemplateCode(array $owner)
static includeNotificationsModule()
getEventFormattedDateTime()
static getSharingEventNameByUserName(?string $userName)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)