fix: route Telegram DM topic deliveries directly

(cherry picked from commit ad8f97db6c)
This commit is contained in:
stepanov1975
2026-05-25 14:54:02 -07:00
committed by Teknium
parent 0dee92df22
commit 415be55394
4 changed files with 140 additions and 20 deletions
+9 -12
View File
@@ -388,7 +388,7 @@ async def test_send_retries_without_thread_on_thread_not_found():
adapter._bot = SimpleNamespace(send_message=mock_send_message)
result = await adapter.send(
chat_id="123",
chat_id="-100123",
content="test message",
metadata={"thread_id": "99999"},
)
@@ -716,16 +716,14 @@ async def test_send_dm_topic_fallback_without_anchor_does_not_crash():
@pytest.mark.asyncio
async def test_send_dm_topic_reply_not_found_retry_drops_thread_id():
"""If Telegram deletes the reply anchor, private-topic retry must drop thread id too."""
async def test_send_dm_topic_reply_not_found_fails_closed():
"""If Telegram deletes the reply anchor, private-topic sends must not fall back elsewhere."""
adapter = _make_adapter()
call_log = []
async def mock_send_message(**kwargs):
call_log.append(dict(kwargs))
if len(call_log) == 1:
raise FakeBadRequest("Message to be replied not found")
return SimpleNamespace(message_id=781)
raise FakeBadRequest("Message to be replied not found")
adapter._bot = SimpleNamespace(send_message=mock_send_message)
@@ -739,12 +737,11 @@ async def test_send_dm_topic_reply_not_found_retry_drops_thread_id():
},
)
assert result.success is True
assert result.success is False
assert result.retryable is False
assert call_log[0]["reply_to_message_id"] == 462
assert call_log[0]["message_thread_id"] == 20197
assert call_log[1]["reply_to_message_id"] is None
assert "message_thread_id" not in call_log[1]
assert "direct_messages_topic_id" not in call_log[1]
assert len(call_log) == 1
@pytest.mark.asyncio
@@ -1085,7 +1082,7 @@ async def test_send_raises_on_other_bad_request():
adapter._bot = SimpleNamespace(send_message=mock_send_message)
result = await adapter.send(
chat_id="123",
chat_id="-100123",
content="test message",
metadata={"thread_id": "99999"},
)
@@ -1246,7 +1243,7 @@ async def test_thread_fallback_only_fires_once():
# Send a long message that gets split into chunks
long_msg = "A" * 5000 # Exceeds Telegram's 4096 limit
result = await adapter.send(
chat_id="123",
chat_id="-100123",
content=long_msg,
metadata={"thread_id": "99999"},
)