-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (70 loc) · 1.79 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"log"
"net/url"
"github.com/delgus/dialogflowbot/bot"
"github.com/delgus/dialogflowbot/providers/common"
"github.com/delgus/dialogflowbot/providers/tg"
"github.com/delgus/dialogflowbot/providers/vk"
"github.com/delgus/dialogflowbot/providers/ws"
"github.com/delgus/dialogflowbot/wsapp/chat"
"github.com/kelseyhightower/envconfig"
)
type config struct {
CredentialsJSON string `envconfig:"CREDENTIALS_JSON"`
ProjectID string `envconfig:"PROJECT_ID"`
TGAccessToken string `envconfig:"TG_ACCESS_TOKEN"`
TGWebhook string `envconfig:"TG_WEBHOOK"`
VKAccessToken string `envconfig:"VK_ACCESS_TOKEN"`
VKWebhook string `envconfig:"VK_WEBHOOK"`
VKConfirmKey string `envconfig:"VK_CONFIRM_KEY"`
WSURL string `envconfig:"WS_URL"`
}
func main() {
// configurations
var cfg config
err := envconfig.Process("", &cfg)
if err != nil {
log.Fatal("can't load config", err)
}
// websocket app
chat.Run()
// providers:
// tg
tgWebhook, err := url.Parse(cfg.TGWebhook)
if err != nil {
log.Fatal(err)
}
tgProvider, err := tg.NewClient(cfg.TGAccessToken, tgWebhook)
if err != nil {
log.Fatal(err)
}
// vk
vkWebhook, err := url.Parse(cfg.VKWebhook)
if err != nil {
log.Fatal(err)
}
vkProvider := vk.NewClient(cfg.VKAccessToken, vkWebhook, cfg.VKConfirmKey)
if err != nil {
log.Fatal(err)
}
// ws
wsURL, err := url.Parse(cfg.WSURL)
if err != nil {
log.Fatal(err)
}
wsProvider := ws.NewClient(wsURL)
if err != nil {
log.Fatal(err)
}
// dialogflow bot
dfBot, err := bot.NewBot(cfg.CredentialsJSON, cfg.ProjectID, map[common.ProviderType]common.Provider{
common.TGProvider: tgProvider,
common.VKProvider: vkProvider,
common.WSProvider: wsProvider,
})
if err != nil {
log.Fatal("can't start dialog flow bot", err)
}
dfBot.Run()
}