7 "github.com/go-telegram-bot-api/telegram-bot-api"
10 var sendChannel chan tgbotapi.Chattable
12 func initTelegramWorkers(token string, ctx context.Context) error {
13 bot, err := tgbotapi.NewBotAPI(token)
20 log.Printf("Authorized on account %s", bot.Self.UserName)
22 sendChannel = make(chan tgbotapi.Chattable)
23 go sendWorker(bot, sendChannel, ctx)
24 go recvWorker(bot, ctx)
29 func recvWorker(bot *tgbotapi.BotAPI, ctx context.Context) {
30 u := tgbotapi.NewUpdate(0)
33 updates, _ := bot.GetUpdatesChan(u)
37 case update := <-updates:
38 session := getSession(update.Message.Chat)
39 sendToSession(session, update.Message)
46 func sendWorker(bot *tgbotapi.BotAPI, sendChannel chan tgbotapi.Chattable, ctx context.Context) {
49 case msg := <-sendChannel:
57 func sendToTelegram(message tgbotapi.Chattable) {
58 sendChannel <- message