-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (38 loc) · 1.02 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/justblackbird/tg-poller/app"
"github.com/justblackbird/tg-poller/telegram"
)
func main() {
host := os.Getenv("TELEGRAM_API_HOST")
if host == "" {
host = "api.telegram.org"
}
token := os.Getenv("TELEGRAM_TOKEN")
if token == "" {
panic("Env variable \"TELEGRAM_TOKEN\" must be defined")
}
updateHook := os.Getenv("UPDATE_HOOK")
if updateHook == "" {
panic("Env variable \"UPDATE_HOOK\" must be defined")
}
fmt.Println("App is running with env:")
fmt.Printf("TELEGRAM_API_HOST = %v\n", host)
fmt.Printf("TELEGRAM_TOKEN = %v\n", token)
fmt.Printf("UPDATE_HOOK = %v\n", updateHook)
poller := app.NewPoller(telegram.NewAPI(host, token))
sender := app.NewSender(updateHook)
sender.SendUpdatesFrom(poller.Updates)
poller.Start()
fmt.Println("App is started")
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
// Wait for a signal to stop.
<-quit
poller.Stop()
fmt.Println("App is stopped")
}