Repository navigation
Expand file tree
/
Copy pathroutes.go
More file actions
106 lines (89 loc) · 4.79 KB
/
Copy pathroutes.go
File metadata and controls
106 lines (89 loc) · 4.79 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
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
106
package main
import (
"github.com/justinas/alice"
"github.com/rs/zerolog"
"github.com/rs/zerolog/hlog"
"net/http"
"os"
"path/filepath"
"time"
)
type Middleware = alice.Constructor
func (s *server) routes() {
if *logType == "json" {
log = zerolog.New(os.Stdout).With().Timestamp().Str("role", filepath.Base(os.Args[0])).Str("host", *address).Logger()
} else {
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
log = zerolog.New(output).With().Timestamp().Str("role", filepath.Base(os.Args[0])).Str("host", *address).Logger()
}
c := alice.New()
// Admin Panel Routes
adminRoutes := s.router.PathPrefix("/api/admin").Subrouter()
adminRoutes.Handle("/dashboard", s.AdminDashboard()).Methods("GET")
adminRoutes.Handle("/integrations", s.AdminIntegrations()).Methods("GET")
adminRoutes.Handle("/integrations", s.AdminCreateIntegration()).Methods("POST")
adminRoutes.Handle("/integrations/{id}", s.AdminDeleteIntegration()).Methods("DELETE")
adminRoutes.Handle("/integrations/{id}/test", s.AdminTestIntegration()).Methods("POST")
adminRoutes.Handle("/chatwoot", s.AdminChatwoot()).Methods("GET")
adminRoutes.Handle("/wuzapi", s.AdminWuzAPI()).Methods("GET")
adminRoutes.Handle("/logs", s.AdminLogs()).Methods("GET")
adminRoutes.Handle("/settings", s.AdminSettings()).Methods("GET")
// Main webhook endpoint
s.router.Handle("/chatwoot", c.Then(s.Chatwoot())).Methods("POST")
// Static files and main interface
s.router.Handle("/", s.GetIndex()).Methods("GET")
s.router.Handle("/api", s.GetApi()).Methods("GET")
c = c.Append(s.authalice)
c = c.Append(hlog.NewHandler(log))
c = c.Append(hlog.AccessHandler(func(r *http.Request, status, size int, duration time.Duration) {
hlog.FromRequest(r).Info().
Str("method", r.Method).
Stringer("url", r.URL).
Int("status", status).
Int("size", size).
Dur("duration", duration).
Str("userid", r.Context().Value("userinfo").(Values).Get("Id")).
Msg("Got API Request")
}))
c = c.Append(hlog.RemoteAddrHandler("ip"))
c = c.Append(hlog.UserAgentHandler("user_agent"))
c = c.Append(hlog.RefererHandler("referer"))
c = c.Append(hlog.RequestIDHandler("req_id", "Request-Id"))
// WuzAPI integration endpoints
s.router.Handle("/session/connect", c.Then(s.Connect())).Methods("POST")
s.router.Handle("/session/disconnect", c.Then(s.Disconnect())).Methods("POST")
s.router.Handle("/session/logout", c.Then(s.Logout())).Methods("POST")
s.router.Handle("/session/status", c.Then(s.GetStatus())).Methods("GET")
s.router.Handle("/session/qr", c.Then(s.GetQR())).Methods("GET")
s.router.Handle("/token", c.Then(s.SetToken())).Methods("POST")
s.router.Handle("/webhook", c.Then(s.SetWebhook())).Methods("POST")
s.router.Handle("/webhook", c.Then(s.GetWebhook())).Methods("GET")
s.router.Handle("/chat/send/text", c.Then(s.SendMessage())).Methods("POST")
s.router.Handle("/chat/send/image", c.Then(s.SendImage())).Methods("POST")
s.router.Handle("/chat/send/audio", c.Then(s.SendAudio())).Methods("POST")
s.router.Handle("/chat/send/document", c.Then(s.SendDocument())).Methods("POST")
s.router.Handle("/chat/send/video", c.Then(s.SendVideo())).Methods("POST")
s.router.Handle("/chat/send/sticker", c.Then(s.SendSticker())).Methods("POST")
s.router.Handle("/chat/send/location", c.Then(s.SendLocation())).Methods("POST")
s.router.Handle("/chat/send/contact", c.Then(s.SendContact())).Methods("POST")
s.router.Handle("/chat/react", c.Then(s.React())).Methods("POST")
s.router.Handle("/chat/send/button", c.Then(s.SendButtons())).Methods("POST")
s.router.Handle("/chat/send/list", c.Then(s.SendLists())).Methods("POST")
s.router.Handle("/chat/send/template", c.Then(s.SendTemplate())).Methods("POST")
s.router.Handle("/user/info", c.Then(s.GetUser())).Methods("POST")
s.router.Handle("/user/check", c.Then(s.CheckUser())).Methods("POST")
s.router.Handle("/user/avatar", c.Then(s.GetAvatar())).Methods("POST")
s.router.Handle("/user/contacts", c.Then(s.GetContacts())).Methods("GET")
s.router.Handle("/chat/presence", c.Then(s.ChatPresence())).Methods("POST")
s.router.Handle("/chat/markread", c.Then(s.MarkRead())).Methods("POST")
s.router.Handle("/chat/downloadimage", c.Then(s.DownloadImage())).Methods("POST")
s.router.Handle("/chat/downloadvideo", c.Then(s.DownloadVideo())).Methods("POST")
s.router.Handle("/chat/downloaddocument", c.Then(s.DownloadDocument())).Methods("POST")
s.router.Handle("/group/list", c.Then(s.ListGroups())).Methods("GET")
s.router.Handle("/group/info", c.Then(s.GetGroupInfo())).Methods("POST")
s.router.Handle("/group/invitelink", c.Then(s.GetGroupInviteLink())).Methods("POST")
s.router.Handle("/group/photo", c.Then(s.SetGroupPhoto())).Methods("POST")
s.router.Handle("/group/name", c.Then(s.SetGroupName())).Methods("POST")
// Serve static files
s.router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
}