signalbot icon indicating copy to clipboard operation
signalbot copied to clipboard

feature request: enabling http instead of https in Bot config

Open NemoDacremont opened this issue 5 months ago • 2 comments

We were trying to use the framework to send messages on signal, but because it was not really about creating a bot replying to commands, we did not use the bot.start() method. More precisely, we're only using the bot.send() method. I guess this is the reason why it was trying to use https instead of http to connect to the signal-cli API.

Maybe this is not really the scope of the project, however I think it would be better to be able to configure the use of SSL or not in the configuration, with SSL enabled by default.

For now, I use the following workaround, but it is not really satisfying :

config = {
    "signal_service": signal_service,
    "phone_number": phone_number
}
self.bot = SignalBot(config)
self.bot._signal._signal_api_uris.use_https = False

Reproduce the SSL error

First, setup the docker as presented in the README, with a docker command like this one :

docker run \
    --rm \
    -p 8080:8080 \
    -v $(pwd)/signal-cli-config:/home/.local/share/signal-cli \
    -e 'MODE=json-rpc' bbernhard/signal-cli-rest-api:latest

Then in a python file :

if __name__ == "__main__":
        signal_service = "127.0.0.1:8080"
        phone_number = "[REDACTED]"

        config = {
            "signal_service": signal_service,
            "phone_number": phone_number
        }
        bot = SignalBot(config)
        asyncio.run(bot.send(receiver=phone_number, text="will it work?"))

This should log something like that :

[Bot] Could not initialize Redis and no SQLite DB name was given. In-memory storage will be used. Restarting will delete the storage! Add storage: {'type': 'in-memory'} to the config to silence this error.
Traceback (most recent call last):
  File "/home/ndacremont/Documents/Cours/3A/osint/venv/lib/python3.13/site-packages/aiohttp/connector.py", line 1283, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs, sock=sock)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 1201, in create_connection
    transport, protocol = await self._create_connection_transport(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        ssl_shutdown_timeout=ssl_shutdown_timeout)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 1234, in _create_connection_transport
    await waiter
  File "/usr/lib/python3.13/asyncio/sslproto.py", line 581, in _on_handshake_complete
    raise handshake_exc
  File "/usr/lib/python3.13/asyncio/sslproto.py", line 563, in _do_handshake
    self._sslobj.do_handshake()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/ssl.py", line 951, in do_handshake
    self._sslobj.do_handshake()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
ssl.SSLError: [SSL] record layer failure (_ssl.c:1032)

The above exception was the direct cause of the following exception:

...

NemoDacremont avatar Nov 03 '25 20:11 NemoDacremont

The error happens because the bot is not properly initialised, would it work for your use case to do this?

if __name__ == "__main__":
  signal_service = "127.0.0.1:8080"
  phone_number = "[REDACTED]"
  
  config = {
      "signal_service": signal_service,
      "phone_number": phone_number
  }
  bot = SignalBot(config)
  
  async def send(repeat = False):
      await asyncio.sleep(1) # Wait for bot intialisation
      await bot.send(receiver="<Number>", text="will it work?")
  
  bot.scheduler.add_job(send)
  bot.start()

Also now that you can call the start method with run_forever = False so that you have full control over the event loop.

Era-Dorta avatar Nov 04 '25 19:11 Era-Dorta

Sorry for the late response, I'll test it soon, thanks for your reply.

NemoDacremont avatar Nov 09 '25 22:11 NemoDacremont