-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathapi_robot.go
75 lines (69 loc) · 2.29 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
package godingtalk
import (
"net/url"
)
type RobotAtList struct {
AtMobiles []string `json:"atMobiles"`
IsAtAll bool `json:"isAtAll"`
}
type RobotOutgoingMessage struct {
MessageType string `json:"msgtype"`
Text struct {
Content string `json:"content,omitempty"`
} `json:"text,omitempty"`
MessageID string `json:"msgId"`
CreatedAt int64 `json:"createAt"`
ConversationID string `json:"conversationId"`
ConversationType string `json:"conversationType"`
ConversationTitle string `json:"conversationTitle"`
SenderID string `json:"senderId"`
SenderNick string `json:"senderNick"`
SenderCorpID string `json:"senderCorpId"`
SenderStaffID string `json:"senderStaffId"`
ChatbotUserID string `json:"chatbotUserId"`
AtUsers []struct {
DingTalkID string `json:"dingtalkId,omitempty"`
StaffID string `json:"staffId,omitempty"`
} `json:"atUsers,omitempty"`
}
//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) (data OAPIResponse, err error) {
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 data, err
}