forked from hugozhu/godingtalk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_robot.go
106 lines (98 loc) · 3.23 KB
/
api_robot.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package godingtalk
import (
"net/url"
)
type RobotAtList struct {
AtMobiles []string `json:"atMobiles"`
IsAtAll bool `json:"isAtAll"`
}
//SendRobotTextMessage can send a text message to a group chat
func (c *DingTalkClient) SendRobotTextMessage(accessToken string, msg string) (data MessageResponse, err error) {
params := url.Values{}
params.Add("access_token", accessToken)
request := map[string]interface{}{
"msgtype": "text",
"text": map[string]interface{}{
"content": msg,
},
}
err = c.httpRPC("robot/send", params, request, &data)
return data, err
}
//SendRobotMarkdownMessage can send a text message to a group chat
func (c *DingTalkClient) SendRobotMarkdownMessage(accessToken string, title string, msg string) (data MessageResponse, err error) {
params := url.Values{}
params.Add("access_token", accessToken)
request := map[string]interface{}{
"msgtype": "markdown",
"markdown": map[string]interface{}{
"title": title,
"text": msg,
},
}
err = c.httpRPC("robot/send", params, request, &data)
return data, err
}
// SendRobotTextAtMessage can send a text message and at user to a group chat
func (c *DingTalkClient) SendRobotTextAtMessage(accessToken string, msg string, at *RobotAtList) error {
var data OAPIResponse
params := url.Values{}
params.Add("access_token", accessToken)
request := map[string]interface{}{
"msgtype": "text",
"text": map[string]interface{}{
"content": msg,
},
"at": at,
}
err := c.httpRPC("robot/send", params, request, &data)
return err
}
//SendRobotMarkdownMessage can send a text message to a group chat
func (c *DingTalkClient) SendRobotMarkdownAtMessage(accessToken string, title string, msg string, at *RobotAtList) (data MessageResponse, err error) {
params := url.Values{}
params.Add("access_token", accessToken)
request := map[string]interface{}{
"msgtype": "markdown",
"markdown": map[string]interface{}{
"title": title,
"text": msg,
},
"at": at,
}
err = c.httpRPC("robot/send", params, request, &data)
return data, err
}
func (c *DingTalkClient) SendRobotActionCardMessage(accessToken string, title string, msg string, btns []map[string]interface{}, btnOrientation string, hideAvatar string) (data MessageResponse, err error) {
params := url.Values{}
params.Add("access_token", accessToken)
request := map[string]interface{}{
"msgtype": "actionCard",
"actionCard": map[string]interface{}{
"title": title,
"text": msg,
"hideAvatar": hideAvatar,
"btnOrientation": btnOrientation,
"btns": btns,
},
}
err = c.httpRPC("robot/send", params, request, &data)
return data, err
}
func (c *DingTalkClient) SendRobotActionCardAtMessage(accessToken string, title string, msg string, btns []map[string]interface{}, btnOrientation string, hideAvatar string, at *RobotAtList) (data MessageResponse, err error) {
params := url.Values{}
params.Add("access_token", accessToken)
request := map[string]interface{}{
"msgtype": "actionCard",
"actionCard": map[string]interface{}{
"title": title,
"text": msg,
"hideAvatar": hideAvatar,
"btnOrientation": btnOrientation,
"btns": btns,
},
"at": at,
}
err = c.httpRPC("robot/send", params, request, &data)
return data, err
}