-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (48 loc) · 1.1 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 (
"awesomeAssistant/core"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"log"
"net/http"
"os"
)
func main() {
err := godotenv.Load()
if err != nil {
panic("Error loading .env file")
}
token := os.Getenv("TOKEN")
//webhookURL := os.Getenv("WEBHOOK_URL")
localPort := os.Getenv("LOCAL_PORT")
println(token)
bot, err := tgbotapi.NewBotAPI(token)
if err != nil {
log.Fatal(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
//wh, _ := tgbotapi.NewWebhook(webhookURL + bot.Token)
//_, err = bot.Request(wh)
//if err != nil {
// log.Fatal(err)
//}
info, err := bot.GetWebhookInfo()
if err != nil {
log.Fatal(err)
}
if info.LastErrorDate != 0 {
log.Printf("Telegram callback failed: %s", info.LastErrorMessage)
}
updates := bot.ListenForWebhook("/update/" + bot.Token)
go func() {
err := http.ListenAndServe("0.0.0.0:"+localPort, nil)
if err != nil {
log.Println(err)
}
}()
for update := range updates {
go core.HandleMessage(update, bot)
}
}