-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin.go
More file actions
320 lines (252 loc) · 9.54 KB
/
Copy pathadmin.go
File metadata and controls
320 lines (252 loc) · 9.54 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package sendbird
// AdminService is an interface for interfacing with the Admin
// endpoints of the Sendbird API
type AdminService interface {
BroadcastMessage(params *BroadcastMessageRequest) (*Response, error)
ReadMessages(params *ReadMessagesRequest) ([]AdminMessage, *Response, error)
DeleteMessage(messageId string) (*DeleteMessage, *Response, error)
ListMessagingChannels(userId string) ([]AdminMessagingChannel, *Response, error)
MuteAllChannels(userId string) (*Response, error)
Mute(params *MuteRequest) ([]string, *Response, error)
UnMuteAllChannels(userId string) (*Response, error)
UnMute(params *UnMuteRequest) ([]string, *Response, error)
MuteList(channelUrls []string) ([]string, *Response, error)
ConcurrentUserCount() (*ConcurrentUserCount, *Response, error)
MemberCountInChannel(channelUrl string) (*ChannelMemberCount, *Response, error)
}
// AdminServiceOp handles communication with the AdminService related methods of
// the Sendbird API.
type AdminServiceOp struct {
client *SendbirdClient
}
var _ AdminService = &AdminServiceOp{}
type BroadcastMessageRequest struct {
RequestDefaults
ChannelUrls []string `json:"channel_url,omitempty"` // List of channel urls
Message string `json:"message,omitempty"` // Message to be sent
Persistent bool `json:"persistent,omitempty"` // Save the message if True
Data string `json:"data,omitempty"` // Custom data field
}
type ReadMessagesRequest struct {
RequestDefaults
ChannelUrl string `json:"channel_url,omitempty"` // (Optional) Channel url
TargetUserIds []string `json:"target_user_ids,omitempty"` // (Optional) Target messaging channel with given two users.
Limit int `json:"limit"` // A number of messages to read (default: 50)
MessageId int64 `json:"message_id"` // Read a given limit of messages before this id. Set to zero to read messages from the last.
}
type MuteRequest struct {
RequestDefaults
Id string `json:"id"` // User ID
ChannelUrls []string `json:"channel_urls"`
IsSoftMute bool `json:"is_soft_mute"` // Channel mute has two modes; hard mute and soft mute. In hard mute mode, messages from muted users are blocked in server. In soft mute mode, messages from muted users are sent to "onMuteMessagesReceived" callback in Client SDK. In most cases, what you need is "hard mute" mode
}
type UnMuteRequest struct {
RequestDefaults
Id string `json:"id"` // User ID
ChannelUrls []string `json:"channel_urls"`
}
type AdminMessage struct {
Id string `json:"id"` // Sender's ID
Nickname string `json:"nickanme"` // Sender's name
MessageId int64 `json:"message_id"` // Message ID
Timestamp int64 `json:"timestamp"` // Epoch timestamp in milliseconds
Message string `json:"message"` // Chat message
File AdminMessageFile `json:"file"` // File Info Object... Empty file info object when message is text message
}
type AdminMessageFile struct {
Url string `json:"url"` // File url
Custom string `json:"custom"` // User custom field
Type string `json:"type"` // File type
Name string `json:"name"` // File name
Size int64 `json:"size"` // File size
}
type DeleteMessage struct {
AppId int64 `json:"app_id"`
MsgId int64 `json:"msg_id"`
}
type AdminMessagingChannel struct {
ChannelUrl string `json:"channel_url"` // Channel URL
UnreadMessageCount int `json:"unread_message_count"` // Unread message count
LastMessage string `json:"last_message"` // Last message
LastMessageTS int64 `json:"last_message_ts"` // Last message timestamp, 0 if last message is empty.
Members []Member `json:"members"`
}
type ConcurrentUserCount struct {
Count int `json:"count"` // Concurrent chatting user count
}
type ChannelMemberCount struct {
AccumulatedMemberCount int `json:"accumulated_member_count"` // number of members joined the channel at least once
OnlineMemberCount int `json:"online_member_count"` // number of members currently online in the channel
MemberCount int `json:"member_count"` // number of members in the channel
}
// BroadcastMessages broadcasts an admin message to the channels
// Please note that this feature is not available on Free and Sprout plans.
func (s *AdminServiceOp) BroadcastMessage(params *BroadcastMessageRequest) (*Response, error) {
path := "/admin/broadcast_message"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
var i interface{}
resp, err := s.client.Do(req, i)
if err != nil {
return resp, err
}
return resp, nil
}
// ReadMessages reads messages from the target channel
// Either channel_url or target_user_ids must be set
func (s *AdminServiceOp) ReadMessages(params *ReadMessagesRequest) ([]AdminMessage, *Response, error) {
path := "/admin/read_messages"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, *params)
messages := []AdminMessage{}
resp, err := s.client.Do(req, &messages)
if err != nil {
return nil, resp, err
}
return messages, resp, nil
}
// DeleteMessage deletes a message from your application
func (s *AdminServiceOp) DeleteMessage(messageId string) (*DeleteMessage, *Response, error) {
path := "/admin/delete_message"
params := struct {
RequestDefaults
MsgId string `json:"msg_id"`
}{
MsgId: messageId,
}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
message := new(DeleteMessage)
resp, err := s.client.Do(req, message)
if err != nil {
return nil, resp, err
}
return message, resp, nil
}
// listMessagingChannels lists messaging channels of the target user
func (s *AdminServiceOp) ListMessagingChannels(userId string) ([]AdminMessagingChannel, *Response, error) {
path := "/admin/list_messaging_channels"
params := struct {
RequestDefaults
Id string `json:"id"`
}{
Id: userId,
}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
channels := []AdminMessagingChannel{}
resp, err := s.client.Do(req, &channels)
if err != nil {
return nil, resp, err
}
return channels, resp, nil
}
// MuteAllChannels mutes a user in all channels in your application. Prohibit a user from sending messages at all.
func (s *AdminServiceOp) MuteAllChannels(userId string) (*Response, error) {
path := "/admin/mute"
params := struct {
RequestDefaults
Id string `json:"id"`
}{
Id: userId,
}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
var i interface{}
resp, err := s.client.Do(req, i)
if err != nil {
return resp, err
}
return resp, nil
}
// Mute mutes a user in some channels in your application
func (s *AdminServiceOp) Mute(params *MuteRequest) ([]string, *Response, error) {
path := "/admin/mute"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
channels := []string{}
resp, err := s.client.Do(req, &channels)
if err != nil {
return nil, resp, err
}
return channels, resp, nil
}
// UnMuteAllChannels unmutes a user to start sending messages in your application. This doesn't unmute channel-wide mute
func (s *AdminServiceOp) UnMuteAllChannels(userId string) (*Response, error) {
path := "/admin/unmute"
params := struct {
RequestDefaults
Id string `json:"id"`
}{
Id: userId,
}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
var i interface{}
resp, err := s.client.Do(req, i)
if err != nil {
return resp, err
}
return resp, nil
}
// UnMute unmutes a user in some channels in your application
func (s *AdminServiceOp) UnMute(params *UnMuteRequest) ([]string, *Response, error) {
path := "/admin/unmute"
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
channels := []string{}
resp, err := s.client.Do(req, &channels)
if err != nil {
return nil, resp, err
}
return channels, resp, nil
}
// MuteList gets the list of muted user ids in application-wide mute
func (s *AdminServiceOp) MuteList(channelUrls []string) ([]string, *Response, error) {
path := "/admin/mute_list"
params := struct {
RequestDefaults
ChannelUrls []string `json:"channel_urls"`
}{
ChannelUrls: channelUrls,
}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
userIds := []string{}
resp, err := s.client.Do(req, &userIds)
if err != nil {
return nil, resp, err
}
return userIds, resp, nil
}
// ConcurrentUserCount gets the list of muted user ids in application-wide mute
func (s *AdminServiceOp) ConcurrentUserCount() (*ConcurrentUserCount, *Response, error) {
path := "/admin/ccu_count"
params := struct{ RequestDefaults }{}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
count := new(ConcurrentUserCount)
resp, err := s.client.Do(req, count)
if err != nil {
return nil, resp, err
}
return count, resp, nil
}
// MemberCountInChannel gets the list of muted user ids in application-wide mute
func (s *AdminServiceOp) MemberCountInChannel(channelUrl string) (*ChannelMemberCount, *Response, error) {
path := "/admin/member_count"
params := struct {
RequestDefaults
ChannelUrl string `json:"channel_url"`
}{
ChannelUrl: channelUrl,
}
params.PopulateAuthApiToken(s.client)
req, err := s.client.NewRequest("POST", path, params)
count := new(ChannelMemberCount)
resp, err := s.client.Do(req, count)
if err != nil {
return nil, resp, err
}
return count, resp, nil
}