/
line.go
35 lines (28 loc) · 839 Bytes
/
line.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
package gutils
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func LineOABoardcastMessages(channelAccessToken string, message []string) {
messagePayload := map[string]interface{}{
"messages": []map[string]interface{}{},
}
messages := []map[string]interface{}{}
for _, v := range message {
messages = append(messages, map[string]interface{}{
"type": "text",
"text": v,
})
}
messagePayload["messages"] = messages
jsonData, _ := json.Marshal(messagePayload)
client := &http.Client{}
req, _ := http.NewRequest("POST", "https://api.line.me/v2/bot/message/broadcast", bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channelAccessToken))
res, _ := client.Do(req)
ioutil.ReadAll(res.Body)
}