tucnak / telebot

Telebot is a Telegram bot framework in Go.
MIT License
3.77k stars 440 forks source link

Why does this code not display the pop-up window? #670

Closed yaooort closed 3 months ago

yaooort commented 3 months ago

Why does this code not display the pop-up window?

{"ok":false,"error_code":400,"description":"Bad Request: query is too old and response timeout expired or query ID is invalid"}

// RepButtons func RepButtons(bot tele.Bot) tele.ReplyMarkup { menuMain := &tele.ReplyMarkup{ResizeKeyboard: true} var btns []tele.Btn var btnDelete = &tele.InlineButton{Unique: "unique123", Text: "Delete"} query := menuMain.Data("queryBtn", "unique123", "welcome") bot.Handle(btnDelete, func(c tele.Context) error { return c.Respond(&tele.CallbackResponse{Text: "HAHA", ShowAlert: true}) }) btns = append(btns, query) menuMain.Inline(btns) return menuMain }


Why does nothing happen when I click the button?
yaooort commented 3 months ago

correct code

func Alert(bot *tele.Bot) {
    bot.Handle("/start", func(c tele.Context) error {
        c.Reply("welcome", RepButtons(bot))
        return nil
    })
}

// RepButtons
func RepButtons(bot *tele.Bot) *tele.ReplyMarkup {
    menuMain := &tele.ReplyMarkup{ResizeKeyboard: true}
    var btns []tele.Btn
    query := menuMain.Data("queryBtn", "unique123", "welcome")
    bot.Handle(&query, func(c tele.Context) error {
        return c.Respond(&tele.CallbackResponse{Text: "HAHA", ShowAlert: true})
    })
    btns = append(btns, query)
    menuMain.Inline(btns)
    return menuMain
}