all repos — escarbot @ 58e84a701c04549efc209f66110fe250c47aa909

Earthbound Café's custom Telegram bot, with lots of cool utilities built-in.

telegram/forward.go (view raw)

 1package telegram
 2
 3import (
 4	"log"
 5
 6	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
 7)
 8
 9func channelPostHandler(escarbot *EscarBot, message *tgbotapi.Message) {
10	chatId := message.Chat.ID
11	if chatId != escarbot.ChannelID {
12		log.Println("Ignoring message since it did not come from the correct chat_id.")
13		return
14	}
15
16	msg := tgbotapi.NewForward(escarbot.GroupID, chatId, message.MessageID)
17	msg.ReplyToMessageID = message.MessageID
18	_, err := escarbot.Bot.Send(msg)
19	if err != nil {
20		log.Println("Error forwarding message to group:", err)
21	}
22}
23
24func forwardToAdmin(escarbot *EscarBot, message *tgbotapi.Message) {
25	if !message.Chat.IsPrivate() {
26		return
27	}
28	msg := tgbotapi.NewForward(escarbot.AdminID, message.Chat.ID, message.MessageID)
29	_, err := escarbot.Bot.Send(msg)
30	if err != nil {
31		log.Println("Error forwarding message to admin:", err)
32	}
33}