Skip to content

Commit e48a1ca

Browse files
committed
При отправке в Телеграм битриксовый шаблон превращается в markdown
1 parent 2b6301d commit e48a1ca

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"symfony/twig-bridge": "^4.4 || ^5",
5050
"proklung/bitrix-containerable-boilerplate": "^1.0",
5151
"proklung/bitrix.module.boilerplate": "^1.0",
52+
"league/html-to-markdown": "^5.0",
5253
"ext-json": "*"
5354
},
5455
"require-dev": {

lib/Bitrix/Sender/BitrixTelegramEventSender.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Bitrix\Main\ArgumentException;
66
use Bitrix\Main\ObjectPropertyException;
77
use Bitrix\Main\SystemException;
8+
use League\HTMLToMarkdown\HtmlConverter;
89
use Proklung\Notifier\Bitrix\EventBridgeMail;
910
use Proklung\Notifier\Bitrix\Utils\EventTableUpdater;
1011
use RuntimeException;
@@ -83,8 +84,13 @@ public function send(string $codeEvent, array $arFields) : void
8384
foreach ($eventsInfo as $eventInfo) {
8485
$compileData = $this->eventBridge->compileMessage($eventInfo, $arFields, ['s1']);
8586

86-
$notification = (new ChatMessage($compileData['subject'] . ' ' . $compileData['body']))
87-
->transport('telegram');
87+
$content = $compileData['subject'] . ' ' . $compileData['body'];
88+
89+
$converter = new HtmlConverter(['remove_nodes' => 'span div']);
90+
$markdown = $converter->convert($content);
91+
92+
$notification = (new ChatMessage($markdown))
93+
->transport('telegram');
8894

8995
$telegramOptions = (new TelegramOptions())
9096
->parseMode('Markdown')
@@ -99,4 +105,4 @@ public function send(string $codeEvent, array $arFields) : void
99105
EventTableUpdater::create($eventInfo->getEventCode(), $eventInfo->getMessageData(), 99999);
100106
}
101107
}
102-
}
108+
}

readme.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,5 @@ return [
245245

246246
Нюанс:
247247

248-
- Telegram плохо переваривает html (даже в режиме `parse_mode = html`). Посему рекомендуется оформлять шаблоны
249-
в `markdown` разметке.
248+
- Telegram плохо переваривает html (даже в режиме `parse_mode = html`). Посему под капотом html шаблона превращается в markdown
249+
разметку.

0 commit comments

Comments
 (0)