mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-10 20:17:02 +01:00
A "!cat" in a busy group produced a cat picture floating loose in the chat with
nothing tying it to whoever asked. Replies now quote the triggering message.
The container advertises this and always could: /v1/about reports
capabilities {"v2/send": ["quotes", "mentions"]}, and /v2/send takes
quote_timestamp, quote_author and quote_message. What was missing was on this
side -- parse_envelope discarded the envelope's timestamp, which is the id
Signal quotes a message by, so nothing downstream could have built a quote even
in principle. IncomingMessage now carries it, preferring the payload's own
value over the envelope's for the case where they ever disagree.
Quote is a value object rather than three more parameters threaded through
every send: the Transport protocol has five methods and two of them send.
CommandContext grows reply_image() so quoting lives in one place instead of
each handler reaching for ctx.transport itself, which is what animals.py did.
quote_of() returns None when the timestamp or author is missing. Answering the
room is a worse reply than a quoted one but a much better outcome than a
payload the container rejects.
The e2e gate learned to tell the two apart: Expectation.quotes demands a send
either does or does not point at a message, defaulting to None so the ten
existing scenarios stay indifferent. Without it the fake would have accepted an
unquoted reply as a pass.
Verified in the testbot group on a real Signal client before this bump, per
kuhy's rule that a bump is a publish rather than a checkpoint: he sent !cat and
confirmed the picture renders attached to his message as a reply.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015d48t4qsQLBJnDwDeo2Nom
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""Replying to the message that asked, rather than to the room."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from signal_bot.models import IncomingMessage, parse_envelope
|
|
from signal_bot.quoting import Quote, quote_of
|
|
from tests.conftest import envelope
|
|
|
|
|
|
def _message(
|
|
*,
|
|
source_uuid: str = "uuid-alice",
|
|
text: str | None = "!cat",
|
|
timestamp: int = 1719177917717,
|
|
) -> IncomingMessage:
|
|
return IncomingMessage(
|
|
source_uuid=source_uuid,
|
|
source_name="Alice",
|
|
group_id="group.one",
|
|
text=text,
|
|
has_sticker=False,
|
|
is_reaction=False,
|
|
timestamp=timestamp,
|
|
)
|
|
|
|
|
|
def test_payload_carries_the_three_keys_v2_send_wants() -> None:
|
|
assert Quote(17, "uuid-alice", "!cat").payload() == {
|
|
"quote_timestamp": 17,
|
|
"quote_author": "uuid-alice",
|
|
"quote_message": "!cat",
|
|
}
|
|
|
|
|
|
def test_a_real_envelope_can_be_quoted() -> None:
|
|
"""The timestamp used to be parsed away, which made this impossible."""
|
|
message = parse_envelope(envelope(text="!cat"))
|
|
assert message is not None
|
|
quote = quote_of(message)
|
|
assert quote == Quote(1719177917717, "uuid-alice", "!cat")
|
|
|
|
|
|
def test_a_message_with_no_timestamp_is_not_quoted() -> None:
|
|
"""Answering the room beats sending a payload the container rejects."""
|
|
assert quote_of(_message(timestamp=0)) is None
|
|
|
|
|
|
def test_a_message_with_no_author_is_not_quoted() -> None:
|
|
assert quote_of(_message(source_uuid="")) is None
|
|
|
|
|
|
def test_a_message_with_no_text_quotes_an_empty_body() -> None:
|
|
"""An image with no caption is still a message worth pointing at."""
|
|
quote = quote_of(_message(text=None))
|
|
assert quote is not None
|
|
assert quote.text == ""
|