-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.15 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
package main
import (
"log"
"os"
"time"
"your_module_name/internal/bot"
"your_module_name/internal/clients"
)
func keepTgUserClientSessionAlive() {
// First time refresh
if err := clients.TgUserClientKeepSessionAlive(); err != nil {
log.Printf("Failed to keep session alive: %v", err)
} else {
log.Printf("Session refresh successful")
}
// Keep session alive every 30 minutes
ticker := time.NewTicker(30 * time.Minute)
go func() {
for range ticker.C {
if err := clients.TgUserClientKeepSessionAlive(); err != nil {
log.Printf("Failed to keep session alive: %v", err)
} else {
log.Printf("Session refresh successful")
}
}
}()
}
func main() {
token := os.Getenv("TG_EVO_BOT_TOKEN")
if token == "" {
log.Fatal("TOKEN environment variable is empty")
}
// Initialize OpenAI client
openaiClient, err := clients.NewOpenAiClient()
if err != nil {
log.Fatalf("Failed to create OpenAI client: %v", err)
}
// Start session keep-alive routine
keepTgUserClientSessionAlive()
bot, err := bot.NewTgBotClient(token, openaiClient)
if err != nil {
log.Fatal("Failed to create Telegram Bot Client: " + err.Error())
}
bot.Start()
}