hynek-urban / rocketchat-async

asyncio-based Python wrapper for the Rocket.Chat Realtime API.
MIT License
13 stars 9 forks source link

[Assistance Required] Issues with Typing Event Functionality #7

Closed kato-mahiro closed 7 months ago

kato-mahiro commented 8 months ago

Hi, @hynek-urban. I am always helped by your project.

Overview

I've written a test script to simulate typing events in a chat channel using the rocketchat_async library. The intended behavior is to signal that a user is typing for a duration and then stops. Unfortunately, the typing events don't seem to be triggered in practice, and I'm at a loss as to why.

Environment details

Code snippet

from rocketchat_async import RocketChat
import asyncio

async def simulate_typing(rc, address, channel_id, username, password):
    await rc.start(address, username, password)
    print(f"{username} starts typing...")
    await rc.send_typing_event(channel_id, True)
    await asyncio.sleep(60)
    print(f"{username} stops typing...")
    await rc.send_typing_event(channel_id, False)

async def main():
    address = "wss://***/websocket"
    username = "***"
    password = "***"
    channel_id = "***"

    rc = RocketChat()
    await simulate_typing(rc, address, channel_id, username, password)

if __name__ == "__main__":
    asyncio.run(main())

Queries

  1. Is there something incorrect or missing in my approach to triggering typing events using the rocketchat_async library?
  2. Does this functionality work as expected in your environment? If so, could you please share the versions of the dependencies you are using?
  3. Do you have any insights into why the typing event might not be working as expected in my setup?

I would greatly appreciate any guidance or suggestions you might have regarding this issue. I'm eager to resolve this problem and continue making progress on my project, and I believe that finding a solution could contribute to enhancing this library.

Thank you very much for your time and assistance.

Best regards

hynek-urban commented 8 months ago

Hi @kato-mahiro , I tried your script and it did work in my environment. Kind of - just keep in mind that if you do await rc.send_typing_event(channel_id, True), rocketchat will only show the typing indicator for a relatively short while. You need to keep resending the event every few seconds or so. (Otherwise, if e.g. someone sent the event and then his connection dropped, he would be forever seen as "typing..." :) )

However, I realized I'm using quite an old version of rocketchat (4.x vs your 6.x). I tried to upgrade but I hit some issues and I don't have time to resolve them today - but I'll try to get back to it within the next days.

kato-mahiro commented 8 months ago

@hynek-urban Thank you very much for your helpful response; the information regarding the version was beneficial.

Following your advice, I attempted to continuously trigger the typing event with the following code, but unfortunately, it did not work in my environment (6.x).

while True:
    await rc.send_typing_event(channel_id, True)
    await asyncio.sleep(5) 

I plan also to try downgrading my rocket.chat version to 4.x to see if that makes a difference. I will report back with the results.

Thank you again for your guidance.

hynek-urban commented 7 months ago

@kato-mahiro I'm not sure if it's still relevant for you but I finally got around to resolving the issue with upgrading Rocket.Chat to the latest version on my end.

I was able to reproduce your issue and it should be fixed now.

Thanks for reporting it!

hynek-urban commented 7 months ago

Closing as I think it's resolved.

kato-mahiro commented 7 months ago

Thank you for making the improvement! This will be very beneficial for my project.