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

V2: Middleware #100

Closed
tucnak opened this issue Nov 7, 2017 · 3 comments
Closed

V2: Middleware #100

tucnak opened this issue Nov 7, 2017 · 3 comments
Assignees
Milestone

Comments

@tucnak
Copy link
Owner

tucnak commented Nov 7, 2017

How about we add some sort of middleware support. The perfect use case is spam handling and abuse mitigation, which is in its basic form is pretty much route-independent.

I doubt we should go with a fully-fledged approach that of Gin, for example, which utilizes route groups with attached middlewares. It seems to me a simple, bot-global middleware chain must be sufficient.

API:

// object :: (Message | Query | Callback)
bot.Use(func(b *Bot, object interface{}) bool {
    return true // return false - breaks the chain
})
@tucnak tucnak added the v2 label Nov 7, 2017
@tucnak tucnak added this to the 2.0 milestone Nov 7, 2017
@tucnak tucnak self-assigned this Nov 7, 2017
@tucnak
Copy link
Owner Author

tucnak commented Nov 7, 2017

/cc @zoni

@tucnak
Copy link
Owner Author

tucnak commented Nov 21, 2017

I can't think of any other use case other than spam handling, which can now be managed via Poller interface, so I suggest middleware no more.

@tucnak tucnak closed this as completed Nov 21, 2017
@tucnak
Copy link
Owner Author

tucnak commented Nov 21, 2017

So I thought about it for a while... and it actually seems worthwhile to implement some middleware system based on Pollers:

(like)

poller := &tb.LongPoller{25 * time.Second}
spamProtected := tb.Middleware(poller, func (upd *Update) bool {
    // return false to deny update
    return true
})

b, err := tb.NewBot(tb.Settings{
    Token: "TOKEN_HERE",
    Poller: spamProtected,
})

@tucnak tucnak reopened this Nov 21, 2017
tucnak pushed a commit that referenced this issue Nov 21, 2017
@tucnak tucnak closed this as completed Nov 21, 2017
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

1 participant