go - InlineKeyboard + Webhook

标签 go telegram webhooks telegram-bot

我开发了一个电报机器人并使用了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)
        }
    }

关于go - InlineKeyboard + Webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63834022/

相关文章:

go - `sync.WaitGroup` 的方法集是什么?

Git WebHook(PHP)无法访问ruby环境,以apache用户运行jekyll

project - GitLab 新项目设置 webhook

telegram - 如何在不向其发送消息的情况下获取 Telegram channel ID

php - Telegram webhook php bot 没有回答

testing - 带 channel 的 Golang 测试不退出

unit-testing - Go 中的模拟随机生成器

go - Golang OAuth客户端和刷新 token

python - 如何检测用户使用电视马拉松阅读消息?

python - 如何使用 Telethon... 登录多个帐户?