From b122381e87577ddfc12b792a3de9121ea830d50e Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 16 Aug 2017 07:17:57 -0500 Subject: PLT-1649: add response_url support for custom slash commands (#6739) * add response_url support for custom slash commands * pr suggestions * pr update / suggestion * test fix --- api4/webhook.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'api4/webhook.go') diff --git a/api4/webhook.go b/api4/webhook.go index 668636932..52576c773 100644 --- a/api4/webhook.go +++ b/api4/webhook.go @@ -7,6 +7,7 @@ import ( "net/http" l4g "github.com/alecthomas/log4go" + "github.com/gorilla/mux" "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" @@ -27,6 +28,8 @@ func InitWebhook() { BaseRoutes.OutgoingHook.Handle("", ApiSessionRequired(updateOutgoingHook)).Methods("PUT") 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") } func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { @@ -435,3 +438,19 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("success") ReturnStatusOK(w) } + +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")) +} -- cgit v1.2.3-1-g7c22