-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (36 loc) · 1.06 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
package main
import (
"fmt"
"github.com/aeidelos/deliverzes/config"
"github.com/aeidelos/deliverzes/service"
tb "github.com/demget/telebot"
"github.com/dgraph-io/badger"
"log"
"net/http"
"time"
)
func main() {
c := config.NewConfig()
p := &tb.LongPoller{Timeout: 15 * time.Second}
d, err := badger.Open(badger.DefaultOptions(c.DbPath))
if err != nil {
log.Fatalln(err)
}
t, err := tb.NewBot(tb.Settings{
Token: c.TelegramToken,
Poller: p,
})
if err != nil {
log.Fatalln(err)
}
b := service.NewBot(t, c, d)
b.Run()
http.HandleFunc("/ping", func(writer http.ResponseWriter, request *http.Request) {
_, _ = writer.Write([]byte("pong"))
})
http.HandleFunc("/create", b.GenerateSubscriberIdHandler)
http.HandleFunc("/send", b.SendMessageHandler)
http.Handle("/", http.Handler(http.FileServer(http.Dir("./web/"))))
log.Printf("starting listen to :%v..", c.HttpPort)
go log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", c.HttpPort), nil))
}