Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable a chat command for one specific group doesn't seem to be working. #43

Open
AlimFreight opened this issue Jan 18, 2024 · 11 comments

Comments

@AlimFreight
Copy link

Enabling a chat command for one specific group doesn't seem to be working. When I use it, I don't receive any messages from that group for the command to which it was applied.
When I enable groups=True everything working just fine.

@filipre
Copy link
Owner

filipre commented Jan 18, 2024

can you share how you are using groups by obfuscating the string?

@AlimFreight
Copy link
Author

AlimFreight commented Jan 18, 2024

I just use your example, where I changed name of group to existing one:
bot.register(PingCommand(), contacts=False, groups=["Test GROUP"]

After that I have any response till I change it to groups=True

Here is response from curl -X GET 'https://mysignalapi.com/v1/groups/regirestedPhone' | python -m json.tool

{ "name": "Test GROUP", "id": "group.OCt1ZkRvMW=", "internal_id": "8+ufDo1lg2X7I4=", "members": [ "+4999999360", "+4987654630" ], "blocked": false, "pending_invites": [], "pending_requests": [], "invite_link": "", "admins": [ "+4987654630" ] }

INFO:root:[Bot] Producer #1 started
INFO:root:[Bot] Consumer #1 started
INFO:root:[Bot] Consumer #2 started
INFO:root:[Bot] Consumer #3 started
INFO:root:[Bot] 2 groups detected`

Here is the log

INFO:root:[Raw Message] {"envelope":{"source":"+4987654630","sourceNumber":"+4987654630","sourceUuid":"4c0bfb15-e2fa-","sourceName":"User Imaginary","sourceDevice":1,"timestamp":1705591726026,"typingMessage":{"action":"STARTED","timestamp":1705591726026,"groupId":"8+ufDo1lg2X7I4QtqzRI="}},"account":"+4987654630"}
INFO:root:[Raw Message] {"envelope":{"source":"+4987654630","sourceNumber":"+4987654630","sourceUuid":"4c0bfb15-e2fa-4765-b852-","sourceName":"User Imaginary","sourceDevice":1,"timestamp":1705591728499,"dataMessage":{"timestamp":1705591728499,"message":"PING","expiresInSeconds":0,"viewOnce":false,"groupInfo":{"groupId":"8+ufDo1lg2X7I4QtqzRskUN","type":"DELIVER"}}},"account":"+4999999360"}
INFO:root:[Bot] Consumer #1 got new job in 0.00012 seconds
INFO:root:[Bot] Consumer #1 got new job in 0.00030 seconds
INFO:root:[Bot] Consumer #1 got new job in 0.00034 seconds
INFO:root:[Bot] Consumer #1 got new job in 0.00038 seconds
INFO:root:[Raw Message] {"envelope":{"source":"+4987654630","sourceNumber":"+4987654630","sourceUuid":"4c0bfb15-e2fa-4765-b852-","sourceName":"User Imaginary","sourceDevice":1,"timestamp":1705591730330,"typingMessage":{"action":"STOPPED","timestamp":1705591730330,"groupId":"8+ufDo1lg2X7I4QtqzRskUN"}},"account":"+4999999360"}

@filipre
Copy link
Owner

filipre commented Jan 18, 2024

just to make sure, on what version of the framework are you?

@AlimFreight
Copy link
Author

On 0.9.2 I just installed it yesterday.

@filipre
Copy link
Owner

filipre commented Jan 18, 2024

"message":"PING"

Oh, can you try typing ping? The command is not performing any string manipulation, see https://github.com/filipre/signalbot/blob/master/example/commands/ping.py#L11

@AlimFreight
Copy link
Author

AlimFreight commented Jan 18, 2024

Oh I forgot to say that I changed Command:

    def describe(self) -> str:
        return "🏓 Ping Command: Listen for a ping"

    @triggered("Ping")
    async def handle(self, c: Context):
        await c.send("`Pong`", text_mode="styled")

But anypingcommand doesn't work until I switch to groups=True

@filipre
Copy link
Owner

filipre commented Jan 18, 2024

got it. I'll try to reproduce it but it may take a while. Maybe there is something wrong with the current way group names are resolved in the current version. groups=["Test GROUP"] looks fine to me.

@AlimFreight
Copy link
Author

got it. I'll try to reproduce it but it may take a while. Maybe there is something wrong with the current way group names are resolved in the current version. groups=["Test GROUP"] looks fine to me.

Ok sounds good, as I faced this issue I eventually tried contacts["+4965847363"] to find out it does't work as well.

@musspi
Copy link

musspi commented Apr 19, 2024

I may have more context on this.

I also face the issue of not receiving messages from groups.
I am using signalbot v0.9.2 and signal-cli-rest-api v0.83 (latest as of today).

I am registering the Ping command like this
bot.register(PingCommand(), contacts=False, groups=[group_id])
where group_id is a string of this format: group.<OMMITED_CHARS>

And the logs reveal the following exception:

INFO:root:[Bot] Producer #1 started
INFO:root:[Bot] Consumer #1 started
INFO:root:[Bot] Consumer #2 started
INFO:root:[Bot] Consumer #3 started
DEBUG:websockets.client:= connection is CONNECTING
DEBUG:websockets.client:> GET /v1/receive/<OMITTED> HTTP/1.1
DEBUG:websockets.client:> Host: 127.0.0.1:3010
DEBUG:websockets.client:> Upgrade: websocket
DEBUG:websockets.client:> Connection: Upgrade
DEBUG:websockets.client:> Sec-WebSocket-Key: <OMITTED>
DEBUG:websockets.client:> Sec-WebSocket-Version: 13
DEBUG:websockets.client:> Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
DEBUG:websockets.client:> User-Agent: Python/3.10 websockets/10.4
DEBUG:websockets.client:! failing connection with code 1006
DEBUG:websockets.client:= connection is CLOSED
DEBUG:websockets.client:x half-closing TCP connection
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-1' coro=<SignalBot._detect_groups() done, defined at /usr/local/lib/python3.10/site-packages/signalbot/bot.py:225> exception=GroupsError()>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/signalbot/api.py", line 132, in get_groups
    resp = await session.get(uri)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 605, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 966, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "/usr/local/lib/python3.10/site-packages/aiohttp/streams.py", line 622, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/signalbot/bot.py", line 227, in _detect_groups
    self.groups = await self._signal.get_groups()
  File "/usr/local/lib/python3.10/site-packages/signalbot/api.py", line 139, in get_groups
    raise GroupsError
signalbot.api.GroupsError
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/http.py", line 120, in read_response
    status_line = await read_line(stream)
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/http.py", line 200, in read_line
    raise EOFError("line without CRLF")
EOFError: line without CRLF

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 138, in read_http_response
    status_code, reason, headers = await read_response(self.reader)
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/http.py", line 122, in read_response
    raise EOFError("connection closed while reading HTTP status line") from exc
EOFError: connection closed while reading HTTP status line

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/signalbot/api.py", line 20, in receive
    async with self.connection as websocket:
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 642, in __aenter__
    return await self
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 659, in __await_impl_timeout__
    return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 666, in __await_impl__
    await protocol.handshake(
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 326, in handshake
    status_code, response_headers = await self.read_http_response()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 144, in read_http_response
    raise InvalidMessage("did not receive a valid HTTP response") from exc
websockets.exceptions.InvalidMessage: did not receive a valid HTTP response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/signalbot/bot.py", line 324, in _produce
    async for raw_message in self._signal.receive():
  File "/usr/local/lib/python3.10/site-packages/signalbot/api.py", line 25, in receive
    raise ReceiveMessagesError(e)
signalbot.api.ReceiveMessagesError: did not receive a valid HTTP response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/signalbot/bot.py", line 294, in _rerun_on_exception
    await coro(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/signalbot/bot.py", line 336, in _produce
    raise SignalBotError(f"Cannot receive messages: {e}")
signalbot.bot.SignalBotError: Cannot receive messages: did not receive a valid HTTP response
``

@joe128
Copy link
Contributor

joe128 commented Jun 28, 2024

i think that is a timing-problem:
first you have to register a command with a group-name, but the data about the groups (including id and name) only be resolved after starting the bot.
I made a first attempt to fix the problem by extending the tuple for registering a command (https://github.com/joe128/signalbot/tree/issue43/recolve_groupnames_for_commands_after_start), but I think it would be better if the command class got dedicated fields for membership (allconctacts, valid_contacts, allgroups, valid_group_ids, unresolved_group_names).

@jamesoncollins
Copy link

Looks to me like the specific issue is that .register checks for _groups_by_name here https://github.com/filipre/signalbot/blob/master/signalbot/bot.py#L158

But that variable isn't populated until _detect_groups is called. Which doesnt happen until start is called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants