4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-05 03:34:03 +00:00

Update vendor (github.com/mattermost)

This commit is contained in:
Wim
2018-02-09 00:11:04 +01:00
parent 1d33e60e36
commit 5aab158c0b
267 changed files with 36409 additions and 5827 deletions

View File

@ -6,6 +6,8 @@ package model
import (
"encoding/json"
"io"
"io/ioutil"
"strings"
)
const (
@ -18,6 +20,8 @@ type CommandResponse struct {
Text string `json:"text"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
Type string `json:"type"`
Props StringInterface `json:"props"`
GotoLocation string `json:"goto_location"`
Attachments []*SlackAttachment `json:"attachments"`
}
@ -31,6 +35,22 @@ func (o *CommandResponse) ToJson() string {
}
}
func CommandResponseFromHTTPBody(contentType string, body io.Reader) *CommandResponse {
if strings.TrimSpace(strings.Split(contentType, ";")[0]) == "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
@ -39,8 +59,7 @@ func CommandResponseFromJson(data io.Reader) *CommandResponse {
return nil
}
o.Text = ExpandAnnouncement(o.Text)
o.Attachments = ProcessSlackAttachments(o.Attachments)
o.Attachments = StringifySlackFieldValue(o.Attachments)
return &o
}