forked from PaulSonOfLars/gotgbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_methods.go
executable file
·4912 lines (4338 loc) · 203 KB
/
gen_methods.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
// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// Regen by running 'go generate' in the repo root.
package gotgbot
import (
"bytes"
"encoding/json"
"fmt"
"io"
"strconv"
)
// AddStickerToSetOpts is the set of optional fields for Bot.AddStickerToSet.
type AddStickerToSetOpts struct {
// PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files
PngSticker InputFile
// TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#animated-sticker-requirements for technical requirements
TgsSticker InputFile
// WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
WebmSticker InputFile
// A JSON-serialized object for position where the mask should be placed on faces
MaskPosition MaskPosition
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// AddStickerToSet Use this method to add a new sticker to a set created by the bot. You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns True on success.
// - userId (type int64): User identifier of sticker set owner
// - name (type string): Sticker set name
// - emojis (type string): One or more emoji corresponding to the sticker
// - opts (type AddStickerToSetOpts): All optional parameters.
// https://core.telegram.org/bots/api#addstickertoset
func (bot *Bot) AddStickerToSet(userId int64, name string, emojis string, opts *AddStickerToSetOpts) (bool, error) {
v := map[string]string{}
data := map[string]NamedReader{}
v["user_id"] = strconv.FormatInt(userId, 10)
v["name"] = name
v["emojis"] = emojis
if opts != nil {
if opts.PngSticker != nil {
switch m := opts.PngSticker.(type) {
case string:
v["png_sticker"] = m
case NamedReader:
v["png_sticker"] = "attach://png_sticker"
data["png_sticker"] = m
case io.Reader:
v["png_sticker"] = "attach://png_sticker"
data["png_sticker"] = NamedFile{File: m}
case []byte:
v["png_sticker"] = "attach://png_sticker"
data["png_sticker"] = NamedFile{File: bytes.NewReader(m)}
default:
return false, fmt.Errorf("unknown type for InputFile: %T", opts.PngSticker)
}
}
if opts.TgsSticker != nil {
switch m := opts.TgsSticker.(type) {
case NamedReader:
v["tgs_sticker"] = "attach://tgs_sticker"
data["tgs_sticker"] = m
case io.Reader:
v["tgs_sticker"] = "attach://tgs_sticker"
data["tgs_sticker"] = NamedFile{File: m}
case []byte:
v["tgs_sticker"] = "attach://tgs_sticker"
data["tgs_sticker"] = NamedFile{File: bytes.NewReader(m)}
default:
return false, fmt.Errorf("unknown type for InputFile: %T", opts.TgsSticker)
}
}
if opts.WebmSticker != nil {
switch m := opts.WebmSticker.(type) {
case NamedReader:
v["webm_sticker"] = "attach://webm_sticker"
data["webm_sticker"] = m
case io.Reader:
v["webm_sticker"] = "attach://webm_sticker"
data["webm_sticker"] = NamedFile{File: m}
case []byte:
v["webm_sticker"] = "attach://webm_sticker"
data["webm_sticker"] = NamedFile{File: bytes.NewReader(m)}
default:
return false, fmt.Errorf("unknown type for InputFile: %T", opts.WebmSticker)
}
}
bs, err := json.Marshal(opts.MaskPosition)
if err != nil {
return false, fmt.Errorf("failed to marshal field mask_position: %w", err)
}
v["mask_position"] = string(bs)
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("addStickerToSet", v, data, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// AnswerCallbackQueryOpts is the set of optional fields for Bot.AnswerCallbackQuery.
type AnswerCallbackQueryOpts struct {
// Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
Text string
// If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
ShowAlert bool
// URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from a callback_game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
Url string
// The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
CacheTime int64
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// AnswerCallbackQuery Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.
// - callbackQueryId (type string): Unique identifier for the query to be answered
// - opts (type AnswerCallbackQueryOpts): All optional parameters.
// https://core.telegram.org/bots/api#answercallbackquery
func (bot *Bot) AnswerCallbackQuery(callbackQueryId string, opts *AnswerCallbackQueryOpts) (bool, error) {
v := map[string]string{}
v["callback_query_id"] = callbackQueryId
if opts != nil {
v["text"] = opts.Text
v["show_alert"] = strconv.FormatBool(opts.ShowAlert)
v["url"] = opts.Url
if opts.CacheTime != 0 {
v["cache_time"] = strconv.FormatInt(opts.CacheTime, 10)
}
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("answerCallbackQuery", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// AnswerInlineQueryOpts is the set of optional fields for Bot.AnswerInlineQuery.
type AnswerInlineQueryOpts struct {
// The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
CacheTime int64
// Pass True if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
IsPersonal bool
// Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
NextOffset string
// If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
SwitchPmText string
// Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed. Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities.
SwitchPmParameter string
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// AnswerInlineQuery Use this method to send answers to an inline query. On success, True is returned.
// No more than 50 results per query are allowed.
// - inlineQueryId (type string): Unique identifier for the answered query
// - results (type []InlineQueryResult): A JSON-serialized array of results for the inline query
// - opts (type AnswerInlineQueryOpts): All optional parameters.
// https://core.telegram.org/bots/api#answerinlinequery
func (bot *Bot) AnswerInlineQuery(inlineQueryId string, results []InlineQueryResult, opts *AnswerInlineQueryOpts) (bool, error) {
v := map[string]string{}
v["inline_query_id"] = inlineQueryId
if results != nil {
bs, err := json.Marshal(results)
if err != nil {
return false, fmt.Errorf("failed to marshal field results: %w", err)
}
v["results"] = string(bs)
}
if opts != nil {
if opts.CacheTime != 0 {
v["cache_time"] = strconv.FormatInt(opts.CacheTime, 10)
}
v["is_personal"] = strconv.FormatBool(opts.IsPersonal)
v["next_offset"] = opts.NextOffset
v["switch_pm_text"] = opts.SwitchPmText
v["switch_pm_parameter"] = opts.SwitchPmParameter
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("answerInlineQuery", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// AnswerPreCheckoutQueryOpts is the set of optional fields for Bot.AnswerPreCheckoutQuery.
type AnswerPreCheckoutQueryOpts struct {
// Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
ErrorMessage string
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// AnswerPreCheckoutQuery Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
// - preCheckoutQueryId (type string): Unique identifier for the query to be answered
// - ok (type bool): Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
// - opts (type AnswerPreCheckoutQueryOpts): All optional parameters.
// https://core.telegram.org/bots/api#answerprecheckoutquery
func (bot *Bot) AnswerPreCheckoutQuery(preCheckoutQueryId string, ok bool, opts *AnswerPreCheckoutQueryOpts) (bool, error) {
v := map[string]string{}
v["pre_checkout_query_id"] = preCheckoutQueryId
v["ok"] = strconv.FormatBool(ok)
if opts != nil {
v["error_message"] = opts.ErrorMessage
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("answerPreCheckoutQuery", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// AnswerShippingQueryOpts is the set of optional fields for Bot.AnswerShippingQuery.
type AnswerShippingQueryOpts struct {
// Required if ok is True. A JSON-serialized array of available shipping options.
ShippingOptions []ShippingOption
// Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
ErrorMessage string
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// AnswerShippingQuery If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
// - shippingQueryId (type string): Unique identifier for the query to be answered
// - ok (type bool): Pass True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
// - opts (type AnswerShippingQueryOpts): All optional parameters.
// https://core.telegram.org/bots/api#answershippingquery
func (bot *Bot) AnswerShippingQuery(shippingQueryId string, ok bool, opts *AnswerShippingQueryOpts) (bool, error) {
v := map[string]string{}
v["shipping_query_id"] = shippingQueryId
v["ok"] = strconv.FormatBool(ok)
if opts != nil {
if opts.ShippingOptions != nil {
bs, err := json.Marshal(opts.ShippingOptions)
if err != nil {
return false, fmt.Errorf("failed to marshal field shipping_options: %w", err)
}
v["shipping_options"] = string(bs)
}
v["error_message"] = opts.ErrorMessage
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("answerShippingQuery", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// AnswerWebAppQueryOpts is the set of optional fields for Bot.AnswerWebAppQuery.
type AnswerWebAppQueryOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// AnswerWebAppQuery Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.
// - webAppQueryId (type string): Unique identifier for the query to be answered
// - result (type InlineQueryResult): A JSON-serialized object describing the message to be sent
// https://core.telegram.org/bots/api#answerwebappquery
func (bot *Bot) AnswerWebAppQuery(webAppQueryId string, result InlineQueryResult, opts *AnswerWebAppQueryOpts) (*SentWebAppMessage, error) {
v := map[string]string{}
v["web_app_query_id"] = webAppQueryId
bs, err := json.Marshal(result)
if err != nil {
return nil, fmt.Errorf("failed to marshal field result: %w", err)
}
v["result"] = string(bs)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("answerWebAppQuery", v, nil, reqOpts)
if err != nil {
return nil, err
}
var s SentWebAppMessage
return &s, json.Unmarshal(r, &s)
}
// ApproveChatJoinRequestOpts is the set of optional fields for Bot.ApproveChatJoinRequest.
type ApproveChatJoinRequestOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// ApproveChatJoinRequest Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// - userId (type int64): Unique identifier of the target user
// https://core.telegram.org/bots/api#approvechatjoinrequest
func (bot *Bot) ApproveChatJoinRequest(chatId int64, userId int64, opts *ApproveChatJoinRequestOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["user_id"] = strconv.FormatInt(userId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("approveChatJoinRequest", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// BanChatMemberOpts is the set of optional fields for Bot.BanChatMember.
type BanChatMemberOpts struct {
// Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.
UntilDate int64
// Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.
RevokeMessages bool
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// BanChatMember Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
// - chatId (type int64): Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
// - userId (type int64): Unique identifier of the target user
// - opts (type BanChatMemberOpts): All optional parameters.
// https://core.telegram.org/bots/api#banchatmember
func (bot *Bot) BanChatMember(chatId int64, userId int64, opts *BanChatMemberOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["user_id"] = strconv.FormatInt(userId, 10)
if opts != nil {
if opts.UntilDate != 0 {
v["until_date"] = strconv.FormatInt(opts.UntilDate, 10)
}
v["revoke_messages"] = strconv.FormatBool(opts.RevokeMessages)
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("banChatMember", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// BanChatSenderChatOpts is the set of optional fields for Bot.BanChatSenderChat.
type BanChatSenderChatOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// BanChatSenderChat Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// - senderChatId (type int64): Unique identifier of the target sender chat
// https://core.telegram.org/bots/api#banchatsenderchat
func (bot *Bot) BanChatSenderChat(chatId int64, senderChatId int64, opts *BanChatSenderChatOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["sender_chat_id"] = strconv.FormatInt(senderChatId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("banChatSenderChat", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// CloseOpts is the set of optional fields for Bot.Close.
type CloseOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// Close Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters.
// https://core.telegram.org/bots/api#close
func (bot *Bot) Close(opts *CloseOpts) (bool, error) {
v := map[string]string{}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("close", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// CloseForumTopicOpts is the set of optional fields for Bot.CloseForumTopic.
type CloseForumTopicOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// CloseForumTopic Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
// - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic
// https://core.telegram.org/bots/api#closeforumtopic
func (bot *Bot) CloseForumTopic(chatId int64, messageThreadId int64, opts *CloseForumTopicOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("closeForumTopic", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// CopyMessageOpts is the set of optional fields for Bot.CopyMessage.
type CopyMessageOpts struct {
// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
MessageThreadId int64
// New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
Caption string
// Mode for parsing entities in the new caption. See formatting options for more details.
ParseMode string
// A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parse_mode
CaptionEntities []MessageEntity
// Sends the message silently. Users will receive a notification with no sound.
DisableNotification bool
// Protects the contents of the sent message from forwarding and saving
ProtectContent bool
// If the message is a reply, ID of the original message
ReplyToMessageId int64
// Pass True if the message should be sent even if the specified replied-to message is not found
AllowSendingWithoutReply bool
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
ReplyMarkup ReplyMarkup
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// CopyMessage Use this method to copy messages of any kind. Service messages and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// - fromChatId (type int64): Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
// - messageId (type int64): Message identifier in the chat specified in from_chat_id
// - opts (type CopyMessageOpts): All optional parameters.
// https://core.telegram.org/bots/api#copymessage
func (bot *Bot) CopyMessage(chatId int64, fromChatId int64, messageId int64, opts *CopyMessageOpts) (*MessageId, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["from_chat_id"] = strconv.FormatInt(fromChatId, 10)
v["message_id"] = strconv.FormatInt(messageId, 10)
if opts != nil {
if opts.MessageThreadId != 0 {
v["message_thread_id"] = strconv.FormatInt(opts.MessageThreadId, 10)
}
v["caption"] = opts.Caption
v["parse_mode"] = opts.ParseMode
if opts.CaptionEntities != nil {
bs, err := json.Marshal(opts.CaptionEntities)
if err != nil {
return nil, fmt.Errorf("failed to marshal field caption_entities: %w", err)
}
v["caption_entities"] = string(bs)
}
v["disable_notification"] = strconv.FormatBool(opts.DisableNotification)
v["protect_content"] = strconv.FormatBool(opts.ProtectContent)
if opts.ReplyToMessageId != 0 {
v["reply_to_message_id"] = strconv.FormatInt(opts.ReplyToMessageId, 10)
}
v["allow_sending_without_reply"] = strconv.FormatBool(opts.AllowSendingWithoutReply)
if opts.ReplyMarkup != nil {
bs, err := json.Marshal(opts.ReplyMarkup)
if err != nil {
return nil, fmt.Errorf("failed to marshal field reply_markup: %w", err)
}
v["reply_markup"] = string(bs)
}
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("copyMessage", v, nil, reqOpts)
if err != nil {
return nil, err
}
var m MessageId
return &m, json.Unmarshal(r, &m)
}
// CreateChatInviteLinkOpts is the set of optional fields for Bot.CreateChatInviteLink.
type CreateChatInviteLinkOpts struct {
// Invite link name; 0-32 characters
Name string
// Point in time (Unix timestamp) when the link will expire
ExpireDate int64
// The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
MemberLimit int64
// True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified
CreatesJoinRequest bool
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// CreateChatInviteLink Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// - opts (type CreateChatInviteLinkOpts): All optional parameters.
// https://core.telegram.org/bots/api#createchatinvitelink
func (bot *Bot) CreateChatInviteLink(chatId int64, opts *CreateChatInviteLinkOpts) (*ChatInviteLink, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
if opts != nil {
v["name"] = opts.Name
if opts.ExpireDate != 0 {
v["expire_date"] = strconv.FormatInt(opts.ExpireDate, 10)
}
if opts.MemberLimit != 0 {
v["member_limit"] = strconv.FormatInt(opts.MemberLimit, 10)
}
v["creates_join_request"] = strconv.FormatBool(opts.CreatesJoinRequest)
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("createChatInviteLink", v, nil, reqOpts)
if err != nil {
return nil, err
}
var c ChatInviteLink
return &c, json.Unmarshal(r, &c)
}
// CreateForumTopicOpts is the set of optional fields for Bot.CreateForumTopic.
type CreateForumTopicOpts struct {
// Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)
IconColor int64
// Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
IconCustomEmojiId string
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// CreateForumTopic Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.
// - chatId (type int64): Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
// - name (type string): Topic name, 1-128 characters
// - opts (type CreateForumTopicOpts): All optional parameters.
// https://core.telegram.org/bots/api#createforumtopic
func (bot *Bot) CreateForumTopic(chatId int64, name string, opts *CreateForumTopicOpts) (*ForumTopic, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["name"] = name
if opts != nil {
if opts.IconColor != 0 {
v["icon_color"] = strconv.FormatInt(opts.IconColor, 10)
}
v["icon_custom_emoji_id"] = opts.IconCustomEmojiId
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("createForumTopic", v, nil, reqOpts)
if err != nil {
return nil, err
}
var f ForumTopic
return &f, json.Unmarshal(r, &f)
}
// CreateInvoiceLinkOpts is the set of optional fields for Bot.CreateInvoiceLink.
type CreateInvoiceLinkOpts struct {
// The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0
MaxTipAmount int64
// A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
SuggestedTipAmounts []int64
// JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
ProviderData string
// URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
PhotoUrl string
// Photo size in bytes
PhotoSize int64
// Photo width
PhotoWidth int64
// Photo height
PhotoHeight int64
// Pass True if you require the user's full name to complete the order
NeedName bool
// Pass True if you require the user's phone number to complete the order
NeedPhoneNumber bool
// Pass True if you require the user's email address to complete the order
NeedEmail bool
// Pass True if you require the user's shipping address to complete the order
NeedShippingAddress bool
// Pass True if the user's phone number should be sent to the provider
SendPhoneNumberToProvider bool
// Pass True if the user's email address should be sent to the provider
SendEmailToProvider bool
// Pass True if the final price depends on the shipping method
IsFlexible bool
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// CreateInvoiceLink Use this method to create a link for an invoice. Returns the created invoice link as String on success.
// - title (type string): Product name, 1-32 characters
// - description (type string): Product description, 1-255 characters
// - payload (type string): Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
// - providerToken (type string): Payment provider token, obtained via BotFather
// - currency (type string): Three-letter ISO 4217 currency code, see more on currencies
// - prices (type []LabeledPrice): Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
// - opts (type CreateInvoiceLinkOpts): All optional parameters.
// https://core.telegram.org/bots/api#createinvoicelink
func (bot *Bot) CreateInvoiceLink(title string, description string, payload string, providerToken string, currency string, prices []LabeledPrice, opts *CreateInvoiceLinkOpts) (string, error) {
v := map[string]string{}
v["title"] = title
v["description"] = description
v["payload"] = payload
v["provider_token"] = providerToken
v["currency"] = currency
if prices != nil {
bs, err := json.Marshal(prices)
if err != nil {
return "", fmt.Errorf("failed to marshal field prices: %w", err)
}
v["prices"] = string(bs)
}
if opts != nil {
if opts.MaxTipAmount != 0 {
v["max_tip_amount"] = strconv.FormatInt(opts.MaxTipAmount, 10)
}
if opts.SuggestedTipAmounts != nil {
bs, err := json.Marshal(opts.SuggestedTipAmounts)
if err != nil {
return "", fmt.Errorf("failed to marshal field suggested_tip_amounts: %w", err)
}
v["suggested_tip_amounts"] = string(bs)
}
v["provider_data"] = opts.ProviderData
v["photo_url"] = opts.PhotoUrl
if opts.PhotoSize != 0 {
v["photo_size"] = strconv.FormatInt(opts.PhotoSize, 10)
}
if opts.PhotoWidth != 0 {
v["photo_width"] = strconv.FormatInt(opts.PhotoWidth, 10)
}
if opts.PhotoHeight != 0 {
v["photo_height"] = strconv.FormatInt(opts.PhotoHeight, 10)
}
v["need_name"] = strconv.FormatBool(opts.NeedName)
v["need_phone_number"] = strconv.FormatBool(opts.NeedPhoneNumber)
v["need_email"] = strconv.FormatBool(opts.NeedEmail)
v["need_shipping_address"] = strconv.FormatBool(opts.NeedShippingAddress)
v["send_phone_number_to_provider"] = strconv.FormatBool(opts.SendPhoneNumberToProvider)
v["send_email_to_provider"] = strconv.FormatBool(opts.SendEmailToProvider)
v["is_flexible"] = strconv.FormatBool(opts.IsFlexible)
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("createInvoiceLink", v, nil, reqOpts)
if err != nil {
return "", err
}
var s string
return s, json.Unmarshal(r, &s)
}
// CreateNewStickerSetOpts is the set of optional fields for Bot.CreateNewStickerSet.
type CreateNewStickerSetOpts struct {
// PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files: https://core.telegram.org/bots/api#sending-files
PngSticker InputFile
// TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#animated-sticker-requirements for technical requirements
TgsSticker InputFile
// WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
WebmSticker InputFile
// Type of stickers in the set, pass "regular" or "mask". Custom emoji sticker sets can't be created via the Bot API at the moment. By default, a regular sticker set is created.
StickerType string
// A JSON-serialized object for position where the mask should be placed on faces
MaskPosition MaskPosition
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// CreateNewStickerSet Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. Returns True on success.
// - userId (type int64): User identifier of created sticker set owner
// - name (type string): Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only English letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in "_by_<bot_username>". <bot_username> is case insensitive. 1-64 characters.
// - title (type string): Sticker set title, 1-64 characters
// - emojis (type string): One or more emoji corresponding to the sticker
// - opts (type CreateNewStickerSetOpts): All optional parameters.
// https://core.telegram.org/bots/api#createnewstickerset
func (bot *Bot) CreateNewStickerSet(userId int64, name string, title string, emojis string, opts *CreateNewStickerSetOpts) (bool, error) {
v := map[string]string{}
data := map[string]NamedReader{}
v["user_id"] = strconv.FormatInt(userId, 10)
v["name"] = name
v["title"] = title
v["emojis"] = emojis
if opts != nil {
if opts.PngSticker != nil {
switch m := opts.PngSticker.(type) {
case string:
v["png_sticker"] = m
case NamedReader:
v["png_sticker"] = "attach://png_sticker"
data["png_sticker"] = m
case io.Reader:
v["png_sticker"] = "attach://png_sticker"
data["png_sticker"] = NamedFile{File: m}
case []byte:
v["png_sticker"] = "attach://png_sticker"
data["png_sticker"] = NamedFile{File: bytes.NewReader(m)}
default:
return false, fmt.Errorf("unknown type for InputFile: %T", opts.PngSticker)
}
}
if opts.TgsSticker != nil {
switch m := opts.TgsSticker.(type) {
case NamedReader:
v["tgs_sticker"] = "attach://tgs_sticker"
data["tgs_sticker"] = m
case io.Reader:
v["tgs_sticker"] = "attach://tgs_sticker"
data["tgs_sticker"] = NamedFile{File: m}
case []byte:
v["tgs_sticker"] = "attach://tgs_sticker"
data["tgs_sticker"] = NamedFile{File: bytes.NewReader(m)}
default:
return false, fmt.Errorf("unknown type for InputFile: %T", opts.TgsSticker)
}
}
if opts.WebmSticker != nil {
switch m := opts.WebmSticker.(type) {
case NamedReader:
v["webm_sticker"] = "attach://webm_sticker"
data["webm_sticker"] = m
case io.Reader:
v["webm_sticker"] = "attach://webm_sticker"
data["webm_sticker"] = NamedFile{File: m}
case []byte:
v["webm_sticker"] = "attach://webm_sticker"
data["webm_sticker"] = NamedFile{File: bytes.NewReader(m)}
default:
return false, fmt.Errorf("unknown type for InputFile: %T", opts.WebmSticker)
}
}
v["sticker_type"] = opts.StickerType
bs, err := json.Marshal(opts.MaskPosition)
if err != nil {
return false, fmt.Errorf("failed to marshal field mask_position: %w", err)
}
v["mask_position"] = string(bs)
}
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("createNewStickerSet", v, data, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// DeclineChatJoinRequestOpts is the set of optional fields for Bot.DeclineChatJoinRequest.
type DeclineChatJoinRequestOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// DeclineChatJoinRequest Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// - userId (type int64): Unique identifier of the target user
// https://core.telegram.org/bots/api#declinechatjoinrequest
func (bot *Bot) DeclineChatJoinRequest(chatId int64, userId int64, opts *DeclineChatJoinRequestOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["user_id"] = strconv.FormatInt(userId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("declineChatJoinRequest", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// DeleteChatPhotoOpts is the set of optional fields for Bot.DeleteChatPhoto.
type DeleteChatPhotoOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// DeleteChatPhoto Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// https://core.telegram.org/bots/api#deletechatphoto
func (bot *Bot) DeleteChatPhoto(chatId int64, opts *DeleteChatPhotoOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("deleteChatPhoto", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// DeleteChatStickerSetOpts is the set of optional fields for Bot.DeleteChatStickerSet.
type DeleteChatStickerSetOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// DeleteChatStickerSet Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
// https://core.telegram.org/bots/api#deletechatstickerset
func (bot *Bot) DeleteChatStickerSet(chatId int64, opts *DeleteChatStickerSetOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("deleteChatStickerSet", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// DeleteForumTopicOpts is the set of optional fields for Bot.DeleteForumTopic.
type DeleteForumTopicOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// DeleteForumTopic Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
// - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic
// https://core.telegram.org/bots/api#deleteforumtopic
func (bot *Bot) DeleteForumTopic(chatId int64, messageThreadId int64, opts *DeleteForumTopicOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["message_thread_id"] = strconv.FormatInt(messageThreadId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("deleteForumTopic", v, nil, reqOpts)
if err != nil {
return false, err
}
var b bool
return b, json.Unmarshal(r, &b)
}
// DeleteMessageOpts is the set of optional fields for Bot.DeleteMessage.
type DeleteMessageOpts struct {
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}
// DeleteMessage Use this method to delete a message, including service messages, with the following limitations:
// - A message can only be deleted if it was sent less than 48 hours ago.
// - Service messages about a supergroup, channel, or forum topic creation can't be deleted.
// - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
// - Bots can delete outgoing messages in private chats, groups, and supergroups.
// - Bots can delete incoming messages in private chats.
// - Bots granted can_post_messages permissions can delete outgoing messages in channels.
// - If the bot is an administrator of a group, it can delete any message there.
// - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
// Returns True on success.
// - chatId (type int64): Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// - messageId (type int64): Identifier of the message to delete
// https://core.telegram.org/bots/api#deletemessage
func (bot *Bot) DeleteMessage(chatId int64, messageId int64, opts *DeleteMessageOpts) (bool, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["message_id"] = strconv.FormatInt(messageId, 10)
var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}
r, err := bot.Request("deleteMessage", v, nil, reqOpts)
if err != nil {