Refactoring codes for more tg message types

This commit is contained in:
2026-03-07 22:16:14 +08:00
parent a396a381b5
commit 912f9fd0ad
26 changed files with 771 additions and 472 deletions

56
adaptors/tg/botsend.go Normal file
View File

@@ -0,0 +1,56 @@
package tg
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
query "github.com/tgckpg/golifehk/query"
)
func BotSendText(bot *tgbotapi.BotAPI, update *tgbotapi.Update, mesg *string) {
var msg tgbotapi.MessageConfig
msg = tgbotapi.NewMessage(update.Message.Chat.ID, *mesg)
msg.ParseMode = "MarkdownV2"
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
func BotSend(bot *tgbotapi.BotAPI, update *tgbotapi.Update, qResult query.IQueryResult) (bool, error) {
var msg tgbotapi.MessageConfig
mesg, err := qResult.Message()
if err != nil {
// not sent, error
return false, err
}
mesgType := qResult.DataType()
switch mesgType {
case "IGNORE":
// not sent with no error tells the parent to look for other processors
return false, nil
}
msg = tgbotapi.NewMessage(update.Message.Chat.ID, mesg)
msg.ParseMode = "MarkdownV2"
switch mesgType {
case "PlainText":
case "Table":
button := tgbotapi.NewInlineKeyboardButtonData(
"Show Status", // what user sees
"status_cmd", // what bot receives
)
msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow(button, button),
)
}
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
return true, nil
}