forked from dodo-open/dodo-open-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.go
293 lines (256 loc) · 9.69 KB
/
channel.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package model
import "errors"
type ChannelType int
const (
TextChannel ChannelType = 1
VoiceChannel ChannelType = 2
ArticleChannel ChannelType = 4
LinkChannel ChannelType = 5
ResChannel ChannelType = 6
)
// ChannelElement 获取频道列表 list element
type ChannelElement struct {
ChannelId string `json:"channelId"` // 频道号
ChannelName string `json:"channelName"` // 频道名称
ChannelType ChannelType `json:"channelType"` // 频道类型,1:文字频道,2:语音频道,4:帖子频道,5:链接频道,6:资料频道
DefaultFlag int `json:"defaultFlag"` // 默认频道标识,0:否,1:是
GroupId string `json:"groupId"` // 分组ID
GroupName string `json:"groupName"` // 分组名称
}
// GetChannelListReq 获取频道列表 request
type GetChannelListReq struct {
IslandSourceId string `json:"islandSourceId" binding:"required"` // 群ID
}
func (p *GetChannelListReq) ValidParams() error {
if p.IslandSourceId == "" {
return errors.New("invalid parameter IslandSourceId (empty detected)")
}
return nil
}
type (
// GetChannelInfoReq 获取频道信息 request
GetChannelInfoReq struct {
ChannelId string `json:"channelId" binding:"required"` // 频道号
}
// GetChannelInfoRsp 获取频道信息 response
GetChannelInfoRsp struct {
ChannelElement
IslandSourceId string `json:"islandSourceId"` // 群ID
}
)
func (p *GetChannelInfoReq) ValidParams() error {
if p.ChannelId == "" {
return errors.New("invalid parameter ChannelId (empty detected)")
}
return nil
}
type (
// CreateChannelReq 创建频道 request
CreateChannelReq struct {
IslandSourceId string `json:"islandSourceId" binding:"required"` // 群ID
ChannelName string `json:"channelName"` // 频道名称,非必传,不传时默认使用名称`新的频道`,不能大于32个字符或16个汉字
ChannelType ChannelType `json:"channelType" binding:"required"` // 频道类型,1:文字频道,2:语音频道(默认自由模式),4:帖子频道(默认详细模式)
}
// CreateChannelRsp 创建频道 response
CreateChannelRsp struct {
ChannelId string `json:"channelId"` // 频道ID
}
)
func (p *CreateChannelReq) ValidParams() error {
if p.IslandSourceId == "" {
return errors.New("invalid parameter IslandSourceId (empty detected)")
}
if p.ChannelType == 0 {
return errors.New("invalid parameter ChannelType (zero detected)")
}
return nil
}
// EditChannelReq 编辑频道 request
type EditChannelReq struct {
IslandSourceId string `json:"islandSourceId" binding:"required"` // 群ID
ChannelId string `json:"channelId" binding:"required"` // 频道号
ChannelName string `json:"channelName,omitempty"`
}
func (p *EditChannelReq) ValidParams() error {
if p.IslandSourceId == "" {
return errors.New("invalid parameter IslandSourceId (empty detected)")
}
if p.ChannelId == "" {
return errors.New("invalid parameter ChannelId (empty detected)")
}
return nil
}
// RemoveChannelReq 删除频道 request
type RemoveChannelReq struct {
IslandSourceId string `json:"islandSourceId" binding:"required"` // 群ID
ChannelId string `json:"channelId" binding:"required"` // 频道号
}
func (p *RemoveChannelReq) ValidParams() error {
if p.IslandSourceId == "" {
return errors.New("invalid parameter IslandSourceId (empty detected)")
}
if p.ChannelId == "" {
return errors.New("invalid parameter ChannelId (empty detected)")
}
return nil
}
type (
// SendChannelMessageReq 发送消息 request
SendChannelMessageReq struct {
ChannelId string `json:"channelId" binding:"required"` // 频道号
MessageType MessageType `json:"messageType" binding:"required"` // 消息类型,该参数会在SDK中重新赋值,所以无需开发者主动设值
MessageBody IMessageBody `json:"messageBody" binding:"required"` // 消息内容
ReferencedMessageId string `json:"referencedMessageId,omitempty"` // 回复消息ID
DodoSourceId string `json:"dodoSourceId,omitempty"` // DoDoID,非必传,如果传了,则给该成员发送频道私信
}
// SendChannelMessageRsp 发送消息 response
SendChannelMessageRsp struct {
MessageId string `json:"messageId"` // 消息 ID
}
)
func (p *SendChannelMessageReq) ValidParams() error {
if p.ChannelId == "" {
return errors.New("invalid parameter ChannelId (empty detected)")
}
if p.MessageBody == nil {
return errors.New("invalid parameter MessageBody (nil detected)")
}
return nil
}
type (
// EditChannelMessageReq 编辑消息 request
EditChannelMessageReq struct {
MessageId string `json:"messageId" binding:"required"` // 欲编辑的消息 ID
MessageType MessageType `json:"messageType" binding:"required"` // 消息类型,该参数会在SDK中重新赋值,所以无需开发者主动设值
MessageBody IMessageBody `json:"messageBody" binding:"required"` // 消息内容
}
// EditChannelMessageRsp 编辑消息 response
EditChannelMessageRsp struct {
MessageId string `json:"messageId"` // 消息 ID
}
)
func (p *EditChannelMessageReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
if p.MessageBody == nil {
return errors.New("invalid parameter MessageBody (nil detected)")
}
return nil
}
// WithdrawChannelMessageReq 撤回消息 request
type WithdrawChannelMessageReq struct {
MessageId string `json:"messageId" binding:"required"` // 消息ID
Reason string `json:"reason,omitempty"` // 撤回原因
}
func (p *WithdrawChannelMessageReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
return nil
}
// AddChannelMessageReactionReq 添加表情反应 request
type AddChannelMessageReactionReq struct {
MessageId string `json:"messageId" binding:"required"` // 消息 ID
Emoji *ReactionEmoji `json:"emoji" binding:"required"` // 反应表情
}
func (p *AddChannelMessageReactionReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
if p.Emoji == nil {
return errors.New("invalid parameter Emoji (nil detected)")
}
if p.Emoji.Id == "" {
return errors.New("invalid parameter Emoji.Id (empty detected)")
}
return nil
}
// RemChannelMessageReactionReq 取消表情反应 request
type RemChannelMessageReactionReq struct {
MessageId string `json:"messageId" binding:"required"` // 消息 ID
Emoji *ReactionEmoji `json:"emoji" binding:"required"` // 反应表情
DodoSourceId string `json:"dodoSourceId,omitempty"` // DoDoID,不传或传空时表示移除机器人自身的反应
}
func (p *RemChannelMessageReactionReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
if p.Emoji == nil {
return errors.New("invalid parameter Emoji (nil detected)")
}
if p.Emoji.Id == "" {
return errors.New("invalid parameter Emoji.Id (empty detected)")
}
return nil
}
// SetChannelMessageTopReq 置顶消息
// [https://open.imdodo.com/dev/api/channel-text.html#%E7%BD%AE%E9%A1%B6%E6%B6%88%E6%81%AF]
type SetChannelMessageTopReq struct {
MessageId string `json:"messageId"`
OperateType int `json:"operateType"`
}
func (p *SetChannelMessageTopReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
if p.OperateType != 0 && p.OperateType != 1 {
return errors.New("invalid parameter operateType (empty detected)")
}
return nil
}
// GetChannelMessageReactionListReq 获取消息反应列表
// [https://open.imdodo.com/dev/api/channel-text.html#%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF%E5%8F%8D%E5%BA%94%E5%88%97%E8%A1%A8]
type GetChannelMessageReactionListReq struct {
MessageId string `json:"messageId"`
}
func (p *GetChannelMessageReactionListReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
return nil
}
// GetChannelMessageReactionListRsp 获取消息反应列表
// [https://open.imdodo.com/dev/api/channel-text.html#%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF%E5%8F%8D%E5%BA%94%E5%88%97%E8%A1%A8]
type GetChannelMessageReactionListRsp struct {
Count int `json:"count"`
Emoji struct {
Id string `json:"id"`
Type int `json:"type"`
} `json:"emoji"`
}
// GetChannelMessageReactionMemberListReq 获取消息反应内成员列表
// [https://open.imdodo.com/dev/api/channel-text.html#%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF%E5%8F%8D%E5%BA%94%E5%86%85%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8]
type GetChannelMessageReactionMemberListReq struct {
MessageId string `json:"messageId"`
Emoji struct {
Type int `json:"type"`
Id string `json:"id"`
} `json:"emoji"`
PageSize int `json:"pageSize"`
MaxId int `json:"maxId"`
}
func (p *GetChannelMessageReactionMemberListReq) ValidParams() error {
if p.MessageId == "" {
return errors.New("invalid parameter MessageId (empty detected)")
}
if p.Emoji.Id == "" {
return errors.New("invalid parameter Emoji.Id (empty detected)")
}
if p.PageSize <= 0 || p.PageSize > 100 {
return errors.New("invalid parameter PageSize (0 < PageSize <= 100)")
}
if p.MaxId < 0 {
return errors.New("invalid parameter maxId")
}
return nil
}
// GetChannelMessageReactionMemberListRsp 获取消息反应内成员列表
// [https://open.imdodo.com/dev/api/channel-text.html#%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF%E5%8F%8D%E5%BA%94%E5%86%85%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8]
type GetChannelMessageReactionMemberListRsp struct {
List []struct {
DodoSourceId string `json:"dodoSourceId"`
NickName string `json:"nickName"`
} `json:"list"`
MaxId int `json:"maxId"`
}