telegram/inline.go (view raw)
1package telegram
2
3import (
4 "log"
5 "strconv"
6
7 tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
8)
9
10var emptyKeyboard tgbotapi.InlineKeyboardMarkup
11var inlineKeyboardFeedback = tgbotapi.NewInlineKeyboardMarkup(
12 tgbotapi.NewInlineKeyboardRow(
13 tgbotapi.NewInlineKeyboardButtonData("✅", "1"),
14 tgbotapi.NewInlineKeyboardButtonData("❌", "0"),
15 ),
16)
17
18func callbackQueryHandler(bot *tgbotapi.BotAPI, query *tgbotapi.CallbackQuery) {
19 res, err := strconv.ParseInt(query.Data, 10, 64)
20 if err != nil {
21 log.Println("Could not parse int:", err)
22 return
23 }
24
25 var callbackResponse tgbotapi.CallbackConfig
26 var action tgbotapi.Chattable
27
28 if res == 0 {
29 callbackResponse = tgbotapi.NewCallback(query.ID, "Ci ho provato...")
30 action = tgbotapi.NewDeleteMessage(query.Message.Chat.ID, query.Message.MessageID)
31 } else {
32 callbackResponse = tgbotapi.NewCallback(query.ID, "Bene!")
33 action = tgbotapi.NewEditMessageReplyMarkup(query.Message.Chat.ID, query.Message.MessageID, emptyKeyboard)
34 }
35
36 if _, err := bot.Request(callbackResponse); err != nil {
37 panic(err)
38 }
39 _, err = bot.Request(action)
40 if err != nil {
41 log.Fatal(err)
42 }
43
44}