-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmethods.go
2831 lines (2432 loc) · 72.2 KB
/
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
package telegrambot
// https://core.telegram.org/bots/api#available-methods
import (
"bytes"
"encoding/json"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)
// GetUpdates retrieves updates from Telegram bot API.
//
// https://core.telegram.org/bots/api#getupdates
func (b *Bot) GetUpdates(
options OptionsGetUpdates,
) (result APIResponse[[]Update]) {
if options == nil {
options = map[string]any{}
}
return requestGeneric[[]Update](b, "getUpdates", options)
}
// SetWebhook sets various options for receiving incoming updates.
//
// `port` should be one of: 443, 80, 88, or 8443.
//
// https://core.telegram.org/bots/api#setwebhook
func (b *Bot) SetWebhook(
host string,
port int,
options OptionsSetWebhook,
) (result APIResponse[bool]) {
b.webhookHost = host
b.webhookPort = port
b.webhookURL = b.getWebhookURL()
params := map[string]any{
"url": b.webhookURL,
}
if cert, exists := options["certificate"]; exists {
var errStr string
if filepath, ok := cert.(string); ok {
if file, err := os.Open(filepath); err == nil {
params["certificate"] = file
} else {
errStr = fmt.Sprintf("failed to open certificate: %s", err)
}
} else {
errStr = "given filepath of certificate is not a string"
}
if errStr != "" {
return APIResponse[bool]{
Ok: false,
Description: &errStr,
Error: strToErr(errStr),
}
}
}
if ipAddress, exists := options["ip_address"]; exists {
params["ip_address"] = ipAddress
}
if maxConnections, exists := options["max_connections"]; exists {
params["max_connections"] = maxConnections
}
if allowedUpdates, exists := options["allowed_updates"]; exists {
params["allowed_updates"] = allowedUpdates
}
if dropPendingUpdates, exists := options["drop_pending_updates"]; exists {
params["drop_pending_updates"] = dropPendingUpdates
}
b.verbose("setting webhook url to: %s", b.webhookURL)
return requestGeneric[bool](b, "setWebhook", params)
}
// DeleteWebhook deletes webhook for this bot.
// (Function GetUpdates will not work if webhook is set, so in that case you'll need to delete it)
//
// https://core.telegram.org/bots/api#deletewebhook
func (b *Bot) DeleteWebhook(
dropPendingUpdates bool,
) (result APIResponse[bool]) {
b.webhookHost = ""
b.webhookPort = 0
b.webhookURL = ""
b.verbose("deleting webhook url")
return requestGeneric[bool](b, "deleteWebhook", map[string]any{
"drop_pending_updates": dropPendingUpdates,
})
}
// GetWebhookInfo gets webhook info for this bot.
//
// https://core.telegram.org/bots/api#getwebhookinfo
func (b *Bot) GetWebhookInfo() (result APIResponse[WebhookInfo]) {
return requestGeneric[WebhookInfo](b, "getWebhookInfo", map[string]any{})
}
// GetMe gets info of this bot.
//
// https://core.telegram.org/bots/api#getme
func (b *Bot) GetMe() (result APIResponse[User]) {
return requestGeneric[User](b, "getMe", map[string]any{}) // no params
}
// LogOut logs this bot from cloud Bot API server.
//
// https://core.telegram.org/bots/api#logout
func (b *Bot) LogOut() (result APIResponse[bool]) {
return requestGeneric[bool](b, "logOut", map[string]any{}) // no params
}
// Close closes this bot from local Bot API server.
//
// https://core.telegram.org/bots/api#close
func (b *Bot) Close() (result APIResponse[bool]) {
return requestGeneric[bool](b, "close", map[string]any{}) // no params
}
// SendMessage sends a message to the bot.
//
// https://core.telegram.org/bots/api#sendmessage
func (b *Bot) SendMessage(
chatID ChatID,
text string,
options OptionsSendMessage,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["text"] = text
return requestGeneric[Message](b, "sendMessage", options)
}
// ForwardMessage forwards a message.
//
// https://core.telegram.org/bots/api#forwardmessage
func (b *Bot) ForwardMessage(
chatID, fromChatID ChatID,
messageID int64,
options OptionsForwardMessage,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["from_chat_id"] = fromChatID
options["message_id"] = messageID
return requestGeneric[Message](b, "forwardMessage", options)
}
// ForwardMessages forwards messages.
//
// https://core.telegram.org/bots/api#forwardmessages
func (b *Bot) ForwardMessages(
chatID, fromChatID ChatID,
messageIDs []int64,
options OptionsForwardMessage,
) (result APIResponse[[]MessageID]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["from_chat_id"] = fromChatID
options["message_ids"] = messageIDs
return requestGeneric[[]MessageID](b, "forwardMessages", options)
}
// CopyMessage copies a message.
//
// https://core.telegram.org/bots/api#copymessage
func (b *Bot) CopyMessage(
chatID, fromChatID ChatID,
messageID int64,
options OptionsCopyMessage,
) (result APIResponse[MessageID]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["from_chat_id"] = fromChatID
options["message_id"] = messageID
return requestGeneric[MessageID](b, "copyMessage", options)
}
// CopyMessages copies messages.
//
// https://core.telegram.org/bots/api#copymessages
func (b *Bot) CopyMessages(
chatID, fromChatID ChatID,
messageIDs []int64,
options OptionsCopyMessages,
) (result APIResponse[[]MessageID]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["from_chat_id"] = fromChatID
options["message_ids"] = messageIDs
return requestGeneric[[]MessageID](b, "copyMessages", options)
}
// SendPhoto sends a photo.
//
// https://core.telegram.org/bots/api#sendphoto
func (b *Bot) SendPhoto(
chatID ChatID,
photo InputFile,
options OptionsSendPhoto,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["photo"] = photo
return requestGeneric[Message](b, "sendPhoto", options)
}
// SendAudio sends an audio file. (.mp3 or .m4a format, will be played with external players)
//
// https://core.telegram.org/bots/api#sendaudio
func (b *Bot) SendAudio(
chatID ChatID,
audio InputFile,
options OptionsSendAudio,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["audio"] = audio
return requestGeneric[Message](b, "sendAudio", options)
}
// SendDocument sends a general file.
//
// https://core.telegram.org/bots/api#senddocument
func (b *Bot) SendDocument(
chatID ChatID,
document InputFile,
options OptionsSendDocument,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["document"] = document
return requestGeneric[Message](b, "sendDocument", options)
}
// SendSticker sends a sticker.
//
// https://core.telegram.org/bots/api#sendsticker
func (b *Bot) SendSticker(
chatID ChatID,
sticker InputFile,
options OptionsSendSticker,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["sticker"] = sticker
return requestGeneric[Message](b, "sendSticker", options)
}
// GetStickerSet gets a sticker set.
//
// https://core.telegram.org/bots/api#getstickerset
func (b *Bot) GetStickerSet(name string) (result APIResponse[StickerSet]) {
// essential params
options := map[string]any{
"name": name,
}
return requestGeneric[StickerSet](b, "getStickerSet", options)
}
// GetCustomEmojiStickers gets custom emoji stickers.
//
// https://core.telegram.org/bots/api#getcustomemojistickers
func (b *Bot) GetCustomEmojiStickers(
customEmojiIDs []string,
) (result APIResponse[[]Sticker]) {
// essential options
options := map[string]any{
"custom_emoji_ids": customEmojiIDs,
}
return requestGeneric[[]Sticker](b, "getCustomEmojiStickers", options)
}
// UploadStickerFile uploads a sticker file.
//
// https://core.telegram.org/bots/api#uploadstickerfile
func (b *Bot) UploadStickerFile(
userID int64,
sticker InputFile,
stickerFormat StickerFormat,
) (result APIResponse[File]) {
// essential options
options := map[string]any{
"user_id": userID,
"sticker": sticker,
"sticker_format": stickerFormat,
}
return requestGeneric[File](b, "uploadStickerFile", options)
}
// CreateNewStickerSet creates a new sticker set.
//
// https://core.telegram.org/bots/api#createnewstickerset
func (b *Bot) CreateNewStickerSet(
userID int64,
name, title string,
stickers []InputSticker,
options OptionsCreateNewStickerSet,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["user_id"] = userID
options["name"] = name
options["title"] = title
options["stickers"] = stickers
return requestGeneric[bool](b, "createNewStickerSet", options)
}
// AddStickerToSet adds a sticker to set.
//
// https://core.telegram.org/bots/api#addstickertoset
func (b *Bot) AddStickerToSet(
userID int64,
name string,
sticker InputSticker,
options OptionsAddStickerToSet,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["user_id"] = userID
options["name"] = name
options["sticker"] = sticker
return requestGeneric[bool](b, "addStickerToSet", options)
}
// SetStickerPositionInSet sets sticker position in set.
//
// https://core.telegram.org/bots/api#setstickerpositioninset
func (b *Bot) SetStickerPositionInSet(
sticker string,
position int,
) (result APIResponse[bool]) {
// essential options
options := map[string]any{
"sticker": sticker,
"position": position,
}
return requestGeneric[bool](b, "setStickerPositionInSet", options)
}
// DeleteStickerFromSet deletes a sticker from set.
//
// https://core.telegram.org/bots/api#deletestickerfromset
func (b *Bot) DeleteStickerFromSet(
sticker string,
) (result APIResponse[bool]) {
// essential options
options := map[string]any{
"sticker": sticker,
}
return requestGeneric[bool](b, "deleteStickerFromSet", options)
}
// SetStickerSetThumbnail sets a thumbnail of a sticker set.
//
// https://core.telegram.org/bots/api#setstickersetthumbnail
func (b *Bot) SetStickerSetThumbnail(
name string,
userID int64,
format StickerFormat,
options OptionsSetStickerSetThumbnail,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["name"] = name
options["user_id"] = userID
options["format"] = format
return requestGeneric[bool](b, "setStickerSetThumbnail", options)
}
// SetCustomEmojiStickerSetThumbnail sets the custom emoji sticker set's thumbnail.
//
// https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
func (b *Bot) SetCustomEmojiStickerSetThumbnail(
name string,
options OptionsSetCustomEmojiStickerSetThumbnail,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["name"] = name
return requestGeneric[bool](b, "setCustomEmojiStickerSetThumbnail", options)
}
// SetStickerSetTitle sets the title of sticker set.
//
// https://core.telegram.org/bots/api#setstickersettitle
func (b *Bot) SetStickerSetTitle(name, title string) (result APIResponse[bool]) {
return requestGeneric[bool](b, "setStickerSetTitle", map[string]any{
"name": name,
"title": title,
})
}
// DeleteStickerSet deletes a sticker set.
//
// https://core.telegram.org/bots/api#deletestickerset
func (b *Bot) DeleteStickerSet(name string) (result APIResponse[bool]) {
return requestGeneric[bool](b, "deleteStickerSet", map[string]any{
"name": name,
})
}
// ReplaceStickerInSet replaces an existing sticker in a sticker set with a new one.
//
// https://core.telegram.org/bots/api#replacestickerinset
func (b *Bot) ReplaceStickerInSet(
userID, name, oldSticker string,
sticker InputSticker,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "replaceStickerInSet", map[string]any{
"user_id": userID,
"name": name,
"old_sticker": oldSticker,
"sticker": sticker,
})
}
// SetStickerEmojiList sets the emoji list of sticker set.
//
// https://core.telegram.org/bots/api#setstickeremojilist
func (b *Bot) SetStickerEmojiList(
sticker string,
emojiList []string,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "setStickerEmojiList", map[string]any{
"sticker": sticker,
"emoji_list": emojiList,
})
}
// SetStickerKeywords sets the keywords of sticker.
//
// https://core.telegram.org/bots/api#setstickerkeywords
func (b *Bot) SetStickerKeywords(
sticker string,
keywords []string,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "setStickerKeywords", map[string]any{
"sticker": sticker,
"keywords": keywords,
})
}
// SetStickerMaskPosition sets mask position of sticker.
//
// https://core.telegram.org/bots/api#setstickermaskposition
func (b *Bot) SetStickerMaskPosition(
sticker string,
options OptionsSetStickerMaskPosition,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["sticker"] = sticker
return requestGeneric[bool](b, "setStickerMaskPosition", options)
}
// GetAvailableGifts returns the list of gifts that can be sent by the bot to users.
//
// https://core.telegram.org/bots/api#getavailablegifts
func (b *Bot) GetAvailableGifts() (result APIResponse[Gifts]) {
return requestGeneric[Gifts](b, "getAvailableGifts", nil)
}
// SendGift sends a gift to the given user.
//
// https://core.telegram.org/bots/api#sendgift
func (b *Bot) SendGift(
giftID string,
options OptionsSendGift,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["gift_id"] = giftID
return requestGeneric[bool](b, "sendGift", options)
}
// GiftPremiumSubscription gifts a Telegram Premium subscription to the given user.
//
// https://core.telegram.org/bots/api#giftpremiumsubscription
func (b *Bot) GiftPremiumSubscription(
userID int64,
monthCount, starCount int,
options OptionsGiftPremiumSubscription,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["user_id"] = userID
options["month_count"] = monthCount
options["star_count"] = starCount
return requestGeneric[bool](b, "giftPremiumSubscription", options)
}
// VerifyUser verifies a user.
//
// https://core.telegram.org/bots/api#verifyuser
func (b *Bot) VerifyUser(
userID int64,
options OptionsVerifyUser,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["user_id"] = userID
return requestGeneric[bool](b, "verifyUser", options)
}
// VerifyChat verifies a chat.
//
// https://core.telegram.org/bots/api#verifychat
func (b *Bot) VerifyChat(
chatID ChatID,
options OptionsVerifyChat,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
return requestGeneric[bool](b, "verifyChat", options)
}
// RemoveUserVerification removes a user's verification.
//
// https://core.telegram.org/bots/api#removeuserverification
func (b *Bot) RemoveUserVerification(userID int64) (result APIResponse[bool]) {
return requestGeneric[bool](b, "removeUserVerification", map[string]any{
"user_id": userID,
})
}
// RemoveChatVerification removes a chat's verification.
//
// https://core.telegram.org/bots/api#removechatverification
func (b *Bot) RemoveChatVerification(chatID ChatID) (result APIResponse[bool]) {
return requestGeneric[bool](b, "removeChatVerification", map[string]any{
"chat_id": chatID,
})
}
// ReadBusinessMessage marks an incoming message as read on behalf of a business account.
//
// https://core.telegram.org/bots/api#readbusinessmessage
func (b *Bot) ReadBusinessMessage(
businessConnectionID string,
chatID, messageID int64,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "readBusinessMessage", map[string]any{
"business_connection_id": businessConnectionID,
"chat_id": chatID,
"message_id": messageID,
})
}
// DeleteBusinessMessages deletes messages on behalf of a business account.
//
// https://core.telegram.org/bots/api#deletebusinessmessages
func (b *Bot) DeleteBusinessMessages(
businessConnectionID string,
messageIDs []int64,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "deleteBusinessMessages", map[string]any{
"business_connection_id": businessConnectionID,
"message_ids": messageIDs,
})
}
// SetBusinessAccountName changes the first and last name of a managed business account.
//
// https://core.telegram.org/bots/api#setbusinessaccountname
func (b *Bot) SetBusinessAccountName(
businessConnectionID string,
firstName string,
options OptionsSetBusinessAccountName,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
options["first_name"] = firstName
return requestGeneric[bool](b, "setBusinessAccountName", options)
}
// SetBusinessAccountUsername changes the username of a managed business account.
//
// https://core.telegram.org/bots/api#setbusinessaccountusername
func (b *Bot) SetBusinessAccountUsername(
businessConnectionID string,
options OptionsSetBusinessAccountUsername,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
return requestGeneric[bool](b, "setBusinessAccountUsername", options)
}
// SetBusinessAccountBio changes the bio of a managed business account.
//
// https://core.telegram.org/bots/api#setbusinessaccountbio
func (b *Bot) SetBusinessAccountBio(
businessConnectionID string,
options OptionsSetBusinessAccountBio,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
return requestGeneric[bool](b, "setBusinessAccountBio", options)
}
// SetBusinessAccountProfilePhoto changes the profile photo of a managed business account.
//
// https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
func (b *Bot) SetBusinessAccountProfilePhoto(
businessConnectionID string,
photo InputProfilePhoto,
options OptionsSetBusinessAccountProfilePhoto,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
options["photo"] = photo
return requestGeneric[bool](b, "setBusinessAccountProfilePhoto", options)
}
// RemoveBusinessAccountProfilePhoto removes the current profile photo of a managed business account.
//
// https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
func (b *Bot) RemoveBusinessAccountProfilePhoto(
businessConnectionID string,
options OptionsRemoveBusinessAccountProfilePhoto,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
return requestGeneric[bool](b, "removeBusinessAccountProfilePhoto", options)
}
// SetBusinessAccountGiftSettings changes the privacy settings pertaining to incoming gifts in a managed business account.
//
// https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
func (b *Bot) SetBusinessAccountGiftSettings(
businessConnectionID string,
showGiftButton bool,
acceptedGiftTypes AcceptedGiftTypes,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "setBusinessAccountGiftSettings", map[string]any{
"business_connection_id": businessConnectionID,
"show_gift_button": showGiftButton,
"accepted_gift_types": acceptedGiftTypes,
})
}
// GetBusinessAccountStarBalance returns the amount of Telegram Stars owned by a managed business account.
//
// https://core.telegram.org/bots/api#getbusinessaccountstarbalance
func (b *Bot) GetBusinessAccountStarBalance(
businessConnectionID string,
) (result APIResponse[StarAmount]) {
return requestGeneric[StarAmount](b, "getBusinessAccountStarBalance", map[string]any{
"business_connection_id": businessConnectionID,
})
}
// TransferBusinessAccountStars transfers Telegram Stars from the business account balance to the bot's balance.
//
// https://core.telegram.org/bots/api#transferbusinessaccountstars
func (b *Bot) TransferBusinessAccountStars(
businessConnectionID string,
starCount int,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "transferBusinessAccountStars", map[string]any{
"business_connection_id": businessConnectionID,
"star_count": starCount,
})
}
// GetBusinessAccountGifts returns the gifts received and owned by a managed business account.
//
// https://core.telegram.org/bots/api#getbusinessaccountgifts
func (b *Bot) GetBusinessAccountGifts(
businessConnectionID string,
options OptionsGetBusinessAccountGifts,
) (result APIResponse[OwnedGifts]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
return requestGeneric[OwnedGifts](b, "getBusinessAccountGifts", options)
}
// ConvertGiftToStars converts a given regular gift to Telegram Stars.
//
// https://core.telegram.org/bots/api#convertgifttostars
func (b *Bot) ConvertGiftToStars(
businessConnectionID, ownedGiftID string,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "convertGiftToStars", map[string]any{
"business_connection_id": businessConnectionID,
"owned_gift_id": ownedGiftID,
})
}
// UpgradeGift upgrades a given regular gift to a unique gift.
//
// https://core.telegram.org/bots/api#upgradegift
func (b *Bot) UpgradeGift(
businessConnectionID, ownedGiftID string,
options OptionsUpgradeGift,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
options["owned_gift_id"] = ownedGiftID
return requestGeneric[bool](b, "upgradeGift", options)
}
// TransferGift transfers an owned unique gift to another user.
//
// https://core.telegram.org/bots/api#transfergift
func (b *Bot) TransferGift(
businessConnectionID, ownedGiftID string,
newOwnerChatID int64,
options OptionsTransferGift,
) (result APIResponse[bool]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
options["owned_gift_id"] = ownedGiftID
options["new_owner_chat_id"] = newOwnerChatID
return requestGeneric[bool](b, "transferGift", options)
}
// PostStory posts a story on behalf of a managed business account.
//
// https://core.telegram.org/bots/api#poststory
func (b *Bot) PostStory(
businessConnectionID string,
content InputStoryContent,
activePeriod int,
options OptionsPostStory,
) (result APIResponse[Story]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
options["content"] = content
options["active_period"] = activePeriod
return requestGeneric[Story](b, "postStory", options)
}
// EditStory edits a story previously posted by the bot on behalf of a managed business account.
//
// https://core.telegram.org/bots/api#editstory
func (b *Bot) EditStory(
businessConnectionID string,
storyID int64,
content InputStoryContent,
options OptionsEditStory,
) (result APIResponse[Story]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["business_connection_id"] = businessConnectionID
options["story_id"] = storyID
options["content"] = content
return requestGeneric[Story](b, "editStory", options)
}
// DeleteStory deletes a story previously posted by the bot on behalf of a managed business account.
//
// https://core.telegram.org/bots/api#deletestory
func (b *Bot) DeleteStory(
businessConnectionID string,
storyID int64,
) (result APIResponse[bool]) {
return requestGeneric[bool](b, "deleteStory", map[string]any{
"business_connection_id": businessConnectionID,
"story_id": storyID,
})
}
// SendVideo sends a video file.
//
// https://core.telegram.org/bots/api#sendvideo
func (b *Bot) SendVideo(
chatID ChatID,
video InputFile,
options OptionsSendVideo,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["video"] = video
return requestGeneric[Message](b, "sendVideo", options)
}
// SendAnimation sends an animation.
//
// https://core.telegram.org/bots/api#sendanimation
func (b *Bot) SendAnimation(
chatID ChatID,
animation InputFile,
options OptionsSendAnimation,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["animation"] = animation
return requestGeneric[Message](b, "sendAnimation", options)
}
// SendVoice sends a voice file. (.ogg format only, will be played with Telegram itself))
//
// https://core.telegram.org/bots/api#sendvoice
func (b *Bot) SendVoice(
chatID ChatID,
voice InputFile,
options OptionsSendVoice,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["voice"] = voice
return requestGeneric[Message](b, "sendVoice", options)
}
// SendVideoNote sends a video note.
//
// videoNote cannot be a remote http url (not supported yet)
//
// https://core.telegram.org/bots/api#sendvideonote
func (b *Bot) SendVideoNote(
chatID ChatID,
videoNote InputFile,
options OptionsSendVideoNote,
) (result APIResponse[Message]) {
if options == nil {
options = map[string]any{}
}
// essential params
options["chat_id"] = chatID
options["video_note"] = videoNote
return requestGeneric[Message](b, "sendVideoNote", options)
}
// SendPaidMedia sends paid media.
//
// https://core.telegram.org/bots/api#sendpaidmedia
func (b *Bot) SendPaidMedia(
chatID ChatID,