-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
57 lines (45 loc) · 1.35 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"os"
"time"
"github.com/hud0shnik/telegram_go_bot/internal/config"
"github.com/hud0shnik/telegram_go_bot/internal/handler"
"github.com/hud0shnik/telegram_go_bot/internal/telegram"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
)
func main() {
// Настройка логгера
logrus.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: time.DateTime,
})
// Инициализация конфига (токенов)
err := config.InitConfig()
if err != nil {
logrus.Fatalf("initConfig error: %s", err)
return
}
// Загрузка переменных окружения
godotenv.Load()
// Url бота для отправки и приёма сообщений
botUrl := "https://api.telegram.org/bot" + os.Getenv("TOKEN")
offSet := 0
// Уведомление о старте
logrus.Info("Bot is running")
// Цикл работы бота
for {
// Получение апдейтов
updates, err := telegram.GetUpdates(botUrl, offSet)
if err != nil {
logrus.Warnf("getUpdates error: %s", err)
continue
}
// Обработка апдейтов
for _, update := range updates {
handler.Respond(botUrl, update)
offSet = update.UpdateId + 1
}
// Вывод в консоль для тестов
// fmt.Println(updates)
}
}