Skip to content

Context

Context

Context(bot: SignalBot, message: Message)

Context is a helper class that provides methods to reply, edit, react, etc. to a message. This is useful to avoid having to pass the recipient and other arguments to the bot's methods manually.

Source code in src/signalbot/context.py
19
20
21
def __init__(self, bot: SignalBot, message: Message) -> None:
    self.bot = bot
    self.message = message

edit async

edit(
    text: str,
    edit_timestamp: int,
    *,
    base64_attachments: list[str] | None = None,
    link_preview: LinkPreview | None = None,
    mentions: list[dict[str, Any]] | None = None,
    text_mode: str | None = None,
    view_once: bool = False,
) -> int

Same as signalbot.SignalBot.send() but with the recipient and timestamp set to the message's.

Source code in src/signalbot/context.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
async def edit(  # noqa: PLR0913
    self,
    text: str,
    edit_timestamp: int,
    *,
    base64_attachments: list[str] | None = None,
    link_preview: LinkPreview | None = None,
    mentions: list[dict[str, Any]] | None = None,
    text_mode: str | None = None,
    view_once: bool = False,
) -> int:
    """Same as
     [signalbot.SignalBot.send()](bot.md#signalbot.SignalBot.send)
    but with the recipient and timestamp set to the message's."""
    return await self.bot.send(
        self.message.recipient(),
        text,
        base64_attachments=base64_attachments,
        mentions=mentions,
        text_mode=text_mode,
        edit_timestamp=edit_timestamp,
        link_preview=link_preview,
        view_once=view_once,
    )

react async

react(emoji: str) -> None

Same as signalbot.SignalBot.react() but with the recipient set to the message's recipient.

Source code in src/signalbot/context.py
103
104
105
106
107
async def react(self, emoji: str) -> None:
    """Same as
     [signalbot.SignalBot.react()](bot.md#signalbot.SignalBot.react)
    but with the recipient set to the message's recipient."""
    await self.bot.react(self.message, emoji)

receipt async

receipt(receipt_type: Literal['read', 'viewed']) -> None

Same as signalbot.SignalBot.receipt() but with the recipient set to the message's recipient.

Source code in src/signalbot/context.py
109
110
111
112
113
async def receipt(self, receipt_type: Literal["read", "viewed"]) -> None:
    """Same as
     [signalbot.SignalBot.receipt()](bot.md#signalbot.SignalBot.receipt)
    but with the recipient set to the message's recipient."""
    await self.bot.receipt(self.message, receipt_type)

remote_delete async

remote_delete(timestamp: int) -> int

Same as signalbot.SignalBot.remote_delete() but with the recipient and timestamp set to the message's.

Source code in src/signalbot/context.py
127
128
129
130
131
132
133
async def remote_delete(self, timestamp: int) -> int:
    """Same as
    [signalbot.SignalBot.remote_delete()](bot.md#signalbot.SignalBot.remote_delete)
    but with the recipient and timestamp set to the message's."""
    return await self.bot.remote_delete(
        self.message.recipient(), timestamp=timestamp
    )

reply async

reply(
    text: str,
    *,
    base64_attachments: list[str] | None = None,
    link_preview: LinkPreview | None = None,
    mentions: list[dict[str, Any]] | None = None,
    text_mode: str | None = None,
    view_once: bool = False,
) -> int

Same as signalbot.SignalBot.send() but with the quote arguments set to the message's.

Source code in src/signalbot/context.py
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
async def reply(  # noqa: PLR0913
    self,
    text: str,
    *,
    base64_attachments: list[str] | None = None,
    link_preview: LinkPreview | None = None,
    mentions: (
        list[dict[str, Any]] | None
    ) = None,  # [{ "author": "uuid" , "start": 0, "length": 1 }]
    text_mode: str | None = None,
    view_once: bool = False,
) -> int:
    """Same as
     [signalbot.SignalBot.send()](bot.md#signalbot.SignalBot.send)
    but with the quote arguments set to the message's."""
    send_mentions = self._convert_receive_mentions_into_send_mentions(
        self.message.mentions,
    )
    return await self.bot.send(
        self.message.recipient(),
        text,
        base64_attachments=base64_attachments,
        quote_author=self.message.source,
        quote_mentions=send_mentions,
        quote_message=self.message.text,
        quote_timestamp=self.message.timestamp,
        mentions=mentions,
        text_mode=text_mode,
        link_preview=link_preview,
        view_once=view_once,
    )

send async

send(
    text: str,
    *,
    base64_attachments: list[str] | None = None,
    link_preview: LinkPreview | None = None,
    mentions: list[dict[str, Any]] | None = None,
    text_mode: str | None = None,
    view_once: bool = False,
) -> int

Same as signalbot.SignalBot.send() but with the recipient set to the message's recipient.

Source code in src/signalbot/context.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
async def send(  # noqa: PLR0913
    self,
    text: str,
    *,
    base64_attachments: list[str] | None = None,
    link_preview: LinkPreview | None = None,
    mentions: list[dict[str, Any]] | None = None,
    text_mode: str | None = None,
    view_once: bool = False,
) -> int:
    """Same as
     [signalbot.SignalBot.send()](bot.md#signalbot.SignalBot.send)
    but with the recipient set to the message's recipient."""
    return await self.bot.send(
        self.message.recipient(),
        text,
        base64_attachments=base64_attachments,
        mentions=mentions,
        text_mode=text_mode,
        link_preview=link_preview,
        view_once=view_once,
    )

start_typing async

start_typing() -> None

Same as signalbot.SignalBot.start_typing() but with the recipient set to the message's recipient.

Source code in src/signalbot/context.py
115
116
117
118
119
async def start_typing(self) -> None:
    """Same as
    [signalbot.SignalBot.start_typing()](bot.md#signalbot.SignalBot.start_typing)
     but with the recipient set to the message's recipient."""
    await self.bot.start_typing(self.message.recipient())

stop_typing async

stop_typing() -> None

Same as signalbot.SignalBot.stop_typing() but with the recipient set to the message's recipient.

Source code in src/signalbot/context.py
121
122
123
124
125
async def stop_typing(self) -> None:
    """Same as
    [signalbot.SignalBot.stop_typing()](bot.md#signalbot.SignalBot.stop_typing)
     but with the recipient set to the message's recipient."""
    await self.bot.stop_typing(self.message.recipient())