Skip to content

set ruby method as callback #89

Description

@3rj

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

Activity

  1. mrkn commented on May 7, 2019

    @mrkn
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions