-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (42 loc) · 1.2 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
package main
import (
"net/http"
"stchb/bot"
"stchb/config"
"stchb/logger"
"stchb/types"
"strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
func main() {
go func() {
logger.ForError(http.ListenAndServe(":"+config.GetConfig().Bot.Port, nil))
}()
logger.ForInfo("Authorized on account.")
botAPI, err := tgbotapi.NewBotAPI(config.GetConfig().Bot.Token)
if err != nil {
logger.ForError(err.Error())
}
logger.ForInfo("Bot have created successfully.")
updates := bot.Updates{}
var updatesChannel tgbotapi.UpdatesChannel
if !strings.EqualFold(config.GetConfig().Bot.Webhook, "") {
updatesChannel, err = updates.SetWebhook(config.GetConfig().Bot.Webhook, botAPI)
if err != nil {
logger.ForError(err.Error())
}
} else {
updatesChannel, err = updates.SetPolling(config.GetConfig().Bot.Polling.Offset,
config.GetConfig().Bot.Polling.Limit, config.GetConfig().Bot.Polling.Timeout, botAPI)
if err != nil {
logger.ForError(err.Error())
}
}
chats, err := types.NewChats(config.GetConfig().Chat.Queue, config.GetConfig().Chat.Users)
if err != nil {
logger.ForError(err.Error())
}
for update := range updatesChannel {
updates.HandleUpdate(update, chats, botAPI)
}
}