-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
105 lines (89 loc) · 2.71 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"net/http"
"os"
//ru "github.com/grokify/go-ringcentral/clientutil"
ru "github.com/grokify/go-ringcentral-client/office/v1/util"
"github.com/grokify/goauth"
ro "github.com/grokify/goauth/ringcentral"
cfg "github.com/grokify/mogo/config"
log "github.com/sirupsen/logrus"
"github.com/grokify/chatblox"
"github.com/grokify/chatblox/glip"
"github.com/grokify/skillbot/handlers/alert_demo/alert"
alertteam "github.com/grokify/skillbot/handlers/alert_demo/alert_team"
"github.com/grokify/skillbot/handlers/bot_info/botinfo"
"github.com/grokify/skillbot/handlers/bot_info/botteams"
"github.com/grokify/skillbot/handlers/help"
"github.com/grokify/skillbot/handlers/query"
"github.com/grokify/skillbot/handlers/sorry"
)
func LoadEnv() string {
// Check and load environment file if necessary
engine := os.Getenv("CHATBLOX_ENGINE")
if len(engine) == 0 {
_, err := cfg.LoadDotEnv([]string{os.Getenv("ENV_PATH"), "./.env"}, 1)
if err != nil {
log.Warn(err)
}
engine = os.Getenv("CHATBLOX_ENGINE")
}
return engine
}
func NewGlipHandler() glip.RcOAuthManager {
creds := goauth.CredentialsOAuth2{
ClientID: os.Getenv("RINGCENTRAL_CLIENT_ID"),
ClientSecret: os.Getenv("RINGCENTRAL_CLIENT_SECRET"),
ServerURL: os.Getenv("RINGCENTRAL_SERVER_URL"),
RedirectURL: os.Getenv("RINGCENTRAL_REDIRECT_URL")}
return glip.NewRcOAuthManager(nil, creds)
}
func main() {
engine := LoadEnv()
glipHandler := NewGlipHandler()
mux := http.NewServeMux()
mux.HandleFunc("/oauth2callback", http.HandlerFunc(glipHandler.HandleOAuthNetHTTP))
serverURL := os.Getenv("RINGCENTRAL_SERVER_URL")
httpClient, err := ro.NewHTTPClientEnvFlexStatic("")
if err != nil {
log.Fatal(err)
}
apiClient, err := ru.NewApiClientHttpClientBaseURL(httpClient, serverURL)
if err != nil {
log.Fatal(err)
}
alertteamFactory := alertteam.Factory{
HTTPClient: httpClient,
ServerURL: serverURL,
APIClient: apiClient}
botinfoFactory := botinfo.Factory{
HTTPClient: httpClient,
ServerURL: serverURL,
APIClient: apiClient}
botteamsFactory := botteams.Factory{
HTTPClient: httpClient,
ServerURL: serverURL,
APIClient: apiClient}
// Set intents
intentRouter := chatblox.IntentRouter{
Intents: []chatblox.Intent{
botinfoFactory.NewIntent(),
botteamsFactory.NewIntent(),
alertteamFactory.NewIntent(),
alert.NewIntent(),
help.NewIntent(),
query.NewIntent(),
sorry.NewIntent()}}
// Run engine
switch engine {
case "awslambda":
log.Info("Starting Engine [awslambda]")
chatblox.ServeAWSLambda(intentRouter)
case "nethttp":
log.Info("Starting Engine [nethttp]")
chatblox.ServeNetHTTP(intentRouter, mux)
default:
log.Fatal(fmt.Sprintf("E_NO_HTTP_ENGINE: [%v]", engine))
}
}