-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (37 loc) · 832 Bytes
/
main.go
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
33
34
35
36
37
38
39
40
41
42
43
44
package robification
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
)
func Send(p *fdChat) error {
url := "http://api.robification.io:1337/v1/flowdock/chat"
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(p.Content)))
if err != nil {
panic(err)
}
req.Header.Set("Token", p.Flow_Token)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
res := apiResponse{}
json.Unmarshal([]byte(body), &res)
// Hard-coding one response for now...
if res.Messages[0].Status == "200 OK" {
return nil
}
return errors.New(res.Messages[0].Status)
}
func NewFdChat(flowToken string, content string) *fdChat {
chat := &fdChat{
Flow_Token: flowToken,
Content: content,
}
return chat
}