GithubHelp home page GithubHelp logo

V2: Moving towards better API about telebot HOT 8 CLOSED

tucnak avatar tucnak commented on August 16, 2024 3
V2: Moving towards better API

from telebot.

Comments (8)

tucnak avatar tucnak commented on August 16, 2024 2

Blimey! You know what?

It is.

Just.

Perfect.

I'm in overdrive, baby!!!

I don't even care anymore because I'm in the process of making Telebot God Emperor Bot Thing so hey boys and girls chill out

from telebot.

tucnak avatar tucnak commented on August 16, 2024

/cc @irgendwr

from telebot.

irgendwr avatar irgendwr commented on August 16, 2024

I really like the Idea of using reflection as a way of simplifying the send methods!
But wouldn't your proposed message builder mean that you have multiple ways of doing the same thing (ie. sending a message)? Might be confusing, idk.
The error handler would also be very useful to reduce repetitive error checking.

start/listen/serve is confusing

  • I think Serve is kind of useless because when I define a handler I expect it to be called by default.
  • Listen is weird as it's not really needed (see second example in readme; I also don't use listen) and is now also kind of getting replaced by Handlers.
    You could add Handlers for Message and Query events to fully replace Listen and the channel-thing.
  • Couldn't Start also be merged with NewBot? Or is there a reason to have to explicitly define when the bot should start? Race-conditions should be unlikely presuming handlers are registered right after creation.

As you can guess I like the "There should be one-- and preferably only one --obvious way to do it." mentality 😄

from telebot.

irgendwr avatar irgendwr commented on August 16, 2024

I haven't used callbacks yet but they could probably be handlers too, registered per user/state or per message for example.

from telebot.

tucnak avatar tucnak commented on August 16, 2024

I think Serve is kind of useless because when I define a handler I expect it to be called by default.

I couldn't introduce it any other way without breaking backwards compat. 😞

Listen is weird as it's not really needed

Fair enough! I kept it for backwards compat too, even though we can now let it go in v2.

Couldn't Start also be merged with NewBot?

Good question. I don't think so. All the receiving channels must be initialized when long polling starts, so we probably should stick to the 3-phase init process: NewBot, channels & handlers, and Start.

I haven't used callbacks yet but they could probably be handlers too, registered per user or per message for example.

I use callbacks for better UI mostly: inline keyboard buttons cause message updates. What's the benefit of "registering" callbacks as handlers and wiring them to messages, especially considering that associated messages are returned as a part of a callback struct?

from telebot.

matteocontrini avatar matteocontrini commented on August 16, 2024

Any progress? It seems there hasn't been much activity after August 25...

from telebot.

tucnak avatar tucnak commented on August 16, 2024

@matteocontrini No progress at all, I'm still pretty much waiting for feedback.

from telebot.

tucnak avatar tucnak commented on August 16, 2024

FYI, I just added Send(), Reply() and Forward() the three "generic" methods. All of them accept 2+ arguments (recipient, payload and "options"). Since both payload and options are of type interface{}, it lets you pass either string or Sendable as payload and pretty much anything for options.

But what exactly is an "option"? Nice thing about this API is that by "options" it doesn't necessarily mean *SendOptions. Both *SendOptions, *ReplyMarkup and one of the const Options (which I'm still working on, but basically these are just fancy shortcuts) will work, following arguments overriding preceding ones. Look:

b.Send(user, "Message")
b.Send(user, photo, tb.ForceReply)

b.Send(user, photo, tb.NoPreview, tb.ForceReply)
// instead of
b.Send(user, photo, &tb.SendOptions{
    DisableWebPagePreview: true,
    ReplyMarkup: &ReplyMarkup{ForceReply: true},
})

// You can override some properties of stored options also:
savedOptions := &tb.SendOptions{}

b.Send(user, "text", savedOptions, tb.NoPreview) // overrides DisableWebPagePreview from `savedOptions` 

Let me know if there's anything that doesn't feel right.

from telebot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.