41 lines
877 B
Go
41 lines
877 B
Go
|
package telegram
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
|
||
|
"git.1750studios.com/ToddShepard/DB640/internal/config"
|
||
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||
|
)
|
||
|
|
||
|
// UpdateChan is telegram UpdatesChannel
|
||
|
type UpdateChan = tgbotapi.UpdatesChannel
|
||
|
|
||
|
var bot *tgbotapi.BotAPI
|
||
|
|
||
|
// Init initzializes the telegram bot
|
||
|
func Init() (UpdateChan, error) {
|
||
|
var err error
|
||
|
bot, err = tgbotapi.NewBotAPI(config.C.Telegram.APIKey)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||
|
|
||
|
u := tgbotapi.NewUpdate(0)
|
||
|
u.Timeout = 60
|
||
|
|
||
|
return bot.GetUpdatesChan(u)
|
||
|
}
|
||
|
|
||
|
// SendReply sends a reply to the given update
|
||
|
func SendReply(reply string, update tgbotapi.Update) error {
|
||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reply)
|
||
|
//msg.ReplyToMessageID = update.Message.MessageID
|
||
|
|
||
|
if _, err := bot.Send(msg); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|