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

set ruby method as callback #89

Open
3rj opened this issue Apr 26, 2019 · 1 comment
Open

set ruby method as callback #89

3rj opened this issue Apr 26, 2019 · 1 comment

Comments

@3rj
Copy link

3rj commented Apr 26, 2019

hi
I want to use Telethon (telegram client library) as library in ruby.
It works find but when I want to set ruby method to receive updates it does not work

This is the docs link about getting updates in Telethon.
https://github.com/LonamiWebs/Telethon/blob/master/readthedocs/extra/basic/working-with-updates.rst

how should i do this?

def handler(update)
    puts update
end

client.add_event_handler(:handler)

I used code above, It does not work

@mrkn
Copy link
Owner

mrkn commented May 7, 2019

I'm not altogether familiar with Telethon (I didn't know that as of today), so this answer may be wrong.

You passed a symbol to Python-side. But the code in Python-side couldn't get the method handler from Ruby-side.

As I see in the document you mentioned, the sample code in the document passes a function itself:

from telethon import TelegramClient, events

async def handler(event):
    ...

with TelegramClient(...) as client:
    client.add_event_handler(handler, events.NewMessage)
    client.run_until_disconnected()

So, you need to pass the method itself, don't you think?

However, the handler function above is defined as an async function.
I think that this library cannot use from PyCall as is if the handler must be an async function. Because PyCall doesn't have the way to make a Ruby's callback an async function.

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

No branches or pull requests

2 participants