diff options
author | Alexander Kiryukhin <alexander@kiryukhin.su> | 2019-02-01 01:20:38 +0300 |
---|---|---|
committer | Alexander Kiryukhin <alexander@kiryukhin.su> | 2019-02-01 01:20:38 +0300 |
commit | 8c499a32b7bb614814da84bace3f3e924be92465 (patch) | |
tree | 3bc9d97a01fdb6e4bf219d5de81f1873232fe696 /message.go | |
parent | fc9aefc97d872ec8faed767a7b9e2a89ee8630f0 (diff) |
fixes
Diffstat (limited to 'message.go')
-rw-r--r-- | message.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/message.go b/message.go new file mode 100644 index 0000000..cb13e75 --- /dev/null +++ b/message.go @@ -0,0 +1,32 @@ +package main + +import ( + "bytes" + "encoding/json" + "errors" + "io/ioutil" + "log" +) + +func sendMessage(responseUrl, origText, text string) error { + jm := message{ + Text: origText, + //ResponseType: "in_channel", + Attachments: []Attachment{{Text: text, Color: "#36a64f"}}, + } + b, _ := json.Marshal(jm) + + resp, err := getClient().Post(responseUrl, "application/json", bytes.NewReader(b)) + if err != nil { + log.Println(err) + return err + } + defer resp.Body.Close() + s, _ := ioutil.ReadAll(resp.Body) + if resp.StatusCode >= 300 || resp.StatusCode < 200 { + log.Println("unexpected status " + resp.Status) + log.Println(string(s)) + return errors.New("unexpected status " + resp.Status) + } + return nil +} |