diff options
author | Chris <ccbrown112@gmail.com> | 2017-08-16 07:17:57 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-08-16 08:17:57 -0400 |
commit | b122381e87577ddfc12b792a3de9121ea830d50e (patch) | |
tree | 1487a6a97aa0a928db230b207463e721e56858c9 /app/command.go | |
parent | 5cd45c939406e5af84b0d9a6967683b77100303c (diff) | |
download | chat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.gz chat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.bz2 chat-b122381e87577ddfc12b792a3de9121ea830d50e.zip |
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
Diffstat (limited to 'app/command.go')
-rw-r--r-- | app/command.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/app/command.go b/app/command.go index 7fe11fffc..83500cc1f 100644 --- a/app/command.go +++ b/app/command.go @@ -45,10 +45,9 @@ func CreateCommandPost(post *model.Post, teamId string, response *model.CommandR parseSlackAttachment(post, response.Attachments) } - switch response.ResponseType { - case model.COMMAND_RESPONSE_TYPE_IN_CHANNEL: + if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL { return CreatePost(post, teamId, true) - case model.COMMAND_RESPONSE_TYPE_EPHEMERAL: + } else if response.ResponseType == "" || response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL { if response.Text == "" { return post, nil } @@ -196,7 +195,12 @@ func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.App p.Set("command", "/"+trigger) p.Set("text", message) - p.Set("response_url", "not supported yet") + + if hook, err := CreateCommandWebhook(cmd.Id, args); err != nil { + return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError) + } else { + p.Set("response_url", args.SiteURL+"/hooks/commands/"+hook.Id) + } method := "POST" if cmd.Method == model.COMMAND_METHOD_GET { @@ -213,7 +217,7 @@ func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.App return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError) } else { if resp.StatusCode == http.StatusOK { - response := model.CommandResponseFromJson(resp.Body) + response := model.CommandResponseFromHTTPBody(resp.Header.Get("Content-Type"), resp.Body) if response == nil { return nil, model.NewAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusInternalServerError) } else { |