blob: cb13e75b779cd304d348b5fe6d67a443ca6c8c60 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
}
|