1
0
mirror of synced 2024-11-22 13:06:05 +03:00
mg-transport-api-client-go/examples/telegram/tg.go

28 lines
621 B
Go
Raw Normal View History

2023-12-28 19:32:03 +03:00
package main
import (
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
)
func InitTGBotAPI() {
botAPI, err := tgbotapi.NewBotAPI(AppConfig.TGBotToken)
if err != nil {
log.Fatalln("cannot initialize TG Bot API:", err)
}
TG = botAPI
log.Printf("initialized Telegram Bot API for bot @%s", botAPI.Self.UserName)
}
func SetTGWebhook() {
wh, err := tgbotapi.NewWebhook(fmt.Sprintf("%s/api/v1/tg", AppConfig.BaseURL))
if err != nil {
log.Fatalln("cannot initialize webhook data:", err)
}
_, err = TG.Request(wh)
if err != nil {
log.Fatalln("cannot register TG webhook:", err)
}
}