Refactoring codes for more tg message types
This commit is contained in:
56
adaptors/tg/botsend.go
Normal file
56
adaptors/tg/botsend.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user