Protocols
High-level interface definitions.
- class signal_bot_framework.protocol.PersonalityProto(*args, **kwargs)
Bases:
ProtocolDefines a “personality” that applies only to messages in specific contexts (e.g., in a specific group).
This
Protocolcontains shared functionality between aSignalBotinstance (a “root” personality) and individualsignal_bot_framework.personality.Personalityinstances. When a message is received, it is checked against any personalities’ callbacks first, then the root peronality’s callbacks.To use, create an instance of (or subclass)
Personalityand register it withSignalBot.add_personality().Not listed here are associated
remove_xxx(...)methods (e.g.,remove_cron()).- matches_context(context)
Whether this personality matches a given context.
- on_message(cb)
Register a callback to be called on any DataMessage.
- on_prefix(prefix, cb)
Register a callback to be called on any DataMessage matching a given prefix (exact match).
- on_cron(schedule, cb)
Register a callback to be called on a Cron schedule.
- on_mention(mention, cb)
Register a callback to be called when a given
AccountNumber/AccountUUIDis @-mentioned.- Parameters:
mention¶ (Union[
AccountNumber,AccountUUID]) – The Signal account to trigger on mentions of.
- Return type:
None
- on_keyword(keyword, cb, case_sensitive=False, whole_word=True)
Register a callback to be called when DataMessage contains a keyword.
- async started(signal)
Handle when
SignalBotis first started.
- abstract handle_callback_exception(exception, cb)
Personalities should implement this to handle when unhandled exceptions occur in a callback.
- class signal_bot_framework.protocol.SignalBot
Bases:
PersonalityProto,ProtocolThe high-level abstraction of
signal_bot_frameworkfunctionality.Implementation can be found in
signal_bot_framework._signal_impl. To create an instance, callsignal_bot_framework.create().- property account_number: AccountNumber
The currently registered Signal account.
- async send_reaction(to, emoji)
React to a previous message.
- Parameters:
to¶ (
DataMessage) – The message to react to.emoji¶ (
str) – The emoji to react with.
- Return type:
Future[Response]
- async send_typing(to, stop=False)
Start (or stop) the “Typing…” indicator.
When started, will display for 15 seconds unless stopped.
- Parameters:
to¶ (Union[
AccountNumber,AccountUUID,GroupID]) – The destination of the typing indicator (an individual or a group).stop¶ (
bool) – Stop (rather than start) the typing indicator.
- Return type:
Future[Response]
- async send_message(to, message=None, args=None)
Send a message.
- Parameters:
to¶ (Union[
AccountNumber,AccountUUID,GroupID]) – The destination of the message (an individual or a group).message¶ (
Optional[str]) – The textual message to send (if any).args¶ (
Optional[SendMessageArgs]) – Additional arguments tosend_message.
- Return type:
Future[Response]
- async delete_message(to, target_timestamp)
Delete a sent message (by timestamp).
- Parameters:
to¶ (Union[
AccountNumber,AccountUUID,GroupID]) – The destination (an individual or a group) in which to delete a message.target_timestamp¶ (
datetime) – The timestamp of the message to delete.
- Return type:
Future[Response]
- async run()
Start Cron callbacks and the message pump loop.
Runs until the transport raises
asyncio.CancelledError(e.g.,stop()is called).- Return type:
None
- async stop()
Stop the message pump loop (if running) and any scheduled Cron callbacks, in-flight requests, etc.
- Return type:
None
- add_personality(personality)
Add a sub-personality.
- Parameters:
personality¶ (
PersonalityProto) – ThePersonalityto add.- Return type:
None