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

[enhancement] Add a reactive $bot.listen method that automatically reads messages #10

Open
trosel opened this issue Mar 3, 2017 · 5 comments

Comments

@trosel
Copy link

trosel commented Mar 3, 2017

Would it be possible to add a listen method that just listens for updates with a start block?

So you could utilize P6's nice react whenever system instead of using callbacks and what-not?

Or does the telegram API not allow for the constant connection?

@GildedHonour
Copy link
Owner

@WildYorkies can you elaborate?

@trosel
Copy link
Author

trosel commented Mar 5, 2017

For example, look at this section of a javascript bot library for telegram: https://github.com/mast/telegram-bot-api#retrieve-messages-sent-to-your-bot

Perl 6 has a really nice abstraction for listening to messages that are emitted. Is that out of scope for this library?

@GildedHonour
Copy link
Owner

@WildYorkies I'm not familiar with that yet. Can you show how a user would use it if it was added?

@trosel
Copy link
Author

trosel commented Mar 6, 2017

Good question!

Using the JS library as an example, if someone passes an "updates" boolean to Telegram::Bot.new($token, :updates), it would actually make the returned $bot a Supply that emits various messages.

use Telegram;

var $bot = Telegram::Bot.new($token, :updates);

react {
    whenever $bot -> $message {
        when 'message'      { say $message; }
        when 'inline.query' { say $message; }
    }
}

Of course, I'm no expert on asynchrony. I'm just thinking about how Perl 6 might be able to mimmick the JS functionality described in what I linked above. Obviously, the actual API for this module could be different from the JS one, though.

edit: See this function in the js lib for how they do it. They use the EventEmitter library, which is built in to Perl 6 by default :)

@GildedHonour
Copy link
Owner

@WildYorkies probably yes, but later.

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

2 participants