1
0
mirror of https://github.com/badkaktus/gorocket.git synced 2024-12-12 11:15:05 +02:00

add hooks

This commit is contained in:
badkaktus 2020-05-05 14:22:50 +03:00
parent e5a9fa2ac6
commit 531c141ed1

38
hooks.go Normal file
View File

@ -0,0 +1,38 @@
package gorocket
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
)
type HookMessage struct {
Text string `json:"text"`
Attachments []HookAttachment `json:"attachments"`
}
type HookAttachment struct {
Title string `json:"title"`
TitleLink string `json:"title_link"`
Text string `json:"text"`
ImageURL string `json:"image_url"`
Color string `json:"color"`
}
func (c *Client) Hooks(msg *HookMessage, token string) {
opt, _ := json.Marshal(msg)
req, err := http.NewRequest("POST",
fmt.Sprintf("%s/hooks/%s", c.baseURL, token),
bytes.NewBuffer(opt))
req.Header.Set("Accept", "application/json; charset=utf-8")
req.Header.Set("Content-Type", "application/json; charset=utf-8")
if err != nil {
log.Fatal("Request error")
//return nil, err
}
}