forked from lightningminers/go-dingtalk
/
open_api_chat.go
165 lines (136 loc) · 3.75 KB
/
open_api_chat.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package dingtalk
import (
"net/url"
)
type ChatCreateResponse struct {
OpenAPIResponse
ChatId string `json:"chatid"`
}
type ChatCreateRequest struct {
Name string `json:"name"`
Owner string `json:"owner"`
UserIdList []string `json:"useridlist"`
ShowHistoryType int `json:"showHistoryType,omitempty"`
}
type ChatUpdateResponse struct {
OpenAPIResponse
}
type ChatUpdateRequest struct {
ChatId string `json:"chatid"`
Name string `json:"name,omitempty"`
Owner string `json:"owner,omitempty"`
AddUserIdList []string `json:"add_useridlist,omitempty"`
DelUserIdList []string `json:"del_useridlist,omitempty"`
}
type ChatGetResponse struct {
OpenAPIResponse
ChatInfo ChatGetInfo `json:"chat_info"`
}
type ChatGetInfo struct {
Name string
Owner string
UserIdList []string `json:"useridlist"`
}
type ChatSendResponse struct {
OpenAPIResponse
}
type ChatSendRequest struct {
ChatId string `json:"chatid"`
MsgType string `json:"msgtype"`
}
type ChatSendActionCardRequest struct {
ChatSendRequest
ActionCard *ChatSendActionCard `json:"action_card"`
}
type ChatSendActionCard struct {
Title string `json:"title"`
Markdown string `json:"markdown"`
SingleTitle string `json:"single_title,omitempty"`
SingleUrl string `json:"single_url,omitempty"`
BtnOrientation string `json:"btn_orientation,omitempty"`
BtnJSONList interface{} `json:"btn_json_list,omitempty"`
AgentId string `json:"agentid,omitempty"`
}
type ChatSendTextRequest struct {
ChatSendRequest
Text *ChatSendText `json:"text"`
}
type ChatSendText struct {
Content string `json:"content"`
}
type ChatSendImageRequest struct {
ChatSendRequest
Image *ChatSendImage `json:"image"`
}
type ChatSendImage struct {
MediaId string `json:"media_id"`
}
type ChatSendVoiceRequest struct {
ChatSendRequest
Voice *ChatSendVoice `json:"voice"`
}
type ChatSendVoice struct {
MediaId string `json:"media_id"`
Duration string `json:"duration"`
}
type ChatSendFileRequest struct {
ChatSendRequest
File *ChatSendFile `json:"file"`
}
type ChatSendFile struct {
MediaId string `json:"media_id"`
}
type ChatSendLinkRequest struct {
ChatSendRequest
Link *ChatSendLink `json:"link"`
}
type ChatSendLink struct {
Title string `json:"title"`
Text string `json:"text"`
PicUrl string `json:"pic_url"`
MessageUrl string `json:"message_url"`
}
type ChatSendOARequest struct {
ChatSendRequest
Oa *ChatSendOA `json:"oa"`
}
type ChatSendOA struct {
MessageUrl string `json:"message_url"`
PcMessageUrl string `json:"pc_message_url,omitempty"`
Head interface{} `json:"head"`
Body interface{} `json:"body"`
}
type ChatSendMarkdownRequest struct {
ChatSendRequest
Markdown *ChatSendMarkdown `json:"markdown"`
}
type ChatSendMarkdown struct {
Title string `json:"title"`
Text string `json:"text"`
}
// 创建会话
func (dtc *DingTalkClient) ChatCreate(info *ChatCreateRequest) (ChatCreateResponse, error) {
var data ChatCreateResponse
err := dtc.httpRPC("chat/create", nil, info, &data)
return data, err
}
// 修改会话
func (dtc *DingTalkClient) ChatUpdate(info *ChatUpdateRequest) (ChatUpdateResponse, error) {
var data ChatUpdateResponse
err := dtc.httpRPC("chat/update", nil, info, &data)
return data, err
}
// 获取会话
func (dtc *DingTalkClient) ChatGet(chatId string) (ChatGetResponse, error) {
var data ChatGetResponse
params := url.Values{}
params.Add("chatid", chatId)
err := dtc.httpRPC("chat/get", params, nil, &data)
return data, err
}
// 发送群消息
func (dtc *DingTalkClient) ChatSend(info interface{}) (ChatSendResponse, error) {
var data ChatSendResponse
err := dtc.httpRPC("chat/send", nil, info, &data)
return data, err
}