Skip to content

Commit f002f80

Browse files
committed
BitrixPolicySender
1 parent 7a567b6 commit f002f80

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
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 Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\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 Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\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+
}

Services/Email/EventBridge/Sender/BitrixPolicySender.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Bitrix\Main\ObjectPropertyException;
77
use Bitrix\Main\SystemException;
88
use Proklung\Notifier\Bitrix\EventBridgeMail;
9+
use Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\Notifier\BitrixNotification;
910
use Proklung\Notifier\Bitrix\Utils\EventTableUpdater;
1011
use Symfony\Component\Notifier\Notification\Notification;
1112
use Symfony\Component\Notifier\NotifierInterface;
@@ -69,7 +70,7 @@ public function send(string $codeEvent, array $arFields, string $importance) : v
6970
foreach ($eventsInfo as $eventInfo) {
7071
$compileData = $this->eventBridge->compileMessage($eventInfo, $arFields, ['s1']);
7172

72-
$notification = (new Notification($compileData['subject']))
73+
$notification = (new BitrixNotification($compileData['subject']))
7374
->content($compileData['body'])
7475
->importance($importance);
7576

readme.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ monolog:
9292

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

95+
При условии `channel_policy` в конфиге `framework.yaml`:
96+
97+
```yaml
98+
'channel_policy':
99+
medium: ['email', 'chat/telegram'],
100+
```
101+
95102
```php
96103
use Prokl\BitrixOrdinaryToolsBundle\Services\Email\EventBridge\Sender\BitrixPolicySender;
97104
use Symfony\Component\Notifier\Notification\Notification;;

0 commit comments

Comments
 (0)