Conversation
Introduce Signal integration using signal-cli JSON-RPC: add Signal adapter (SignalMessage, SignalResponder, SignalRPC) and a signal_runner to process incoming commands and wire handlers/middlewares. Persist Signal users: add signal_user_id_seq and signal_users table/index in init_db.sql and implement DatabaseManager.get_or_create_signal_user. Add settings flags (ENABLE_SIGNAL, SIGNAL_PHONE_NUMBER, SIGNAL_CLI_PATH) and validation, and register the Signal platform in main.py. Also update PermissionLevelFactory to build middlewares by inspecting handler command lists. SignalRPC manages a subprocess with JSON-RPC, SignalResponder strips markdown and handles file cleanup; JSON responses are not supported by the responder.
Bump VERSION to 4.2.0 and refactor Signal adapter internals. - Converted many single-underscore attributes to double-underscore (name-mangled) for stronger encapsulation across SignalMessage, SignalResponder and SignalRPC. - Moved markdown stripping into SignalResponder as a private static method and made its regexes private. - Reworked SignalRPC lifecycle and I/O handling: track event handler tasks, validate started state in __call, use asyncio.get_running_loop() for futures, add timeout cleanup, create/track event tasks for incoming events, and set exceptions on pending futures if the connection closes. Stop now cancels and awaits event tasks before terminating the subprocess. - Minor change in signal_runner to ensure rpc.stop() is always awaited in finally (removed a no-op CancelledError catch). Overall these changes strengthen encapsulation and make the Signal RPC code more robust and resilient to process/IO shutdowns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request introduces support for the Signal messenger as a new platform for the bot, utilizing the
signal-clitool.Key changes introduced in this PR:
SignalRPCclass (bot/adapters/signal/signal_rpc.py) to handle asynchronous JSON-RPC communication with thesignal-cliprocess.SignalMessageandSignalResponder, implementingAbstractMessageandAbstractResponderrespectively, for seamless integration with the bot's core logic (handling text, Markdown, photos, videos, and documents).run_signal_bot(bot/platforms/signal_runner.py), which listens for incoming Signal events, identifies commands, and passes them through the middleware chain. Updatedmain.pyto initialize the platform when enabled.init_db.sqlby adding thesignal_userstable and an ID sequence. Added theget_or_create_signal_usermethod toDatabaseManager.settings.py): Expanded settings with theENABLE_SIGNALflag, as well asSIGNAL_PHONE_NUMBERandSIGNAL_CLI_PATHvariables. Added validation requiring a phone number if the Signal platform is active.VERSIONfrom 4.1.0 to 4.2.0.