-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdingtalk.go
47 lines (39 loc) · 895 Bytes
/
dingtalk.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
45
46
47
package msgpush
import (
"github.com/imroc/req"
)
const baseUrl = "https://oapi.dingtalk.com/robot/send?access_token="
type SendTextContent struct {
Msgtype string `json:"msgtype"`
Text struct {
Content string `json:"content"`
} `json:"text"`
At struct {
AtMobiles []string `json:"atMobiles"`
IsAtAll bool `json:"isAtAll"`
} `json:"at"`
}
type DingTalk struct {
Token string
ReqUrl string
}
func NewDingTalk(token string) *DingTalk {
return &DingTalk{Token: token, ReqUrl: baseUrl + token}
}
func (d *DingTalk) Send(content string) error {
return d.SendText(content)
}
func (d *DingTalk) SendText(content string) error {
_, err := req.Post(d.ReqUrl, req.BodyJSON(&SendTextContent{
Msgtype: "text",
Text: struct {
Content string `json:"content"`
}{
Content: content,
},
}))
return err
}
func (d *DingTalk) String() string {
return "dingtalk"
}