InlineKeyboard + Webhook

问题描述

我开发了一个电报机器人并使用了webhook。但是,我不知道如何使用InlineKeyboard和CallbackQuery。如果有人知道,请在下面写下一个简单的例子

我的尝试:

func AddFundsAction(bottext BotMessage,NewBot *tgBotApi.BotAPI) {
    chatUser := int64(bottext.Message.From.Id)
    markup := tgBotApi.NewInlineKeyboardMarkup(
        tgBotApi.NewInlineKeyboardRow(
            tgBotApi.NewInlineKeyboardButtonData("3","3"),),)
    reply := tgBotApi.NewMessage(chatUser,"hello,world!")
    reply.ReplyMarkup = &markup
    res,_ := NewBot.Send(reply)
    fmt.Println(res)
}

错误

Bad Request: chat not found

解决方法

我使用了HandlFunc而不是ListenWebHook,但我无法实现我的想法。 它对我有用:

setWebhook(NewBot)
    updates := NewBot.ListenForWebhook("/" + configuration.BOT_TOKEN)
    go successfulPaymentListen()
    go http.ListenAndServeTLS(fmt.Sprintf("%s:%s",configuration.BOT_HOST,configuration.BOT_PORT),configuration.CERT_FILE,configuration.CERT_KEY,nil)
    for update := range updates {
        if update.Message != nil {
            recognizeCommand(update)
        } else if update.CallbackQuery != nil {
            log.Print(update.CallbackQuery.Data)
        }
    }