hynek-urban / rocketchat-async

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

add token based authentication #2

Closed mcg88 closed 1 year ago

mcg88 commented 1 year ago
async def main(address, username, token):
    while True:
        try:
            rc = RocketChat()
            await rc.resume(address,username, token)

            # A possible workflow consists of two steps:
            #
            # 1. Set up the desired callbacks...
            for channel_id, channel_type in await rc.get_channels():
            # 2. ...and then simply wait for the registered events.
            await rc.run_forever()

        except (RocketChat.ConnectionClosed,
                RocketChat.ConnectCallFailed) as e:
            print(f'Connection failed: {e}. Waiting a few seconds...')
            await asyncio.sleep(random.uniform(4, 8))
            print('Reconnecting...')

asyncio.run(main('websocket', 'username', 'token'))
hynek-urban commented 1 year ago

@mcg88 Hi, thanks a lot! I'll take a detailed look and hopefully merge this during the week.

mcg88 commented 1 year ago

right on. I don't believe passing the username is required, but the async response to the "resume" command doesn't include the username value so I wasn't sure if it would break anything downstream

hynek-urban commented 1 year ago

Thanks, @mcg88, much appreciated. I'm going to merge this and fix a small issue I found. Sorry it took me so long.