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 /model/command_response.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 'model/command_response.go')
-rw-r--r-- | model/command_response.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/model/command_response.go b/model/command_response.go index 27d39e173..0b80b297b 100644 --- a/model/command_response.go +++ b/model/command_response.go @@ -6,6 +6,7 @@ package model import ( "encoding/json" "io" + "io/ioutil" ) const ( @@ -31,6 +32,22 @@ func (o *CommandResponse) ToJson() string { } } +func CommandResponseFromHTTPBody(contentType string, body io.Reader) *CommandResponse { + if contentType == "application/json" { + return CommandResponseFromJson(body) + } + if b, err := ioutil.ReadAll(body); err == nil { + return CommandResponseFromPlainText(string(b)) + } + return nil +} + +func CommandResponseFromPlainText(text string) *CommandResponse { + return &CommandResponse{ + Text: text, + } +} + func CommandResponseFromJson(data io.Reader) *CommandResponse { decoder := json.NewDecoder(data) var o CommandResponse |