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

Add support of handling different updates #60

Closed
wants to merge 1 commit into from

Conversation

glebkin
Copy link

@glebkin glebkin commented Feb 12, 2024

Currently, there's no way to handle updates, which does not contain Message or CallbackQuery:

func (b *Bot) ProcessUpdate(ctx context.Context, upd *models.Update) {
	h := b.defaultHandlerFunc

	defer func() {
		applyMiddlewares(h, b.middlewares...)(ctx, b, upd)
	}()

	if upd.Message != nil {
		h = b.findHandler(HandlerTypeMessageText, upd)
		return
	}
	if upd.CallbackQuery != nil {
		h = b.findHandler(HandlerTypeCallbackQueryData, upd)
		return
	}
}

Which is actually a problem, because you can't for example handle channel post updates.

@negasus
Copy link
Contributor

negasus commented Feb 21, 2024

For handle any updates, you can implement your logic in DefaultHandler

	opts := []bot.Option{
		bot.WithDefaultHandler(handler),
	}

	b, err := bot.New(os.Getenv("EXAMPLE_TELEGRAM_BOT_TOKEN"), opts...)

...

func handler(ctx context.Context, b *bot.Bot, update *models.Update) {
	if update.Message != nil {
		// handle message
		return
	}

	// ...

	if update.Poll != nil {
		// handle poll
	}

	// etc...
}

@negasus
Copy link
Contributor

negasus commented Mar 4, 2024

Released in #65

@negasus negasus closed this Mar 4, 2024
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

Successfully merging this pull request may close these issues.

2 participants