mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
feat(gateway): add Telegram adapter and formatting
This commit is contained in:
parent
c9b7d7b572
commit
59e6475348
5 changed files with 298 additions and 0 deletions
18
surfsense_backend/tests/unit/gateway/test_formatting.py
Normal file
18
surfsense_backend/tests/unit/gateway/test_formatting.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from app.gateway.telegram.formatting import chunk_message, escape_markdown_v2
|
||||
|
||||
|
||||
def test_escape_markdown_v2_reserved_chars():
|
||||
text = r"_*[]()~`>#+-=|{}.!"
|
||||
|
||||
assert escape_markdown_v2(text) == r"\_\*\[\]\(\)\~\`\>\#\+\-\=\|\{\}\.\!"
|
||||
|
||||
|
||||
def test_chunk_message_preserves_content_and_limits_size():
|
||||
text = "First paragraph.\n\n" + ("x" * 5000)
|
||||
|
||||
chunks = chunk_message(text, max_units=4096)
|
||||
|
||||
assert "".join(chunks) == text
|
||||
assert len(chunks) > 1
|
||||
assert all(len(chunk.encode("utf-16-le")) // 2 <= 4096 for chunk in chunks)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue