/
zulip.go
44 lines (35 loc) · 925 Bytes
/
zulip.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 zulip
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"strings"
"time"
)
const timeout time.Duration = 5 * time.Second
// ThumbsUp on a message.
func ThumbsUp(ctx context.Context, messageID int) {
//nolint:exhaustivestruct
apiURL := url.URL{
User: url.UserPassword(os.Getenv("ZULIP_BOT_MAIL"), os.Getenv("ZULIP_BOT_APIKEY")),
Host: "reload.zulipchat.com",
Path: fmt.Sprintf("/api/v1/messages/%d/reactions", messageID),
Scheme: "https",
}
payload := url.Values{}
payload.Set("emoji_name", "+1")
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL.String(), strings.NewReader(payload.Encode()))
if err != nil {
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
response, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer response.Body.Close()
}