-
Notifications
You must be signed in to change notification settings - Fork 2
/
telegram.go
35 lines (29 loc) · 1018 Bytes
/
telegram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"strings"
tgbotapi "gopkg.in/telegram-bot-api.v4"
)
func sendMessage(chatId int64, msg string) tgbotapi.Message {
return sendMessageAsReply(chatId, msg, 0)
}
func sendMessageAsReply(chatId int64, msg string, replyToId int) tgbotapi.Message {
return sendMessageWithKeyboard(chatId, msg, nil, replyToId)
}
func sendMessageWithKeyboard(chatId int64, msg string, keyboard *tgbotapi.InlineKeyboardMarkup, replyToId int) tgbotapi.Message {
chattable := tgbotapi.NewMessage(chatId, msg)
chattable.BaseChat.ReplyToMessageID = replyToId
chattable.ParseMode = "HTML"
chattable.DisableWebPagePreview = true
if keyboard != nil {
chattable.BaseChat.ReplyMarkup = *keyboard
}
message, err := bot.Send(chattable)
if err != nil {
if strings.Index(err.Error(), "reply message not found") != -1 {
chattable.BaseChat.ReplyToMessageID = 0
message, err = bot.Send(chattable)
}
log.Warn().Err(err).Int64("chat", chatId).Str("msg", msg).Msg("error sending message")
}
return message
}