Skip to content

Commit 660869f

Browse files
committed
BitrixPolicySender. Доработки.
1 parent f8224eb commit 660869f

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Proklung\Notifier\Bitrix\Notifier;
4+
5+
use League\HTMLToMarkdown\HtmlConverter;
6+
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
7+
use Symfony\Component\Notifier\Message\ChatMessage;
8+
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
9+
use Symfony\Component\Notifier\Notification\Notification;
10+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
11+
12+
/**
13+
* Class BitrixNotifier
14+
* @package Proklung\Notifier\Bitrix\Notifier
15+
*/
16+
class BitrixNotification extends Notification implements ChatNotificationInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
22+
{
23+
if ('telegram' === $transport) {
24+
$content = $this->getSubject() . ' ' . $this->getContent();
25+
26+
$converter = new HtmlConverter(['remove_nodes' => 'span div']);
27+
$markdown = $converter->convert($content);
28+
29+
$telegramOptions = (new TelegramOptions())
30+
->parseMode('Markdown')
31+
->disableWebPagePreview(true)
32+
->disableNotification(false);
33+
34+
return (new ChatMessage($markdown, $telegramOptions));
35+
}
36+
37+
return null;
38+
}
39+
}

lib/Bitrix/Sender/BitrixPolicySender.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Bitrix\Main\ObjectPropertyException;
77
use Bitrix\Main\SystemException;
88
use Proklung\Notifier\Bitrix\EventBridgeMail;
9+
use Proklung\Notifier\Bitrix\Notifier\BitrixNotification;
910
use Proklung\Notifier\Bitrix\Utils\EventTableUpdater;
10-
use Symfony\Component\Notifier\Notification\Notification;
1111
use Symfony\Component\Notifier\NotifierInterface;
1212
use Symfony\Component\Notifier\Recipient\Recipient;
1313

@@ -69,7 +69,7 @@ public function send(string $codeEvent, array $arFields, string $importance) : v
6969
foreach ($eventsInfo as $eventInfo) {
7070
$compileData = $this->eventBridge->compileMessage($eventInfo, $arFields, ['s1']);
7171

72-
$notification = (new Notification($compileData['subject']))
72+
$notification = (new BitrixNotification($compileData['subject']))
7373
->content($compileData['body'])
7474
->importance($importance);
7575

readme.MD

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ return [
206206

207207
### Отправка битриксового события согласно channel_policy
208208

209+
При условии `channel_policy` в `/bitrix/,settings.php`:
210+
211+
```php
212+
'channel_policy' => [
213+
//...
214+
'medium' => ['email', 'chat/telegram'],
215+
//...
216+
],
217+
```
218+
209219
```php
210220
use Proklung\Notifier\Bitrix\Sender\BitrixPolicySender;
211221
use Symfony\Component\Notifier\Notification\Notification;;
@@ -219,7 +229,7 @@ return [
219229
// См. https://dev.1c-bitrix.ru/api_help/main/reference/cevent/send.php
220230
$arFields = ['NAME' => 'testing email', 'EMAIL' => 'recipitient@gmail.com'];
221231

222-
// Будет оправлено сообщение в канал email и сделана запись в таблице b_event.
232+
// Будет оправлено сообщение в канал email и telegram, а также сделана запись в таблице b_event.
223233
$bitrixEventHandler->send('CODE_MAIL_EVENT', $arFields, Notification::IMPORTANCE_MEDIUM);
224234
```
225235

0 commit comments

Comments
 (0)