mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-11 12:57:32 +01:00
Per-person photo commands, where the mechanism is public and the album is not. Nothing identifying is in this repository: who the people are, what fires their photos and which file shows whom all live in one directory outside it, and the tests, the docs and the offline e2e run use three invented people instead. Several names in one message intersect -- "!alfa beta" is a photo with both -- and where an entry offers a choice the bot picks among the readings that actually have a photo, so a question the album could answer is not refused. A combination nobody photographed gets one line rather than silence, which from the group's side is indistinguishable from a broken bot. Scoping is enforced in the dispatcher, not in the handler: a command the group is not allowed resolves to nothing, so it is not answered, not counted as a command, and never named in a log line outside its own groups. A handler that quietly returned would leak all three. Commands are named by pseudonym (pack:p1), so the journal and command_uses say somebody asked for a photo and nothing about whose. Video works: the attachment goes out as data:video/mp4;filename=...;base64, which is the container's own spelling, read off its /swagger/doc.json. Told it is a photo, Signal renders a clip as an unplayable file. tool/tagger.py serves one page on loopback to fill the album in -- names are typed into the page, never as arguments, and it prints how many photos each command would have when it stops, because a command with zero is dead on arrival. Also renames the real people who were still sitting in the stats test fixtures. They remain in the history; the point is that nothing new is added to it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017w1HZ3cZ7neL3rFdQ6VMBA
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""The seam between the bot and Signal.
|
|
|
|
Everything above this interface is transport-agnostic, which is what lets the
|
|
same bot code run against the real signal-cli-rest-api container and against
|
|
the local fake used by the tests and the end-to-end script.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Protocol, runtime_checkable
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import AsyncIterator
|
|
|
|
from signal_bot.quoting import Quote
|
|
|
|
|
|
@runtime_checkable
|
|
class Transport(Protocol):
|
|
"""What the bot needs from a Signal backend."""
|
|
|
|
def receive(self) -> AsyncIterator[str]:
|
|
"""Yield raw envelope frames until the transport is closed."""
|
|
|
|
async def send_text(self, text: str, recipient: str, quote: Quote | None = None) -> None:
|
|
"""Send a plain-text message, optionally quoting one message."""
|
|
|
|
async def send_image(
|
|
self,
|
|
image_base64: str,
|
|
recipient: str,
|
|
quote: Quote | None = None,
|
|
caption: str = "",
|
|
) -> None:
|
|
"""Send an image attachment, optionally captioned and quoting a message.
|
|
|
|
/v2/send carries the caption in the same payload as the attachment, so
|
|
a captioned photo is one message in the group rather than two.
|
|
"""
|
|
|
|
async def send_media(
|
|
self,
|
|
payload_base64: str,
|
|
recipient: str,
|
|
quote: Quote | None = None,
|
|
caption: str = "",
|
|
media_type: str = "",
|
|
filename: str = "",
|
|
) -> None:
|
|
"""Send an attachment of a stated type, optionally captioned.
|
|
|
|
send_image is the case where the type can be left to signal-cli.
|
|
Anything Signal renders differently -- a video, above all -- has to
|
|
say what it is, or it arrives as an unplayable blob.
|
|
"""
|
|
|
|
async def list_attachments(self) -> list[str]:
|
|
"""Return the ids of attachments stored server-side."""
|
|
|
|
async def delete_attachment(self, attachment_id: str) -> None:
|
|
"""Delete one stored attachment by id."""
|