Closed oanhnn closed 3 days ago
I make PR #107 to fix this issue. Please check soon @negasus
Just tested on v1.7.3
I have a universal update router registered via WithDefaultHandler
and it still does not catch any CallbackQuery updates.
@NiJeTi I showed my case in the chat, everything seemed to work. Can you provide your example?
@negasus What I have is pretty simple configuration:
// func main()
tgBot := telegram.Configure(
cfg.Telegram,
tgPkg.WithErrorsHandler(tgRouter.ErrorHandle),
tgPkg.WithDefaultHandler(tgRouter.Handle),
)
// telegram.Configure()
func Configure(cfg Config, opts ...tgPkg.Option) *tgPkg.Bot {
bot, err := tgPkg.New(cfg.Token, opts...)
if err != nil {
log.Fatalln("failed to connect to telegram:", err)
}
return bot
}
// telegram.Router.Handle()
func (r *Router) Handle(ctx context.Context, bot *tgPkg.Bot, update *tgModels.Update) {
log.Println("update received")
}
And unfortunately router's method Handle
never triggers if I press an inline keyboard button.
@NiJeTi
Its work for me
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
opts := []bot.Option{
bot.WithDefaultHandler(handler),
}
b, _ := bot.New(os.Getenv("EXAMPLE_TELEGRAM_BOT_TOKEN"), opts...)
b.Start(ctx)
}
func handler(ctx context.Context, b *bot.Bot, update *models.Update) {
if update.Message != nil {
kb := &models.InlineKeyboardMarkup{InlineKeyboard: [][]models.InlineKeyboardButton{
{
{Text: "button", CallbackData: "button"},
},
}}
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: update.Message.Chat.ID,
Text: update.Message.Text,
ReplyMarkup: kb,
})
return
}
log.Printf("update %v", update)
}
Sorry for confusion. Yes, you are right. After a brief investigation it became clear that it was some sort of (Telegram's ?) bug. I reissued token and set up a proper log out and now everything seems to work just fine. Thanks for the help!
P.S. If you have any explanation why should either logOut
or close
methods be called directly when not using webhooks at all it would be very helpful.
I don't use logOut )
I don't use logOut )
Neither did I, but it seems that my approach with placing bot.Start
in goroutine may caused such behavior.
Reproduction Steps:
Expected Behavior:
The match function should return true, and the handler added using RegisterHandlerMatchFunc should be executed.
Actual Behavior:
The match function is not executed, and the default handler is triggered instead.
Test Case to Reproduce the Issue:
Solution