diff options
Diffstat (limited to 'api4/webhook.go')
-rw-r--r-- | api4/webhook.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/api4/webhook.go b/api4/webhook.go index ef68fd9fe..e34cc4137 100644 --- a/api4/webhook.go +++ b/api4/webhook.go @@ -31,6 +31,7 @@ func InitWebhook() { BaseRoutes.OutgoingHook.Handle("", ApiSessionRequired(deleteOutgoingHook)).Methods("DELETE") BaseRoutes.OutgoingHook.Handle("/regen_token", ApiSessionRequired(regenOutgoingHookToken)).Methods("POST") + BaseRoutes.Root.Handle("/hooks/commands/{id:[A-Za-z0-9]+}", ApiHandler(commandWebhook)).Methods("POST") BaseRoutes.Root.Handle("/hooks/{id:[A-Za-z0-9]+}", ApiHandler(incomingWebhook)).Methods("POST") // Old endpoint for backwards compatibility @@ -486,3 +487,19 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") w.Write([]byte("ok")) } + +func commandWebhook(c *Context, w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + id := params["id"] + + response := model.CommandResponseFromHTTPBody(r.Header.Get("Content-Type"), r.Body) + + err := app.HandleCommandWebhook(id, response) + if err != nil { + c.Err = err + return + } + + w.Header().Set("Content-Type", "text/plain") + w.Write([]byte("ok")) +} |