forked from go-lark/lark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_group.go
200 lines (178 loc) · 6.44 KB
/
api_group.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package lark
import (
"fmt"
)
const (
groupListURL = "/open-apis/chat/v3/list/"
groupInfoURL = "/open-apis/chat/v4/info/"
createGroupURL = "/open-apis/chat/v3/create/"
addGroupMemberURL = "/open-apis/chat/v4/chatter/add/"
deleteGroupMemberURL = "/open-apis/chat/v3/chatter/delete/"
updateGroupURL = "/open-apis/chat/v3/update/"
addBotToGroupURL = "/open-apis/bot/v4/add"
removeBotFromGroupURL = "/open-apis/bot/v4/remove"
disbandGroupURL = "/open-apis/chat/v4/disband"
)
// GroupListResponse .
type GroupListResponse struct {
BaseResponse
HasMore bool `json:"has_more"`
Chats []struct {
ID string `json:"id"`
Name string `json:"name"`
OwnerID string `json:"owner_id"`
} `json:"chats"`
}
// GroupInfoResponse .
type GroupInfoResponse struct {
BaseResponse
Data struct {
AddMemberVerify bool `json:"add_member_verify"`
Avatar string `json:"avatar"`
ChatID string `json:"chat_id"`
Description string `json:"description"`
GroupEmailEnabled bool `json:"group_email_enabled"`
JoinMessageVisibility string `json:"join_message_visibility"`
LeaveMessageVisibility string `json:"leave_message_visibility"`
Members []struct {
OpenID string `json:"open_id"`
} `json:"members"`
Name string `json:"name"`
OnlyOwnerAdd bool `json:"only_owner_add"`
OnlyOwnerAtAll bool `json:"only_owner_at_all"`
OnlyOwnerEdit bool `json:"only_owner_edit"`
OwnerOpenID string `json:"owner_open_id"`
SendGroupEmailPermission string `json:"send_group_email_permission"`
SendMessagePermission string `json:"send_message_permission"`
ShareAllowed bool `json:"share_allowed"`
Type string `json:"type"`
} `json:"data"`
}
// CreateGroupResponse .
type CreateGroupResponse struct {
BaseResponse
OpenChatID string `json:"open_chat_id"`
InvalidOpenID []string `json:"invalid_open_ids"`
}
// AddGroupMemberResponse .
type AddGroupMemberResponse struct {
BaseResponse
InvalidOpenID []string `json:"invalid_open_ids"`
}
// DeleteGroupMemberResponse .
type DeleteGroupMemberResponse AddGroupMemberResponse
// UpdateGroupInfoReq .
type UpdateGroupInfoReq struct {
OpenChatID string `json:"open_chat_id"`
OwnerID string `json:"owner_id,omitempty"`
OwnerEmployeeID string `json:"owner_employee_id,omitempty"`
Name string `json:"name,omitempty"`
I18nNames map[string]string `json:"i18n_names,omitempty"`
}
// UpdateGroupInfoResponse .
type UpdateGroupInfoResponse struct {
BaseResponse
OpenChatID string `json:"open_chat_id"`
}
// AddBotToGroupResponse .
type AddBotToGroupResponse = BaseResponse
// RemoveBotFromGroupResponse .
type RemoveBotFromGroupResponse = BaseResponse
// DisbandGroupResponse .
type DisbandGroupResponse = BaseResponse
// GetGroupList returns group list
func (bot *Bot) GetGroupList(pageNum, pageSize int) (*GroupListResponse, error) {
params := map[string]interface{}{
"page": pageNum,
"page_size": pageSize,
}
var respData GroupListResponse
err := bot.PostAPIRequest("GetGroupList", groupListURL, true, params, &respData)
return &respData, err
}
// GetGroupInfo returns group info
func (bot *Bot) GetGroupInfo(openChatID string) (*GroupInfoResponse, error) {
params := map[string]interface{}{
"chat_id": openChatID,
}
var respData GroupInfoResponse
err := bot.PostAPIRequest("GetGroupInfo", groupInfoURL, true, params, &respData)
return &respData, err
}
// CreateGroup creates a group
func (bot *Bot) CreateGroup(name, description string, openID []string) (*CreateGroupResponse, error) {
params := map[string]interface{}{
"name": name,
"description": description,
"open_ids": openID,
}
var respData CreateGroupResponse
err := bot.PostAPIRequest("CreateGroup", createGroupURL, true, params, &respData)
return &respData, err
}
// AddGroupMember adds a group member
func (bot *Bot) AddGroupMember(openChatID string, openID []string) (*AddGroupMemberResponse, error) {
params := map[string]interface{}{
"chat_id": openChatID,
"open_ids": openID,
}
var respData AddGroupMemberResponse
err := bot.PostAPIRequest("AddGroupMember", addGroupMemberURL, true, params, &respData)
return &respData, err
}
// AddGroupMemberByUserID adds a group member
func (bot *Bot) AddGroupMemberByUserID(openChatID string, userID []string) (*AddGroupMemberResponse, error) {
params := map[string]interface{}{
"chat_id": openChatID,
"user_ids": userID,
}
var respData AddGroupMemberResponse
err := bot.PostAPIRequest("AddGroupMemberByUserID", addGroupMemberURL, true, params, &respData)
return &respData, err
}
// DeleteGroupMember deletes a group member
func (bot *Bot) DeleteGroupMember(openChatID string, openID []string) (*DeleteGroupMemberResponse, error) {
params := map[string]interface{}{
"open_chat_id": openChatID,
"open_ids": openID,
}
var respData DeleteGroupMemberResponse
err := bot.PostAPIRequest("DeleteGroupMember", deleteGroupMemberURL, true, params, &respData)
return &respData, err
}
// UpdateGroupInfo update lark group info
func (bot *Bot) UpdateGroupInfo(params *UpdateGroupInfoReq) (*UpdateGroupInfoResponse, error) {
if params.OpenChatID == "" {
return nil, fmt.Errorf("open chat id is empty in parameters")
}
var respData UpdateGroupInfoResponse
err := bot.PostAPIRequest("UpdateGroupInfo", updateGroupURL, true, params, &respData)
return &respData, err
}
// AddBotToGroup .
func (bot *Bot) AddBotToGroup(openChatID string) (*AddBotToGroupResponse, error) {
params := map[string]interface{}{
"chat_id": openChatID,
}
var respData AddBotToGroupResponse
err := bot.PostAPIRequest("AddBotToGroup", addBotToGroupURL, true, params, &respData)
return &respData, err
}
// RemoveBotFromGroup .
func (bot *Bot) RemoveBotFromGroup(openChatID string) (*RemoveBotFromGroupResponse, error) {
params := map[string]interface{}{
"chat_id": openChatID,
}
var respData RemoveBotFromGroupResponse
err := bot.PostAPIRequest("RemoveBotFromGroup", removeBotFromGroupURL, true, params, &respData)
return &respData, err
}
// DisbandGroup .
func (bot *Bot) DisbandGroup(openChatID string) (*DisbandGroupResponse, error) {
params := map[string]interface{}{
"chat_id": openChatID,
}
var respData DisbandGroupResponse
err := bot.PostAPIRequest("DisbandGroup", disbandGroupURL, true, params, &respData)
return &respData, err
}