-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
1519 lines (1218 loc) · 50.7 KB
/
messages.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
992
993
994
995
996
997
998
999
1000
package vkbotgo
// GENERATED FILE: DO NOT EDIT
import (
"fmt"
"github.com/google/go-querystring/query"
)
// MessagesGetConversationsParams params for messages.getConversations method
//
// https://vk.com/dev/messages.getConversations
type MessagesGetConversationsParams struct {
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
// Offset needed to return a specific subset of conversations.
Offset int64 `url:"offset,omitempty"`
// Number of conversations to return.
Count int64 `url:"count,omitempty"`
// Filter to apply: 'all' — all conversations, 'unread' — conversations with unread messages, 'important' — conversations, marked as important (only for community messages), 'unanswered' — conversations, marked as unanswered (only for community messages)
Filter string `url:"filter,omitempty"`
// '1' — return extra information about users and communities
Extended bool `url:"extended,omitempty"`
// ID of the message from what to return dialogs.
StartMessageID int64 `url:"start_message_id,omitempty"`
// Profile and communities fields to return.
Fields []string `url:"fields,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetConversationsParams) Validate() error {
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
if param.Count < 0.000000 {
return fmt.Errorf("parameter Count(=%v) must be greater or equal than 0.000000", param.Count)
}
if param.Count > 200.000000 {
return fmt.Errorf("parameter Count(=%v) must be less or equal than 200.000000", param.Count)
}
enum := map[string]struct{}{"all": {}, "unread": {}, "important": {}, "unanswered": {}}
if _, ok := enum[param.Filter]; !ok {
return fmt.Errorf("parameter Filter(=%v) expected in [all unread important unanswered]", param.Filter)
}
if param.StartMessageID < 0.000000 {
return fmt.Errorf("parameter StartMessageID(=%v) must be greater or equal than 0.000000", param.StartMessageID)
}
return nil
}
// MessagesGetConversations calls VK API method messages.getConversations. Returns a list of the current user's conversations.
//
// https://vk.com/dev/messages.getConversations
func (vkBot *VkBot) MessagesGetConversations(params *MessagesGetConversationsParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getConversations", vals)
}
// MessagesGetConversationsByIdParams params for messages.getConversationsById method
//
// https://vk.com/dev/messages.getConversationsById
type MessagesGetConversationsByIdParams struct {
// Destination IDs. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerIds []int64 `url:"peer_ids"`
// Return extended properties
Extended bool `url:"extended,omitempty"`
// Profile and communities fields to return.
Fields []string `url:"fields,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetConversationsByIdParams) Validate() error {
if len(param.PeerIds) > 100 {
return fmt.Errorf("length(=%d) of parameter PeerIds must be less or equal than 100", len(param.PeerIds))
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesGetConversationsById calls VK API method messages.getConversationsById. Returns conversations by their IDs
//
// https://vk.com/dev/messages.getConversationsById
func (vkBot *VkBot) MessagesGetConversationsById(params *MessagesGetConversationsByIdParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getConversationsById", vals)
}
// MessagesGetByIdParams params for messages.getById method
//
// https://vk.com/dev/messages.getById
type MessagesGetByIdParams struct {
// Message IDs.
MessageIds []int64 `url:"message_ids"`
// Number of characters after which to truncate a previewed message. To preview the full message, specify '0'. "NOTE: Messages are not truncated by default. Messages are truncated by words."
PreviewLength int64 `url:"preview_length,omitempty"`
// Information whether the response should be extended
Extended bool `url:"extended,omitempty"`
// Profile fields to return.
Fields []string `url:"fields,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetByIdParams) Validate() error {
if len(param.MessageIds) > 100 {
return fmt.Errorf("length(=%d) of parameter MessageIds must be less or equal than 100", len(param.MessageIds))
}
for i, item := range param.MessageIds {
if item < 0.000000 {
return fmt.Errorf("item[#%d](=%v) of parameter MessageIds must be greater or equal than 0.000000", i, item)
}
}
if param.PreviewLength < 0.000000 {
return fmt.Errorf("parameter PreviewLength(=%v) must be greater or equal than 0.000000", param.PreviewLength)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesGetById calls VK API method messages.getById. Returns messages by their IDs.
//
// https://vk.com/dev/messages.getById
func (vkBot *VkBot) MessagesGetById(params *MessagesGetByIdParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getById", vals)
}
// MessagesGetByConversationMessageIdParams params for messages.getByConversationMessageId method
//
// https://vk.com/dev/messages.getByConversationMessageId
type MessagesGetByConversationMessageIdParams struct {
// Destination ID. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerID int64 `url:"peer_id,omitempty"`
// Conversation message IDs.
ConversationMessageIds []int64 `url:"conversation_message_ids"`
// Information whether the response should be extended
Extended bool `url:"extended,omitempty"`
// Profile fields to return.
Fields []string `url:"fields,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetByConversationMessageIdParams) Validate() error {
if len(param.ConversationMessageIds) > 100 {
return fmt.Errorf("length(=%d) of parameter ConversationMessageIds must be less or equal than 100", len(param.ConversationMessageIds))
}
for i, item := range param.ConversationMessageIds {
if item < 0.000000 {
return fmt.Errorf("item[#%d](=%v) of parameter ConversationMessageIds must be greater or equal than 0.000000", i, item)
}
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesGetByConversationMessageId calls VK API method messages.getByConversationMessageId. Returns messages by their IDs within the conversation.
//
// https://vk.com/dev/messages.getByConversationMessageId
func (vkBot *VkBot) MessagesGetByConversationMessageId(params *MessagesGetByConversationMessageIdParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getByConversationMessageId", vals)
}
// MessagesSearchParams params for messages.search method
//
// https://vk.com/dev/messages.search
type MessagesSearchParams struct {
// Search query string.
Q string `url:"q,omitempty"`
// Destination ID. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerID int64 `url:"peer_id,omitempty"`
// Date to search message before in Unixtime.
Date int64 `url:"date,omitempty"`
// Number of characters after which to truncate a previewed message. To preview the full message, specify '0'. "NOTE: Messages are not truncated by default. Messages are truncated by words."
PreviewLength int64 `url:"preview_length,omitempty"`
// Offset needed to return a specific subset of messages.
Offset int64 `url:"offset,omitempty"`
// Number of messages to return.
Count int64 `url:"count,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesSearchParams) Validate() error {
if param.Date < 0.000000 {
return fmt.Errorf("parameter Date(=%v) must be greater or equal than 0.000000", param.Date)
}
if param.PreviewLength < 0.000000 {
return fmt.Errorf("parameter PreviewLength(=%v) must be greater or equal than 0.000000", param.PreviewLength)
}
if param.Offset < 0.000000 {
return fmt.Errorf("parameter Offset(=%v) must be greater or equal than 0.000000", param.Offset)
}
if param.Count < 0.000000 {
return fmt.Errorf("parameter Count(=%v) must be greater or equal than 0.000000", param.Count)
}
if param.Count > 100.000000 {
return fmt.Errorf("parameter Count(=%v) must be less or equal than 100.000000", param.Count)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesSearch calls VK API method messages.search. Returns a list of the current user's private messages that match search criteria.
//
// https://vk.com/dev/messages.search
func (vkBot *VkBot) MessagesSearch(params *MessagesSearchParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.search", vals)
}
// MessagesGetHistoryParams params for messages.getHistory method
//
// https://vk.com/dev/messages.getHistory
type MessagesGetHistoryParams struct {
// Offset needed to return a specific subset of messages.
Offset int64 `url:"offset,omitempty"`
// Number of messages to return.
Count int64 `url:"count,omitempty"`
// ID of the user whose message history you want to return.
UserID int64 `url:"user_id,omitempty"`
//
PeerID int64 `url:"peer_id,omitempty"`
// Starting message ID from which to return history.
StartMessageID int64 `url:"start_message_id,omitempty"`
// Information whether the response should be extended
Extended bool `url:"extended,omitempty"`
// Profile fields to return.
Fields []string `url:"fields,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
// Sort order: '1' — return messages in chronological order. '0' — return messages in reverse chronological order.
Rev int64 `url:"rev,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetHistoryParams) Validate() error {
if param.Count < 0.000000 {
return fmt.Errorf("parameter Count(=%v) must be greater or equal than 0.000000", param.Count)
}
if param.Count > 200.000000 {
return fmt.Errorf("parameter Count(=%v) must be less or equal than 200.000000", param.Count)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
enum := map[int64]struct{}{1: {}, 0: {}}
if _, ok := enum[param.Rev]; !ok {
return fmt.Errorf("parameter Rev(=%v) expected in [1 0]", param.Rev)
}
return nil
}
// MessagesGetHistory calls VK API method messages.getHistory. Returns message history for the specified user or group chat.
//
// https://vk.com/dev/messages.getHistory
func (vkBot *VkBot) MessagesGetHistory(params *MessagesGetHistoryParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getHistory", vals)
}
// MessagesGetHistoryAttachmentsParams params for messages.getHistoryAttachments method
//
// https://vk.com/dev/messages.getHistoryAttachments
type MessagesGetHistoryAttachmentsParams struct {
// Peer ID. ", For group chat: '2000000000 + chat ID' , , For community: '-community ID'"
PeerID int64 `url:"peer_id"`
// Type of media files to return: *'photo',, *'video',, *'audio',, *'doc',, *'link'.,*'market'.,*'wall'.,*'share'
MediaType string `url:"media_type,omitempty"`
// Message ID to start return results from.
StartFrom string `url:"start_from,omitempty"`
// Number of objects to return.
Count int64 `url:"count,omitempty"`
// '1' — to return photo sizes in a
PhotoSizes bool `url:"photo_sizes,omitempty"`
// Additional profile [vk.com/dev/fields|fields] to return.
Fields []string `url:"fields,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetHistoryAttachmentsParams) Validate() error {
enum := map[string]struct{}{"photo": {}, "video": {}, "doc": {}, "audio": {}, "link": {}, "market": {}, "wall": {}, "share": {}}
if _, ok := enum[param.MediaType]; !ok {
return fmt.Errorf("parameter MediaType(=%v) expected in [photo video doc audio link market wall share]", param.MediaType)
}
if param.Count < 0.000000 {
return fmt.Errorf("parameter Count(=%v) must be greater or equal than 0.000000", param.Count)
}
if param.Count > 200.000000 {
return fmt.Errorf("parameter Count(=%v) must be less or equal than 200.000000", param.Count)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesGetHistoryAttachments calls VK API method messages.getHistoryAttachments. Returns media files from the dialog or group chat.
//
// https://vk.com/dev/messages.getHistoryAttachments
func (vkBot *VkBot) MessagesGetHistoryAttachments(params *MessagesGetHistoryAttachmentsParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getHistoryAttachments", vals)
}
// MessagesSendParams params for messages.send method
//
// https://vk.com/dev/messages.send
type MessagesSendParams struct {
// User ID (by default — current user).
UserID int64 `url:"user_id,omitempty"`
// Unique identifier to avoid resending the message.
RandomID int64 `url:"random_id,omitempty"`
// Destination ID. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerID int64 `url:"peer_id,omitempty"`
// User's short address (for example, 'illarionov').
Domain string `url:"domain,omitempty"`
// ID of conversation the message will relate to.
ChatID int64 `url:"chat_id,omitempty"`
// IDs of message recipients (if new conversation shall be started).
UserIds []int64 `url:"user_ids,omitempty"`
// (Required if 'attachments' is not set.) Text of the message.
Message string `url:"message,omitempty"`
// Geographical latitude of a check-in, in degrees (from -90 to 90).
Lat float64 `url:"lat,omitempty"`
// Geographical longitude of a check-in, in degrees (from -180 to 180).
Long float64 `url:"long,omitempty"`
// (Required if 'message' is not set.) List of objects attached to the message, separated by commas, in the following format: "<owner_id>_<media_id>", '' — Type of media attachment: 'photo' — photo, 'video' — video, 'audio' — audio, 'doc' — document, 'wall' — wall post, '<owner_id>' — ID of the media attachment owner. '<media_id>' — media attachment ID. Example: "photo100172_166443618"
Attachment []string `url:"attachment,omitempty"`
// ID of forwarded messages, separated with a comma. Listed messages of the sender will be shown in the message body at the recipient's. Example: "123,431,544"
ForwardMessages string `url:"forward_messages,omitempty"`
// Sticker id.
StickerID int64 `url:"sticker_id,omitempty"`
// '1' if the message is a notification (for community messages).
Notification bool `url:"notification,omitempty"`
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesSendParams) Validate() error {
if param.ChatID < 0.000000 {
return fmt.Errorf("parameter ChatID(=%v) must be greater or equal than 0.000000", param.ChatID)
}
if param.Lat < -90.000000 {
return fmt.Errorf("parameter Lat(=%v) must be greater or equal than -90.000000", param.Lat)
}
if param.Lat > 90.000000 {
return fmt.Errorf("parameter Lat(=%v) must be less or equal than 90.000000", param.Lat)
}
if param.Long < -180.000000 {
return fmt.Errorf("parameter Long(=%v) must be greater or equal than -180.000000", param.Long)
}
if param.Long > 180.000000 {
return fmt.Errorf("parameter Long(=%v) must be less or equal than 180.000000", param.Long)
}
if param.StickerID < 0.000000 {
return fmt.Errorf("parameter StickerID(=%v) must be greater or equal than 0.000000", param.StickerID)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesSend calls VK API method messages.send. Sends a message.
//
// https://vk.com/dev/messages.send
func (vkBot *VkBot) MessagesSend(params *MessagesSendParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.send", vals)
}
// MessagesEditParams params for messages.edit method
//
// https://vk.com/dev/messages.edit
type MessagesEditParams struct {
// Destination ID. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerID int64 `url:"peer_id"`
// (Required if 'attachments' is not set.) Text of the message.
Message string `url:"message,omitempty"`
// Geographical latitude of a check-in, in degrees (from -90 to 90).
Lat float64 `url:"lat,omitempty"`
// Geographical longitude of a check-in, in degrees (from -180 to 180).
Long float64 `url:"long,omitempty"`
// (Required if 'message' is not set.) List of objects attached to the message, separated by commas, in the following format: "<owner_id>_<media_id>", '' — Type of media attachment: 'photo' — photo, 'video' — video, 'audio' — audio, 'doc' — document, 'wall' — wall post, '<owner_id>' — ID of the media attachment owner. '<media_id>' — media attachment ID. Example: "photo100172_166443618"
Attachment []string `url:"attachment,omitempty"`
// '1' — to keep forwarded, messages.
KeepForwardMessages bool `url:"keep_forward_messages,omitempty"`
// '1' — to keep attached snippets.
KeepSnippets bool `url:"keep_snippets,omitempty"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesEditParams) Validate() error {
if param.Lat < -90.000000 {
return fmt.Errorf("parameter Lat(=%v) must be greater or equal than -90.000000", param.Lat)
}
if param.Lat > 90.000000 {
return fmt.Errorf("parameter Lat(=%v) must be less or equal than 90.000000", param.Lat)
}
if param.Long < -180.000000 {
return fmt.Errorf("parameter Long(=%v) must be greater or equal than -180.000000", param.Long)
}
if param.Long > 180.000000 {
return fmt.Errorf("parameter Long(=%v) must be less or equal than 180.000000", param.Long)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesEdit calls VK API method messages.edit. Edits the message.
//
// https://vk.com/dev/messages.edit
func (vkBot *VkBot) MessagesEdit(params *MessagesEditParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.edit", vals)
}
// MessagesDeleteParams params for messages.delete method
//
// https://vk.com/dev/messages.delete
type MessagesDeleteParams struct {
// Message IDs.
MessageIds []int64 `url:"message_ids,omitempty"`
// '1' — to mark message as spam.
Spam bool `url:"spam,omitempty"`
// '1' — delete message for for all.
DeleteForAll bool `url:"delete_for_all,omitempty"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesDeleteParams) Validate() error {
for i, item := range param.MessageIds {
if item < 0.000000 {
return fmt.Errorf("item[#%d](=%v) of parameter MessageIds must be greater or equal than 0.000000", i, item)
}
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesDelete calls VK API method messages.delete. Deletes one or more messages.
//
// https://vk.com/dev/messages.delete
func (vkBot *VkBot) MessagesDelete(params *MessagesDeleteParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.delete", vals)
}
// MessagesDeleteConversationParams params for messages.deleteConversation method
//
// https://vk.com/dev/messages.deleteConversation
type MessagesDeleteConversationParams struct {
// User ID. To clear a chat history use 'chat_id'
UserID string `url:"user_id,omitempty"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
// Destination ID. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerID int64 `url:"peer_id,omitempty"`
// Offset needed to delete a specific subset of conversations.
Offset int64 `url:"offset,omitempty"`
// Number of conversations to delete. "NOTE: If the number of messages exceeds the maximum, the method shall be called several times."
Count int64 `url:"count,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesDeleteConversationParams) Validate() error {
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
if param.Offset < 0.000000 {
return fmt.Errorf("parameter Offset(=%v) must be greater or equal than 0.000000", param.Offset)
}
if param.Count < 0.000000 {
return fmt.Errorf("parameter Count(=%v) must be greater or equal than 0.000000", param.Count)
}
if param.Count > 10000.000000 {
return fmt.Errorf("parameter Count(=%v) must be less or equal than 10000.000000", param.Count)
}
return nil
}
// MessagesDeleteConversation calls VK API method messages.deleteConversation. Deletes all private messages in a conversation.
//
// https://vk.com/dev/messages.deleteConversation
func (vkBot *VkBot) MessagesDeleteConversation(params *MessagesDeleteConversationParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.deleteConversation", vals)
}
// MessagesRestoreParams params for messages.restore method
//
// https://vk.com/dev/messages.restore
type MessagesRestoreParams struct {
// ID of a previously-deleted message to restore.
MessageID int64 `url:"message_id"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesRestoreParams) Validate() error {
if param.MessageID < 0.000000 {
return fmt.Errorf("parameter MessageID(=%v) must be greater or equal than 0.000000", param.MessageID)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesRestore calls VK API method messages.restore. Restores a deleted message.
//
// https://vk.com/dev/messages.restore
func (vkBot *VkBot) MessagesRestore(params *MessagesRestoreParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.restore", vals)
}
// MessagesMarkAsReadParams params for messages.markAsRead method
//
// https://vk.com/dev/messages.markAsRead
type MessagesMarkAsReadParams struct {
// IDs of messages to mark as read.
MessageIds []int64 `url:"message_ids,omitempty"`
// Destination ID. "For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'. For community: '- community ID', e.g. '-12345'. "
PeerID int64 `url:"peer_id,omitempty"`
// Message ID to start from.
StartMessageID int64 `url:"start_message_id,omitempty"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesMarkAsReadParams) Validate() error {
for i, item := range param.MessageIds {
if item < 0.000000 {
return fmt.Errorf("item[#%d](=%v) of parameter MessageIds must be greater or equal than 0.000000", i, item)
}
}
if param.StartMessageID < 0.000000 {
return fmt.Errorf("parameter StartMessageID(=%v) must be greater or equal than 0.000000", param.StartMessageID)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesMarkAsRead calls VK API method messages.markAsRead. Marks messages as read.
//
// https://vk.com/dev/messages.markAsRead
func (vkBot *VkBot) MessagesMarkAsRead(params *MessagesMarkAsReadParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.markAsRead", vals)
}
// MessagesMarkAsImportantParams params for messages.markAsImportant method
//
// https://vk.com/dev/messages.markAsImportant
type MessagesMarkAsImportantParams struct {
// IDs of messages to mark as important.
MessageIds []int64 `url:"message_ids,omitempty"`
// '1' — to add a star (mark as important), '0' — to remove the star
Important bool `url:"important,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesMarkAsImportantParams) Validate() error {
for i, item := range param.MessageIds {
if item < 0.000000 {
return fmt.Errorf("item[#%d](=%v) of parameter MessageIds must be greater or equal than 0.000000", i, item)
}
}
return nil
}
// MessagesMarkAsImportant calls VK API method messages.markAsImportant. Marks and unmarks messages as important (starred).
//
// https://vk.com/dev/messages.markAsImportant
func (vkBot *VkBot) MessagesMarkAsImportant(params *MessagesMarkAsImportantParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.markAsImportant", vals)
}
// MessagesMarkAsImportantConversationParams params for messages.markAsImportantConversation method
//
// https://vk.com/dev/messages.markAsImportantConversation
type MessagesMarkAsImportantConversationParams struct {
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
// ID of conversation to mark as important.
PeerID int64 `url:"peer_id"`
// '1' — to add a star (mark as important), '0' — to remove the star
Important bool `url:"important,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesMarkAsImportantConversationParams) Validate() error {
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesMarkAsImportantConversation calls VK API method messages.markAsImportantConversation. Marks and unmarks conversations as important.
//
// https://vk.com/dev/messages.markAsImportantConversation
func (vkBot *VkBot) MessagesMarkAsImportantConversation(params *MessagesMarkAsImportantConversationParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.markAsImportantConversation", vals)
}
// MessagesMarkAsAnsweredConversationParams params for messages.markAsAnsweredConversation method
//
// https://vk.com/dev/messages.markAsAnsweredConversation
type MessagesMarkAsAnsweredConversationParams struct {
// Group ID (for group messages with group access token)
GroupID int64 `url:"group_id,omitempty"`
// ID of conversation to mark as important.
PeerID int64 `url:"peer_id"`
// '1' — to mark as answered, '0' — to remove the mark
Answered bool `url:"answered,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesMarkAsAnsweredConversationParams) Validate() error {
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesMarkAsAnsweredConversation calls VK API method messages.markAsAnsweredConversation. Marks and unmarks conversations as unanswered.
//
// https://vk.com/dev/messages.markAsAnsweredConversation
func (vkBot *VkBot) MessagesMarkAsAnsweredConversation(params *MessagesMarkAsAnsweredConversationParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.markAsAnsweredConversation", vals)
}
// MessagesGetLongPollServerParams params for messages.getLongPollServer method
//
// https://vk.com/dev/messages.getLongPollServer
type MessagesGetLongPollServerParams struct {
// Long poll version
LpVersion int64 `url:"lp_version,omitempty"`
// '1' — to return the 'pts' field, needed for the [vk.com/dev/messages.getLongPollHistory|messages.getLongPollHistory] method.
NeedPts bool `url:"need_pts,omitempty"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetLongPollServerParams) Validate() error {
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}
// MessagesGetLongPollServer calls VK API method messages.getLongPollServer. Returns data required for connection to a Long Poll server.
//
// https://vk.com/dev/messages.getLongPollServer
func (vkBot *VkBot) MessagesGetLongPollServer(params *MessagesGetLongPollServerParams) (*VkResponse, error) {
err := params.Validate()
if err != nil {
return nil, err
}
vals, err := query.Values(params)
if err != nil {
return nil, err
}
return vkBot.Request("messages.getLongPollServer", vals)
}
// MessagesGetLongPollHistoryParams params for messages.getLongPollHistory method
//
// https://vk.com/dev/messages.getLongPollHistory
type MessagesGetLongPollHistoryParams struct {
// Last value of the 'ts' parameter returned from the Long Poll server or by using [vk.com/dev/messages.getLongPollHistory|messages.getLongPollHistory] method.
Ts int64 `url:"ts,omitempty"`
// Lsat value of 'pts' parameter returned from the Long Poll server or by using [vk.com/dev/messages.getLongPollHistory|messages.getLongPollHistory] method.
Pts int64 `url:"pts,omitempty"`
// Number of characters after which to truncate a previewed message. To preview the full message, specify '0'. "NOTE: Messages are not truncated by default. Messages are truncated by words."
PreviewLength int64 `url:"preview_length,omitempty"`
// '1' — to return history with online users only.
Onlines bool `url:"onlines,omitempty"`
// Additional profile [vk.com/dev/fields|fields] to return.
Fields []string `url:"fields,omitempty"`
// Maximum number of events to return.
EventsLimit int64 `url:"events_limit,omitempty"`
// Maximum number of messages to return.
MsgsLimit int64 `url:"msgs_limit,omitempty"`
// Maximum ID of the message among existing ones in the local copy. Both messages received with API methods (for example, , ), and data received from a Long Poll server (events with code 4) are taken into account.
MaxMsgID int64 `url:"max_msg_id,omitempty"`
// Group ID (for group messages with user access token)
GroupID int64 `url:"group_id,omitempty"`
}
// Validate is called before sending a request to VK API to validate parameters.
func (param *MessagesGetLongPollHistoryParams) Validate() error {
if param.Ts < 0.000000 {
return fmt.Errorf("parameter Ts(=%v) must be greater or equal than 0.000000", param.Ts)
}
if param.Pts < 0.000000 {
return fmt.Errorf("parameter Pts(=%v) must be greater or equal than 0.000000", param.Pts)
}
if param.PreviewLength < 0.000000 {
return fmt.Errorf("parameter PreviewLength(=%v) must be greater or equal than 0.000000", param.PreviewLength)
}
if param.EventsLimit < 1000.000000 {
return fmt.Errorf("parameter EventsLimit(=%v) must be greater or equal than 1000.000000", param.EventsLimit)
}
if param.MsgsLimit < 200.000000 {
return fmt.Errorf("parameter MsgsLimit(=%v) must be greater or equal than 200.000000", param.MsgsLimit)
}
if param.MaxMsgID < 0.000000 {
return fmt.Errorf("parameter MaxMsgID(=%v) must be greater or equal than 0.000000", param.MaxMsgID)
}
if param.GroupID < 0.000000 {
return fmt.Errorf("parameter GroupID(=%v) must be greater or equal than 0.000000", param.GroupID)
}
return nil
}