-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.go
991 lines (916 loc) · 35.9 KB
/
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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
// Code generated by GetStream internal OpenAPI code generator. DO NOT EDIT.
package getstream
import (
"context"
)
type ChatClient struct {
client *Client
}
func NewChatClient(client *Client) *ChatClient {
return &ChatClient{
client: client,
}
}
// Query channels with filter query
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) QueryChannels(ctx context.Context, request *QueryChannelsRequest) (*StreamResponse[QueryChannelsResponse], error) {
var result QueryChannelsResponse
res, err := MakeRequest[QueryChannelsRequest, QueryChannelsResponse](c.client, ctx, "POST", "/api/v2/chat/channels", nil, request, &result, nil)
return res, err
}
// Allows to delete several channels at once asynchronously
//
// Sends events:
// - channel.deleted
//
// Required permissions:
// - DeleteChannel
func (c *ChatClient) DeleteChannels(ctx context.Context, request *DeleteChannelsRequest) (*StreamResponse[DeleteChannelsResponse], error) {
var result DeleteChannelsResponse
res, err := MakeRequest[DeleteChannelsRequest, DeleteChannelsResponse](c.client, ctx, "POST", "/api/v2/chat/channels/delete", nil, request, &result, nil)
return res, err
}
// Marks channels as read up to the specific message. If no channels is given, mark all channel as read
//
// Sends events:
// - message.read
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) MarkChannelsRead(ctx context.Context, request *MarkChannelsReadRequest) (*StreamResponse[MarkReadResponse], error) {
var result MarkReadResponse
res, err := MakeRequest[MarkChannelsReadRequest, MarkReadResponse](c.client, ctx, "POST", "/api/v2/chat/channels/read", nil, request, &result, nil)
return res, err
}
// This Method creates a channel or returns an existing one with matching attributes
//
// Sends events:
// - channel.created
// - member.added
// - member.removed
// - member.updated
// - user.watching.start
func (c *ChatClient) GetOrCreateDistinctChannel(ctx context.Context, _type string, request *GetOrCreateDistinctChannelRequest) (*StreamResponse[ChannelStateResponse], error) {
var result ChannelStateResponse
pathParams := map[string]string{
"type": _type,
}
res, err := MakeRequest[GetOrCreateDistinctChannelRequest, ChannelStateResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/query", nil, request, &result, pathParams)
return res, err
}
// Deletes channel
//
// Sends events:
// - channel.deleted
//
// Required permissions:
// - DeleteChannel
func (c *ChatClient) DeleteChannel(ctx context.Context, _type string, id string, request *DeleteChannelRequest) (*StreamResponse[DeleteChannelResponse], error) {
var result DeleteChannelResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, DeleteChannelResponse](c.client, ctx, "DELETE", "/api/v2/chat/channels/{type}/{id}", params, nil, &result, pathParams)
return res, err
}
// Updates certain fields of the channel
//
// Sends events:
// - channel.updated
//
// Required permissions:
// - UpdateChannel
// - UpdateChannelCooldown
// - UpdateChannelFrozen
func (c *ChatClient) UpdateChannelPartial(ctx context.Context, _type string, id string, request *UpdateChannelPartialRequest) (*StreamResponse[UpdateChannelPartialResponse], error) {
var result UpdateChannelPartialResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[UpdateChannelPartialRequest, UpdateChannelPartialResponse](c.client, ctx, "PATCH", "/api/v2/chat/channels/{type}/{id}", nil, request, &result, pathParams)
return res, err
}
// Change channel data
//
// Sends events:
// - channel.updated
// - member.added
// - member.removed
// - member.updated
// - message.new
//
// Required permissions:
// - AddOwnChannelMembership
// - RemoveOwnChannelMembership
// - UpdateChannel
// - UpdateChannelCooldown
// - UpdateChannelFrozen
// - UpdateChannelMembers
func (c *ChatClient) UpdateChannel(ctx context.Context, _type string, id string, request *UpdateChannelRequest) (*StreamResponse[UpdateChannelResponse], error) {
var result UpdateChannelResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[UpdateChannelRequest, UpdateChannelResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}", nil, request, &result, pathParams)
return res, err
}
// Sends event to the channel
//
// Required permissions:
// - SendCustomEvent
func (c *ChatClient) SendEvent(ctx context.Context, _type string, id string, request *SendEventRequest) (*StreamResponse[EventResponse], error) {
var result EventResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[SendEventRequest, EventResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/event", nil, request, &result, pathParams)
return res, err
}
// Deletes previously uploaded file
//
// Required permissions:
// - DeleteAttachment
func (c *ChatClient) DeleteFile(ctx context.Context, _type string, id string, request *DeleteFileRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"type": _type,
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, Response](c.client, ctx, "DELETE", "/api/v2/chat/channels/{type}/{id}/file", params, nil, &result, pathParams)
return res, err
}
// Uploads file
//
// Required permissions:
// - UploadAttachment
func (c *ChatClient) UploadFile(ctx context.Context, _type string, id string, request *UploadFileRequest) (*StreamResponse[FileUploadResponse], error) {
var result FileUploadResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[UploadFileRequest, FileUploadResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/file", nil, request, &result, pathParams)
return res, err
}
// Marks channel as hidden for current user
//
// Sends events:
// - channel.hidden
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) HideChannel(ctx context.Context, _type string, id string, request *HideChannelRequest) (*StreamResponse[HideChannelResponse], error) {
var result HideChannelResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[HideChannelRequest, HideChannelResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/hide", nil, request, &result, pathParams)
return res, err
}
// Deletes previously uploaded image
//
// Required permissions:
// - DeleteAttachment
func (c *ChatClient) DeleteImage(ctx context.Context, _type string, id string, request *DeleteImageRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"type": _type,
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, Response](c.client, ctx, "DELETE", "/api/v2/chat/channels/{type}/{id}/image", params, nil, &result, pathParams)
return res, err
}
// Uploads image
//
// Required permissions:
// - UploadAttachment
func (c *ChatClient) UploadImage(ctx context.Context, _type string, id string, request *UploadImageRequest) (*StreamResponse[ImageUploadResponse], error) {
var result ImageUploadResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[UploadImageRequest, ImageUploadResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/image", nil, request, &result, pathParams)
return res, err
}
func (c *ChatClient) UpdateMemberPartial(ctx context.Context, userID string, _type string, id string, request *UpdateMemberPartialRequest) (*StreamResponse[UpdateMemberPartialResponse], error) {
var result UpdateMemberPartialResponse
pathParams := map[string]string{
"user_id": userID,
"type": _type,
"id": id,
}
res, err := MakeRequest[UpdateMemberPartialRequest, UpdateMemberPartialResponse](c.client, ctx, "PATCH", "/api/v2/chat/channels/{type}/{id}/member/{user_id}", nil, request, &result, pathParams)
return res, err
}
// Sends new message to the specified channel
//
// Sends events:
// - message.new
// - message.updated
//
// Required permissions:
// - AddLinks
// - CreateMessage
// - PinMessage
// - SkipChannelCooldown
// - SkipMessageModeration
// - UseFrozenChannel
func (c *ChatClient) SendMessage(ctx context.Context, _type string, id string, request *SendMessageRequest) (*StreamResponse[SendMessageResponse], error) {
var result SendMessageResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[SendMessageRequest, SendMessageResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/message", nil, request, &result, pathParams)
return res, err
}
// Returns list messages found by IDs
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) GetManyMessages(ctx context.Context, _type string, id string, request *GetManyMessagesRequest) (*StreamResponse[GetManyMessagesResponse], error) {
var result GetManyMessagesResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, GetManyMessagesResponse](c.client, ctx, "GET", "/api/v2/chat/channels/{type}/{id}/messages", params, nil, &result, pathParams)
return res, err
}
// This Method creates a channel or returns an existing one with matching attributes
//
// Sends events:
// - channel.created
// - member.added
// - member.removed
// - member.updated
// - user.watching.start
func (c *ChatClient) GetOrCreateChannel(ctx context.Context, _type string, id string, request *GetOrCreateChannelRequest) (*StreamResponse[ChannelStateResponse], error) {
var result ChannelStateResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[GetOrCreateChannelRequest, ChannelStateResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/query", nil, request, &result, pathParams)
return res, err
}
// Marks channel as read up to the specific message
//
// Sends events:
// - message.read
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) MarkRead(ctx context.Context, _type string, id string, request *MarkReadRequest) (*StreamResponse[MarkReadResponse], error) {
var result MarkReadResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[MarkReadRequest, MarkReadResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/read", nil, request, &result, pathParams)
return res, err
}
// Shows previously hidden channel
//
// Sends events:
// - channel.visible
func (c *ChatClient) ShowChannel(ctx context.Context, _type string, id string, request *ShowChannelRequest) (*StreamResponse[ShowChannelResponse], error) {
var result ShowChannelResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[ShowChannelRequest, ShowChannelResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/show", nil, request, &result, pathParams)
return res, err
}
// Truncates channel
//
// Sends events:
// - channel.truncated
//
// Required permissions:
// - DeleteChannel
// - TruncateChannel
func (c *ChatClient) TruncateChannel(ctx context.Context, _type string, id string, request *TruncateChannelRequest) (*StreamResponse[TruncateChannelResponse], error) {
var result TruncateChannelResponse
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[TruncateChannelRequest, TruncateChannelResponse](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/truncate", nil, request, &result, pathParams)
return res, err
}
// Marks channel as unread from a specific message
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) MarkUnread(ctx context.Context, _type string, id string, request *MarkUnreadRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"type": _type,
"id": id,
}
res, err := MakeRequest[MarkUnreadRequest, Response](c.client, ctx, "POST", "/api/v2/chat/channels/{type}/{id}/unread", nil, request, &result, pathParams)
return res, err
}
// Lists all available channel types
func (c *ChatClient) ListChannelTypes(ctx context.Context, request *ListChannelTypesRequest) (*StreamResponse[ListChannelTypesResponse], error) {
var result ListChannelTypesResponse
res, err := MakeRequest[any, ListChannelTypesResponse](c.client, ctx, "GET", "/api/v2/chat/channeltypes", nil, nil, &result, nil)
return res, err
}
// Creates new channel type
func (c *ChatClient) CreateChannelType(ctx context.Context, request *CreateChannelTypeRequest) (*StreamResponse[CreateChannelTypeResponse], error) {
var result CreateChannelTypeResponse
res, err := MakeRequest[CreateChannelTypeRequest, CreateChannelTypeResponse](c.client, ctx, "POST", "/api/v2/chat/channeltypes", nil, request, &result, nil)
return res, err
}
// Deletes channel type
func (c *ChatClient) DeleteChannelType(ctx context.Context, name string, request *DeleteChannelTypeRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"name": name,
}
res, err := MakeRequest[any, Response](c.client, ctx, "DELETE", "/api/v2/chat/channeltypes/{name}", nil, nil, &result, pathParams)
return res, err
}
// Gets channel type
func (c *ChatClient) GetChannelType(ctx context.Context, name string, request *GetChannelTypeRequest) (*StreamResponse[GetChannelTypeResponse], error) {
var result GetChannelTypeResponse
pathParams := map[string]string{
"name": name,
}
res, err := MakeRequest[any, GetChannelTypeResponse](c.client, ctx, "GET", "/api/v2/chat/channeltypes/{name}", nil, nil, &result, pathParams)
return res, err
}
// Updates channel type
func (c *ChatClient) UpdateChannelType(ctx context.Context, name string, request *UpdateChannelTypeRequest) (*StreamResponse[UpdateChannelTypeResponse], error) {
var result UpdateChannelTypeResponse
pathParams := map[string]string{
"name": name,
}
res, err := MakeRequest[UpdateChannelTypeRequest, UpdateChannelTypeResponse](c.client, ctx, "PUT", "/api/v2/chat/channeltypes/{name}", nil, request, &result, pathParams)
return res, err
}
// Returns all custom commands
func (c *ChatClient) ListCommands(ctx context.Context, request *ListCommandsRequest) (*StreamResponse[ListCommandsResponse], error) {
var result ListCommandsResponse
res, err := MakeRequest[any, ListCommandsResponse](c.client, ctx, "GET", "/api/v2/chat/commands", nil, nil, &result, nil)
return res, err
}
// Creates custom chat command
func (c *ChatClient) CreateCommand(ctx context.Context, request *CreateCommandRequest) (*StreamResponse[CreateCommandResponse], error) {
var result CreateCommandResponse
res, err := MakeRequest[CreateCommandRequest, CreateCommandResponse](c.client, ctx, "POST", "/api/v2/chat/commands", nil, request, &result, nil)
return res, err
}
// Deletes custom chat command
func (c *ChatClient) DeleteCommand(ctx context.Context, name string, request *DeleteCommandRequest) (*StreamResponse[DeleteCommandResponse], error) {
var result DeleteCommandResponse
pathParams := map[string]string{
"name": name,
}
res, err := MakeRequest[any, DeleteCommandResponse](c.client, ctx, "DELETE", "/api/v2/chat/commands/{name}", nil, nil, &result, pathParams)
return res, err
}
// Returns custom command by its name
func (c *ChatClient) GetCommand(ctx context.Context, name string, request *GetCommandRequest) (*StreamResponse[GetCommandResponse], error) {
var result GetCommandResponse
pathParams := map[string]string{
"name": name,
}
res, err := MakeRequest[any, GetCommandResponse](c.client, ctx, "GET", "/api/v2/chat/commands/{name}", nil, nil, &result, pathParams)
return res, err
}
// Updates custom chat command
func (c *ChatClient) UpdateCommand(ctx context.Context, name string, request *UpdateCommandRequest) (*StreamResponse[UpdateCommandResponse], error) {
var result UpdateCommandResponse
pathParams := map[string]string{
"name": name,
}
res, err := MakeRequest[UpdateCommandRequest, UpdateCommandResponse](c.client, ctx, "PUT", "/api/v2/chat/commands/{name}", nil, request, &result, pathParams)
return res, err
}
// Exports channel data to JSON file
func (c *ChatClient) ExportChannels(ctx context.Context, request *ExportChannelsRequest) (*StreamResponse[ExportChannelsResponse], error) {
var result ExportChannelsResponse
res, err := MakeRequest[ExportChannelsRequest, ExportChannelsResponse](c.client, ctx, "POST", "/api/v2/chat/export_channels", nil, request, &result, nil)
return res, err
}
func (c *ChatClient) GetExportChannelsStatus(ctx context.Context, id string, request *GetExportChannelsStatusRequest) (*StreamResponse[GetExportChannelsStatusResponse], error) {
var result GetExportChannelsStatusResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[any, GetExportChannelsStatusResponse](c.client, ctx, "GET", "/api/v2/chat/export_channels/{id}", nil, nil, &result, pathParams)
return res, err
}
// Find and filter channel members
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) QueryMembers(ctx context.Context, request *QueryMembersRequest) (*StreamResponse[MembersResponse], error) {
var result MembersResponse
params := extractQueryParams(request)
res, err := MakeRequest[any, MembersResponse](c.client, ctx, "GET", "/api/v2/chat/members", params, nil, &result, nil)
return res, err
}
// Queries history for one message
func (c *ChatClient) QueryMessageHistory(ctx context.Context, request *QueryMessageHistoryRequest) (*StreamResponse[QueryMessageHistoryResponse], error) {
var result QueryMessageHistoryResponse
res, err := MakeRequest[QueryMessageHistoryRequest, QueryMessageHistoryResponse](c.client, ctx, "POST", "/api/v2/chat/messages/history", nil, request, &result, nil)
return res, err
}
// Deletes message
//
// Sends events:
// - message.deleted
//
// Required permissions:
// - DeleteMessage
func (c *ChatClient) DeleteMessage(ctx context.Context, id string, request *DeleteMessageRequest) (*StreamResponse[DeleteMessageResponse], error) {
var result DeleteMessageResponse
pathParams := map[string]string{
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, DeleteMessageResponse](c.client, ctx, "DELETE", "/api/v2/chat/messages/{id}", params, nil, &result, pathParams)
return res, err
}
// Returns message by ID
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) GetMessage(ctx context.Context, id string, request *GetMessageRequest) (*StreamResponse[GetMessageResponse], error) {
var result GetMessageResponse
pathParams := map[string]string{
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, GetMessageResponse](c.client, ctx, "GET", "/api/v2/chat/messages/{id}", params, nil, &result, pathParams)
return res, err
}
// Updates message with new data
//
// Sends events:
// - message.updated
//
// Required permissions:
// - AddLinks
// - PinMessage
// - SkipMessageModeration
// - UpdateMessage
func (c *ChatClient) UpdateMessage(ctx context.Context, id string, request *UpdateMessageRequest) (*StreamResponse[UpdateMessageResponse], error) {
var result UpdateMessageResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[UpdateMessageRequest, UpdateMessageResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}", nil, request, &result, pathParams)
return res, err
}
// Updates certain fields of the message
//
// Sends events:
// - message.updated
//
// Required permissions:
// - AddLinks
// - PinMessage
// - SkipMessageModeration
// - UpdateMessage
func (c *ChatClient) UpdateMessagePartial(ctx context.Context, id string, request *UpdateMessagePartialRequest) (*StreamResponse[UpdateMessagePartialResponse], error) {
var result UpdateMessagePartialResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[UpdateMessagePartialRequest, UpdateMessagePartialResponse](c.client, ctx, "PUT", "/api/v2/chat/messages/{id}", nil, request, &result, pathParams)
return res, err
}
// Executes message command action with given parameters
//
// Sends events:
// - message.new
//
// Required permissions:
// - RunMessageAction
func (c *ChatClient) RunMessageAction(ctx context.Context, id string, request *RunMessageActionRequest) (*StreamResponse[MessageResponse], error) {
var result MessageResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[RunMessageActionRequest, MessageResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}/action", nil, request, &result, pathParams)
return res, err
}
// Commits a pending message, which will make it visible in the channel
//
// Sends events:
// - message.new
// - message.updated
func (c *ChatClient) CommitMessage(ctx context.Context, id string, request *CommitMessageRequest) (*StreamResponse[MessageResponse], error) {
var result MessageResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[CommitMessageRequest, MessageResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}/commit", nil, request, &result, pathParams)
return res, err
}
// Sends reaction to specified message
//
// Sends events:
// - reaction.new
// - reaction.updated
//
// Required permissions:
// - CreateReaction
// - UseFrozenChannel
func (c *ChatClient) SendReaction(ctx context.Context, id string, request *SendReactionRequest) (*StreamResponse[SendReactionResponse], error) {
var result SendReactionResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[SendReactionRequest, SendReactionResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}/reaction", nil, request, &result, pathParams)
return res, err
}
// Removes user reaction from the message
//
// Sends events:
// - reaction.deleted
//
// Required permissions:
// - DeleteReaction
func (c *ChatClient) DeleteReaction(ctx context.Context, id string, _type string, request *DeleteReactionRequest) (*StreamResponse[ReactionRemovalResponse], error) {
var result ReactionRemovalResponse
pathParams := map[string]string{
"id": id,
"type": _type,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, ReactionRemovalResponse](c.client, ctx, "DELETE", "/api/v2/chat/messages/{id}/reaction/{type}", params, nil, &result, pathParams)
return res, err
}
// Returns list of reactions of specific message
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) GetReactions(ctx context.Context, id string, request *GetReactionsRequest) (*StreamResponse[GetReactionsResponse], error) {
var result GetReactionsResponse
pathParams := map[string]string{
"id": id,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, GetReactionsResponse](c.client, ctx, "GET", "/api/v2/chat/messages/{id}/reactions", params, nil, &result, pathParams)
return res, err
}
// Get reactions on a message
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) QueryReactions(ctx context.Context, id string, request *QueryReactionsRequest) (*StreamResponse[QueryReactionsResponse], error) {
var result QueryReactionsResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[QueryReactionsRequest, QueryReactionsResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}/reactions", nil, request, &result, pathParams)
return res, err
}
// Translates message to a given language using automated translation software
//
// Sends events:
// - message.updated
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) TranslateMessage(ctx context.Context, id string, request *TranslateMessageRequest) (*StreamResponse[MessageResponse], error) {
var result MessageResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[TranslateMessageRequest, MessageResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}/translate", nil, request, &result, pathParams)
return res, err
}
// Undelete a message that was previously soft-deleted
//
// Sends events:
// - message.undeleted
func (c *ChatClient) UndeleteMessage(ctx context.Context, id string, request *UndeleteMessageRequest) (*StreamResponse[UpdateMessageResponse], error) {
var result UpdateMessageResponse
pathParams := map[string]string{
"id": id,
}
res, err := MakeRequest[UndeleteMessageRequest, UpdateMessageResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{id}/undelete", nil, request, &result, pathParams)
return res, err
}
// Cast a vote on a poll
//
// Sends events:
// - poll.vote_casted
//
// Required permissions:
// - CastVote
func (c *ChatClient) CastPollVote(ctx context.Context, messageID string, pollID string, request *CastPollVoteRequest) (*StreamResponse[PollVoteResponse], error) {
var result PollVoteResponse
pathParams := map[string]string{
"message_id": messageID,
"poll_id": pollID,
}
res, err := MakeRequest[CastPollVoteRequest, PollVoteResponse](c.client, ctx, "POST", "/api/v2/chat/messages/{message_id}/polls/{poll_id}/vote", nil, request, &result, pathParams)
return res, err
}
// Delete a vote from a poll
//
// Sends events:
// - poll.vote_removed
//
// Required permissions:
// - CastVote
func (c *ChatClient) RemovePollVote(ctx context.Context, messageID string, pollID string, voteID string, request *RemovePollVoteRequest) (*StreamResponse[PollVoteResponse], error) {
var result PollVoteResponse
pathParams := map[string]string{
"message_id": messageID,
"poll_id": pollID,
"vote_id": voteID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, PollVoteResponse](c.client, ctx, "DELETE", "/api/v2/chat/messages/{message_id}/polls/{poll_id}/vote/{vote_id}", params, nil, &result, pathParams)
return res, err
}
// Returns replies (thread) of the message
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) GetReplies(ctx context.Context, parentID string, request *GetRepliesRequest) (*StreamResponse[GetRepliesResponse], error) {
var result GetRepliesResponse
pathParams := map[string]string{
"parent_id": parentID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, GetRepliesResponse](c.client, ctx, "GET", "/api/v2/chat/messages/{parent_id}/replies", params, nil, &result, pathParams)
return res, err
}
// Find and filter message flags
//
// Required permissions:
// - ReadMessageFlags
func (c *ChatClient) QueryMessageFlags(ctx context.Context, request *QueryMessageFlagsRequest) (*StreamResponse[QueryMessageFlagsResponse], error) {
var result QueryMessageFlagsResponse
params := extractQueryParams(request)
res, err := MakeRequest[any, QueryMessageFlagsResponse](c.client, ctx, "GET", "/api/v2/chat/moderation/flags/message", params, nil, &result, nil)
return res, err
}
// Mutes channel for user
//
// Sends events:
// - channel.muted
//
// Required permissions:
// - MuteChannel
func (c *ChatClient) MuteChannel(ctx context.Context, request *MuteChannelRequest) (*StreamResponse[MuteChannelResponse], error) {
var result MuteChannelResponse
res, err := MakeRequest[MuteChannelRequest, MuteChannelResponse](c.client, ctx, "POST", "/api/v2/chat/moderation/mute/channel", nil, request, &result, nil)
return res, err
}
// Unmutes channel for user
//
// Sends events:
// - channel.unmuted
//
// Required permissions:
// - MuteChannel
func (c *ChatClient) UnmuteChannel(ctx context.Context, request *UnmuteChannelRequest) (*StreamResponse[UnmuteResponse], error) {
var result UnmuteResponse
res, err := MakeRequest[UnmuteChannelRequest, UnmuteResponse](c.client, ctx, "POST", "/api/v2/chat/moderation/unmute/channel", nil, request, &result, nil)
return res, err
}
// Creates a new poll
//
// Required permissions:
// - CreatePoll
func (c *ChatClient) CreatePoll(ctx context.Context, request *CreatePollRequest) (*StreamResponse[PollResponse], error) {
var result PollResponse
res, err := MakeRequest[CreatePollRequest, PollResponse](c.client, ctx, "POST", "/api/v2/chat/polls", nil, request, &result, nil)
return res, err
}
// Updates a poll
//
// Sends events:
// - poll.closed
// - poll.updated
//
// Required permissions:
// - UpdatePoll
func (c *ChatClient) UpdatePoll(ctx context.Context, request *UpdatePollRequest) (*StreamResponse[PollResponse], error) {
var result PollResponse
res, err := MakeRequest[UpdatePollRequest, PollResponse](c.client, ctx, "PUT", "/api/v2/chat/polls", nil, request, &result, nil)
return res, err
}
// Queries polls
func (c *ChatClient) QueryPolls(ctx context.Context, request *QueryPollsRequest) (*StreamResponse[QueryPollsResponse], error) {
var result QueryPollsResponse
params := extractQueryParams(request)
res, err := MakeRequest[QueryPollsRequest, QueryPollsResponse](c.client, ctx, "POST", "/api/v2/chat/polls/query", params, request, &result, nil)
return res, err
}
// Deletes a poll
//
// Sends events:
// - poll.deleted
//
// Required permissions:
// - DeletePoll
func (c *ChatClient) DeletePoll(ctx context.Context, pollID string, request *DeletePollRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"poll_id": pollID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, Response](c.client, ctx, "DELETE", "/api/v2/chat/polls/{poll_id}", params, nil, &result, pathParams)
return res, err
}
// Retrieves a poll
func (c *ChatClient) GetPoll(ctx context.Context, pollID string, request *GetPollRequest) (*StreamResponse[PollResponse], error) {
var result PollResponse
pathParams := map[string]string{
"poll_id": pollID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, PollResponse](c.client, ctx, "GET", "/api/v2/chat/polls/{poll_id}", params, nil, &result, pathParams)
return res, err
}
// Updates a poll partially
//
// Sends events:
// - poll.updated
//
// Required permissions:
// - UpdatePoll
func (c *ChatClient) UpdatePollPartial(ctx context.Context, pollID string, request *UpdatePollPartialRequest) (*StreamResponse[PollResponse], error) {
var result PollResponse
pathParams := map[string]string{
"poll_id": pollID,
}
res, err := MakeRequest[UpdatePollPartialRequest, PollResponse](c.client, ctx, "PATCH", "/api/v2/chat/polls/{poll_id}", nil, request, &result, pathParams)
return res, err
}
// Creates a poll option
//
// Sends events:
// - poll.updated
//
// Required permissions:
// - CastVote
// - UpdatePoll
func (c *ChatClient) CreatePollOption(ctx context.Context, pollID string, request *CreatePollOptionRequest) (*StreamResponse[PollOptionResponse], error) {
var result PollOptionResponse
pathParams := map[string]string{
"poll_id": pollID,
}
res, err := MakeRequest[CreatePollOptionRequest, PollOptionResponse](c.client, ctx, "POST", "/api/v2/chat/polls/{poll_id}/options", nil, request, &result, pathParams)
return res, err
}
// Updates a poll option
//
// Sends events:
// - poll.updated
//
// Required permissions:
// - UpdatePoll
func (c *ChatClient) UpdatePollOption(ctx context.Context, pollID string, request *UpdatePollOptionRequest) (*StreamResponse[PollOptionResponse], error) {
var result PollOptionResponse
pathParams := map[string]string{
"poll_id": pollID,
}
res, err := MakeRequest[UpdatePollOptionRequest, PollOptionResponse](c.client, ctx, "PUT", "/api/v2/chat/polls/{poll_id}/options", nil, request, &result, pathParams)
return res, err
}
// Deletes a poll option
//
// Sends events:
// - poll.updated
//
// Required permissions:
// - UpdatePoll
func (c *ChatClient) DeletePollOption(ctx context.Context, pollID string, optionID string, request *DeletePollOptionRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"poll_id": pollID,
"option_id": optionID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, Response](c.client, ctx, "DELETE", "/api/v2/chat/polls/{poll_id}/options/{option_id}", params, nil, &result, pathParams)
return res, err
}
// Retrieves a poll option
func (c *ChatClient) GetPollOption(ctx context.Context, pollID string, optionID string, request *GetPollOptionRequest) (*StreamResponse[PollOptionResponse], error) {
var result PollOptionResponse
pathParams := map[string]string{
"poll_id": pollID,
"option_id": optionID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, PollOptionResponse](c.client, ctx, "GET", "/api/v2/chat/polls/{poll_id}/options/{option_id}", params, nil, &result, pathParams)
return res, err
}
// Queries votes
func (c *ChatClient) QueryPollVotes(ctx context.Context, pollID string, request *QueryPollVotesRequest) (*StreamResponse[PollVotesResponse], error) {
var result PollVotesResponse
pathParams := map[string]string{
"poll_id": pollID,
}
params := extractQueryParams(request)
res, err := MakeRequest[QueryPollVotesRequest, PollVotesResponse](c.client, ctx, "POST", "/api/v2/chat/polls/{poll_id}/votes", params, request, &result, pathParams)
return res, err
}
// Find and filter channel scoped or global user bans
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) QueryBannedUsers(ctx context.Context, request *QueryBannedUsersRequest) (*StreamResponse[QueryBannedUsersResponse], error) {
var result QueryBannedUsersResponse
params := extractQueryParams(request)
res, err := MakeRequest[any, QueryBannedUsersResponse](c.client, ctx, "GET", "/api/v2/chat/query_banned_users", params, nil, &result, nil)
return res, err
}
// Search messages across channels
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) Search(ctx context.Context, request *SearchRequest) (*StreamResponse[SearchResponse], error) {
var result SearchResponse
params := extractQueryParams(request)
res, err := MakeRequest[any, SearchResponse](c.client, ctx, "GET", "/api/v2/chat/search", params, nil, &result, nil)
return res, err
}
// Returns the list of threads for specific user
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) QueryThreads(ctx context.Context, request *QueryThreadsRequest) (*StreamResponse[QueryThreadsResponse], error) {
var result QueryThreadsResponse
res, err := MakeRequest[QueryThreadsRequest, QueryThreadsResponse](c.client, ctx, "POST", "/api/v2/chat/threads", nil, request, &result, nil)
return res, err
}
// Return a specific thread
//
// Required permissions:
// - ReadChannel
func (c *ChatClient) GetThread(ctx context.Context, messageID string, request *GetThreadRequest) (*StreamResponse[GetThreadResponse], error) {
var result GetThreadResponse
pathParams := map[string]string{
"message_id": messageID,
}
params := extractQueryParams(request)
res, err := MakeRequest[any, GetThreadResponse](c.client, ctx, "GET", "/api/v2/chat/threads/{message_id}", params, nil, &result, pathParams)
return res, err
}
// Updates certain fields of the thread
//
// Sends events:
// - thread.updated
//
// Required permissions:
// - ReadChannel
// - UpdateThread
func (c *ChatClient) UpdateThreadPartial(ctx context.Context, messageID string, request *UpdateThreadPartialRequest) (*StreamResponse[UpdateThreadPartialResponse], error) {
var result UpdateThreadPartialResponse
pathParams := map[string]string{
"message_id": messageID,
}
res, err := MakeRequest[UpdateThreadPartialRequest, UpdateThreadPartialResponse](c.client, ctx, "PATCH", "/api/v2/chat/threads/{message_id}", nil, request, &result, pathParams)
return res, err
}
// Fetch unread counts for a single user
func (c *ChatClient) UnreadCounts(ctx context.Context, request *UnreadCountsRequest) (*StreamResponse[WrappedUnreadCountsResponse], error) {
var result WrappedUnreadCountsResponse
res, err := MakeRequest[any, WrappedUnreadCountsResponse](c.client, ctx, "GET", "/api/v2/chat/unread", nil, nil, &result, nil)
return res, err
}
// Fetch unread counts in batch for multiple users in one call
func (c *ChatClient) UnreadCountsBatch(ctx context.Context, request *UnreadCountsBatchRequest) (*StreamResponse[UnreadCountsBatchResponse], error) {
var result UnreadCountsBatchResponse
res, err := MakeRequest[UnreadCountsBatchRequest, UnreadCountsBatchResponse](c.client, ctx, "POST", "/api/v2/chat/unread_batch", nil, request, &result, nil)
return res, err
}
// Sends a custom event to a user
//
// Sends events:
// - *
func (c *ChatClient) SendUserCustomEvent(ctx context.Context, userID string, request *SendUserCustomEventRequest) (*StreamResponse[Response], error) {
var result Response
pathParams := map[string]string{
"user_id": userID,
}
res, err := MakeRequest[SendUserCustomEventRequest, Response](c.client, ctx, "POST", "/api/v2/chat/users/{user_id}/event", nil, request, &result, pathParams)
return res, err
}