-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (53 loc) · 1.66 KB
/
main.go
File metadata and controls
63 lines (53 loc) · 1.66 KB
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
58
59
60
61
62
63
package main
import (
"flag"
"net/http"
"os"
"github.com/viktorbarzin/webhook-handler/chatbot"
"github.com/viktorbarzin/webhook-handler/chatbot/fbapi"
"github.com/golang/glog"
)
const (
fsmFlagName = "fsm"
listenAddr = ":3000"
configEnvVarName = "CONFIG"
)
func main() {
flag.Set("logtostderr", "true")
flag.Set("stderrthreshold", "WARNING")
flag.Set("v", "2")
fsmConfigFile := flag.String(fsmFlagName, "", "YAML file which contains the description of conversation state machine.")
flag.Parse()
// TEST
// out, err := executor.Execute(auth.Command{CMD: "echo input isss: $line"}, "kek")
// if err != nil {
// glog.Fatalf("ERR: %s", err.Error())
// }
// glog.Infof(out)
// return
// END TEST
var configFromEnv string
if *fsmConfigFile == "" {
configFromEnv = os.Getenv(configEnvVarName)
if configFromEnv == "" {
glog.Fatal("Please provide config file(--" + fsmFlagName + " flag) or set " + configEnvVarName + " env variable")
} else {
*fsmConfigFile = configFromEnv
}
}
glog.Infof("Initializing chatbot handler with %s config file", *fsmConfigFile)
chatbotHandler, err := chatbot.NewChatbotHandler(*fsmConfigFile)
if err != nil {
glog.Fatalf("Failed to create chatbot handler: %s", err.Error())
}
mux := http.NewServeMux()
mux.HandleFunc(dockerhubPath, dockerHubHandler)
mux.HandleFunc(fbapi.HandlerPath, chatbotHandler.HandleFunc)
mux.HandleFunc(messageViktorHandler, MessageViktorHandleFunc)
mux.HandleFunc(authentikProvisionPath, authentikProvisionHandler)
glog.Infof("Starting webhook handler on %s", listenAddr)
err = http.ListenAndServe(listenAddr, mux)
if err != nil {
glog.Fatalf("Error: %s", err.Error())
}
}