-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.gs
2280 lines (2155 loc) · 95.1 KB
/
main.gs
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
/**
* A class representing the Telegram API wrapper.
* @class
* @param {string} token - The authentication token for the Telegram bot.
* @param {boolean} [logging=false] - Whether or not to log API responses.
* @property {string} token - The authentication token for the Telegram bot.
* @property {boolean} logging - Whether or not to log API responses.
* @property {string} apiVersion - The version of the Telegram API to use.
* @property {function} Type - A factory function for creating new Type objects.
* @property {function} Utils - A factory function for creating new Utils objects.
* @property {function} apiCall - A function for making API requests to the Telegram API.
*/
class TelegramApp {
constructor(token, logging) {
this.token = token;
this.logging = logging || false;
this.apiVersion = '6.6';
this.Type = () => new Type();
this.Utils = () => new Utils();
/**
* Makes an API request to the Telegram API.
* @function
* @param {string} token - The authentication token for the Telegram bot.
* @param {string} method - The Telegram API method to call.
* @param {object} [data] - The data to include in the API request.
* @returns {object} The result of the API request, if successful.
*/
this.apiCall = (token, method, data) => {
const url = `https://api.telegram.org/bot${token}/${method}`;
const options = {
muteHttpExceptions: true,
method: 'POST',
contentType: 'application/json',
};
if (data != null) {
options.payload = JSON.stringify(data);
}
const response = UrlFetchApp.fetch(url, options);
if (this.logging) {
Logger.log(response);
}
const json = JSON.parse(response);
if (json.result) {
return json.result;
} else {
Logger.log(response);
return;
}
};
}
// Getting updates
/**
* Retrieves updates using the Telegram API.
* @return {Object[]} An array of update objects.
*/
getUpdates() {
return this.apiCall(this.token, 'getUpdates').map(function (element) {
return this.Type().Update(element);
});
}
/**
* Sets a new incoming webhook for the Telegram Bot API.
* @param {Object} [params] - The parameters for the new incoming webhook.
* @param {string} [params.url] - HTTPS url to send updates to. Use an empty string to remove webhook integration.
* @param {Buffer} [params.certificate] - Public key certificate (PEM format) for the webhook server.
* @param {string} [params.ip_address] - The fixed IP address which should be used to send webhook requests instead of the IP address resolved through DNS.
* @param {number} [params.max_connections] - Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40.
* @param {string[]} [params.allowed_updates] - List the types of updates you want your bot to receive.
* @param {boolean} [params.drop_pending_updates] - Pass true to drop all pending updates.
* @param {string} [params.secret_token] - A secret token for the webhook URL has been specified, we will use this token to generate a unique URL for each user visiting the bot's webhook.
* @returns {Object} - Object representing the result of the API call.
* @throws {Error} - If `params` is not provided.
*/
setWebhook(params = {
url,
certificate,
ip_address,
max_connections,
allowed_updates,
drop_pending_updates,
secret_token
}) {
if (params) {
return this.apiCall(this.token, 'setWebhook', params);
} else {
throw new Error('Set setWebhook params');
}
}
/**
* Deletes the current webhook.
* @param {Object} [params] - The parameters to pass to the API request.
* @returns {boolean} - Returns True on success.
* @throws {Error} - If the `params` argument is not provided.
*/
deleteWebhook(params = {
drop_pending_updates
}) {
if (params) {
return this.apiCall(this.token, 'deleteWebhook', params);
} else {
throw new Error('Set deleteWebhook params');
}
}
/**
* Retrieves information about the current webhook.
* @returns {Object} The webhook information.
*/
getWebhookInfo() {
return this.Type().WebhookInfo(
this.apiCall(this.token, 'getWebhookInfo')
);
}
// Available methods
/**
* Retrieves information about the bot.
* @returns {User} Returns basic information about the bot in form of a User object.
*/
getMe() {
return this.Type().User(
this.apiCall(this.token, 'getMe')
);
}
/**
* Logs the bot out by calling the API's `logOut` method.
* @returns {boolean} Returns True on success.
*/
logOut() {
return this.apiCall(this.token, 'logOut');
}
/**
* Use this method to close the bot instance before moving it from one local server to another.
* @returns {boolean} Returns True on success.
*/
close() {
return this.apiCall(this.token, 'close');
}
/**
* Sends a message with the given parameters to a chat.
* @param {Object} [params={}] - An object containing the parameters for the message.
* @param {number} [params.chat_id] - The ID of the chat where the message should be sent.
* @param {number} [params.message_thread_id] - The ID of the message thread.
* @param {string} [params.text] - The text of the message.
* @param {string} [params.parse_mode] - The mode for parsing entities in the message text.
* @param {Object[]} [params.entities] - An array of message entities.
* @param {boolean} [params.disable_web_page_preview] - Whether to disable web page previews for links in the message.
* @param {boolean} [params.disable_notification] - Whether to disable notifications for the message.
* @param {boolean} [params.protect_content] - Whether to protect the content of the message.
* @param {number} [params.reply_to_message_id] - The ID of the message being replied to.
* @param {boolean} [params.allow_sending_without_reply] - Whether to allow sending the message without a reply.
* @param {Object} [params.reply_markup] - The reply markup for the message.
* @returns {Object} A message object.
*/
sendMessage(params = {
chat_id,
message_thread_id,
text,
parse_mode,
entities,
disable_web_page_preview,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendMessage', params)
);
}
/**
* Forward a message from one chat to another.
* @param {Object} params - Parameters for forwarding the message.
* @param {number} params.chat_id - The ID of the chat to forward the message to.
* @param {number} params.message_thread_id - The ID of the message thread to forward.
* @param {number} params.from_chat_id - The ID of the chat the message is being forwarded from.
* @param {boolean} [params.disable_notification=false] - Whether to disable notifications for the forwarded message.
* @param {boolean} [params.protect_content=false] - Whether to protect the forwarded message's content from being forwarded again.
* @param {number} [params.message_id] - The ID of the message to forward, if known.
* @returns {Object} - The forwarded message.
*/
forwardMessage(params = {
chat_id,
message_thread_id,
from_chat_id,
disable_notification,
protect_content,
message_id
}) {
return this.Type().Message(
this.apiCall(this.token, 'forwardMessage', params)
);
}
/**
* Copies a message to a different chat or channel.
* @param {Object} params - The parameters for the message copy operation.
* @param {number} params.chat_id - The ID of the chat where the message will be copied to.
* @param {number} params.message_thread_id - The ID of the thread where the message will be copied to.
* @param {number} params.from_chat_id - The ID of the chat where the original message was sent.
* @param {number} params.message_id - The ID of the original message to be copied.
* @param {string} params.caption - The caption to be sent with the copied message.
* @param {string} params.parse_mode - The parsing mode for the caption.
* @param {Array} params.caption_entities - An array of special entities in the caption, such as usernames or hashtags.
* @param {boolean} params.disable_notification - Whether to disable notifications for the copied message.
* @param {boolean} params.protect_content - Whether to protect the copied content with a password.
* @param {number} params.reply_to_message_id - The ID of the message to reply to with the copied message.
* @param {boolean} params.allow_sending_without_reply - Whether to allow sending the copied message without a reply.
* @param {Object} params.reply_markup - The reply markup for the copied message.
* @returns {Object} - The message ID of the copied message.
*/
copyMessage(params = {
chat_id,
message_thread_id,
from_chat_id,
message_id,
caption,
parse_mode,
caption_entities,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().MessageId(
this.apiCall(this.token, 'copyMessage', params)
);
}
/**
* Sends a photo message to a chat.
* @param {Object} [params] - The parameters object.
* @param {number|string} [params.chat_id] - The chat ID where the photo will be sent.
* @param {number} [params.message_thread_id] - The ID of the message thread.
* @param {string|ReadableStream|Buffer} [params.photo] - The photo to send. Can be a file ID, a ReadableStream or a Buffer.
* @param {string} [params.caption] - The caption for the photo.
* @param {string} [params.parse_mode] - The parse mode to use for the caption.
* @param {Object[]} [params.caption_entities] - List of special entities that appear in the caption.
* @param {boolean} [params.has_spoiler] - Whether the photo contains a spoiler.
* @param {boolean} [params.disable_notification] - Whether to disable the notification for the message.
* @param {boolean} [params.protect_content] - Whether the content should be protected.
* @param {number} [params.reply_to_message_id] - The ID of the message to reply to.
* @param {boolean} [params.allow_sending_without_reply] - Whether to allow sending the message without a reply.
* @param {Object} [params.reply_markup] - The reply markup for the message.
* @returns {Object} - On success, the sent Message is returned.
*/
sendPhoto(params = {
chat_id,
message_thread_id,
photo,
caption,
parse_mode,
caption_entities,
has_spoiler,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendPhoto', params)
);
}
/**
* Sends an audio message with parameters supplied as an object
* @param {Object} params - An object with the parameters for sending an audio
* @param {String} params.chat_id - Unique identifier of the chat
* @param {String} params.message_thread_id - Unique identifier of the thread
* @param {String|InputFile} params.audio - Audio file
* @param {String} params.caption - Audio message caption, 0-1024 characters
* @param {String} params.parse_mode - Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption
* @param {Array} params.caption_entities - Array of InlineKeyboardMarkup objects
* @param {Integer} params.duration - Duration of the audio in seconds
* @param {String} params.performer - Performer
* @param {String} params.title - Track name
* @param {String|InputFile} params.thumbnail - Thumbnail of the audio file
* @param {boolean} params.disable_notification - Sends the message silently.
* @param {boolean} params.protect_content - True, if content should be protected
* @param {String} params.reply_to_message_id - If the message is a reply, ID of the original message
* @param {boolean} params.allow_sending_without_reply - Pass True, if the message should be sent even if the specified replied-to message is not found
* @param {Object} params.reply_markup - Keyboard of InlineKeyboardMarkup type
* @return {Message} - Message object
*/
sendAudio(params = {
chat_id,
message_thread_id,
audio,
caption,
parse_mode,
caption_entities,
duration,
performer,
title,
thumbnail,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendAudio', params)
);
}
/**
* Sends a document
* @param {Object} params - Object containing all the parameters
* @param {number} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param {string} params.message_thread_id - Identifier of the message thread in which the messaging participants are involved
* @param {string} params.document - File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet
* @param {string} params.thumbnail - Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side
* @param {string} params.caption - Optional. Document caption (may also be used when resending documents by file_id)
* @param {string} params.parse_mode - Optional. Mode for parsing entities in the document caption. See formatting options for more details.
* @param {Object[]} params.caption_entities - Optional. List of special entities that appear in the caption, which can be specified instead of “parse_mode”
* @param {boolean} params.disable_content_type_detection - Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data
* @param {boolean} params.disable_notification - Optional. Sends the message silently. Users will receive a notification with no sound
* @param {boolean} params.protect_content -Optional. Use this parameter if you want Telegram to send a message as a Markdown or HTML
* @param {number} params.reply_to_message_id - Optional. If the message is a reply, ID of the original message
* @param {boolean} params.allow_sending_without_reply - Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
* @param {Object} params.reply_markup - Optional. Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user
* @returns {Message} Data for a new sent message
*/
sendDocument(params = {
chat_id,
message_thread_id,
document,
thumbnail,
caption,
parse_mode,
caption_entities,
disable_content_type_detection,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendDocument', params)
);
}
/**
* Sends a video to the specified chat.
* @param {Object} params - The request parameters
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target channel
* @param {String} params.message_thread_id - The message thread identifier of the previous sent message.
* @param {unit8Array} params.video - Video file
* @param {Number} [params.duration] - Duration of the video in seconds
* @param {Number} [params.width] - Video width
* @param {Number} [params.height] - Video height
* @param {Object|String} [params.thumbnail] - Video thumbnail
* @param {String} [params.caption] - Video caption
* @param {String} [params.parse_mode] - The parse mode used for the caption
* @param {Array} [params.caption_entities] - Additional caption formatting entities
* @param {Boolean} [params.has_spoiler] - Boolean value to mark content that contains spoilers
* @param {Boolean} [params.supports_streaming] - Boolean indicating if the video supports streaming
* @param {Boolean} [params.disable_notification] - Sends the message silently. Users will receive a notification with no sound.
* @param {Boolean} [params.protect_content] - Boolean value disallow users to capture and share the video
* @param {Number} [params.reply_to_message_id] - If the message is a reply, ID of the original message
* @param {Boolean} [params.allow_sending_without_reply] - Pass True, if the message should be sent even if the specified replied-to message is not found
* @param {Array} [params.reply_markup] - Additional interface options
* @returns {Object} Message
*/
sendVideo(params = {
chat_id,
message_thread_id,
video,
duration,
width,
height,
thumbnail,
caption,
parse_mode,
caption_entities,
has_spoiler,
supports_streaming,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendVideo', params)
);
}
/**
* Sends an animation to chat.
* @param {Object} [params] The parameters to send along with the animation.
* @param {number} [params.chat_id] Unique identifier for the target chat.
* @param {string} [params.message_thread_id] The identifier of the message thread which sender want to send animation to.
* @param {InputFile} [params.animation] Animation to send. You can either pass a file_id as String to resend an animation that is already on the Telegram servers, or upload a new animation file using multipart/form-data
* @param {number} [params.duration] Duration of sent animation in seconds
* @param {number} [params.width] Animation width
* @param {number} [params.height] Animation height
* @param {InputFile} [params.thumbnail] Thumbnail of the animation file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
* @param {string} [params.caption] Animation caption (may also be used when resending animation by file_id), 0-1024 characters
* @param {string} [params.parse_mode] Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
* @param {MessageEntity} [params.caption_entities] List of special entities that appear in the caption, which can be specified instead of parse_mode
* @param {boolean} [params.has_spoiler] Pass True, if the message should be marked as a warning
* @param {boolean} [params.disable_notification] Sends the message silently. Users will receive a notification with no sound.
* @param {boolean} [params.protect_content] Pass True, if you want to upload animation which must be treated as safe by the clients.
* @param {number} [params.reply_to_message_id] If the message is a reply, ID of the original message
* @param {boolean} [params.allow_sending_without_reply] Pass True, if the message should be sent even if the specified replied-to message is not found
* @param {InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply} [params.reply_markup] 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.
* @returns {Message} On success, the sent Message is returned.
*/
sendAnimation(params = {
chat_id,
message_thread_id,
animation,
duration,
width,
height,
thumbnail,
caption,
parse_mode,
caption_entities,
has_spoiler,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendAnimation', params)
);
}
/**
* Sends an audio message using a voice.
* @param { Object } [params] - Parameters for the request
* @param { Number } [params.chat_id] - Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param { Number } [params.message_thread_id] - Identifier of the message to reply to.
* @param { String } params.voice - Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data
* @param { String } [params.caption] - Voice message caption, 0-1024 characters
* @param { String } [params.parse_mode] - Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
* @param { Array<objects> } [params.caption_entities] - List of special entities that appear in the caption, which can be specified instead of parse_mode
* @param { Number } [params.duration] - Duration of the voice message in seconds.
* @param { Boolean } [params.disable_notification] - Sends the message silently. Users will receive a notification with no sound.
* @param { String } [params.protect_content] - Pass True, to enable server-side content notification protection for this message.
* @param { Number } [params.reply_to_message_id] - If the message is a reply, ID of the original message
* @param { Boolean } [params.allow_sending_without_reply] - Pass True, if the message should be sent even if the specified replied-to message is not found
* @param { Object } [params.reply_markup] - 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.
* @returns { Message } - Returns the sent Message on success
*/
sendVoice(params = {
chat_id,
message_thread_id,
voice,
caption,
parse_mode,
caption_entities,
duration,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendVoice', params)
);
}
/**
* Sends a video note to the specified chat.
* @param {object} params - An object containing the necessary parameters to send a video note.
* @param {number|string} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @param {string} params.message_thread_id - Identifier of the message thread to send the video note.
* @param {string} params.video_note - Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data.
* @param {number} params.duration - Duration of sent video in seconds.
* @param {number} params.length - Video width and height.
* @param {string} params.thumbnail - Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* @param {boolean} params.disable_notification - Sends the message silently. Users will receive a notification with no sound.
* @param {boolean} params.protect_content - Disables content sharing in the message thread.
* @param {number} params.reply_to_message_id - If the message is a reply, ID of the original message.
* @param {boolean} params.allow_sending_without_reply - Pass True, if the message should be sent even if the specified replied-to message is not found.
* @param {object} params.reply_markup - Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
* @return {Message} - Sent message object.
*/
sendVideoNote(params = {
chat_id,
message_thread_id,
video_note,
duration,
length,
thumbnail,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendVideoNote', params)
);
}
/**
* Send a group of media files.
* @param {Object} params - Parameters for media group sending request.
* @param {Number|String} params.chat_id - Unique identifier for the target chat.
* @param {String} params.message_thread_id - thread identifier that mediagroup belongs to.
* @param {Object} params.media - An array containing media objects.
* @param {Boolean} [params.disable_notification] - Sends the message silently.
* @param {Boolean} [params.protect_content] - Pass True, if messages should be sent in media group should be protected.
* @param {Number} [params.reply_to_message_id] - If the message is a reply, ID of the original message.
* @param {Boolean} [params.allow_sending_without_reply] - Pass True, if messages should be sent in media group should be sent without mention.
* @return {Message} - A message with its fields filled.
*/
sendMediaGroup(params = {
chat_id,
message_thread_id,
media,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendMediaGroup', params)
);
}
/**
* Send a location
* @param {Object=} params Object with optional params.
* @prop {Number} params.chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @prop {String} params.message_thread_id Identifies the message thread the message will be sent in
* @prop {Number} params.latitude Latitude of the location
* @prop {Number} params.longitude Longitude of the location
* @prop {Number} params.horizontal_accuracy The radius of uncertainty for the location, measured in meters
* @prop {Number} params.live_period Period in seconds for which the location will be updated (see Live Locations)
* @prop {Number} params.heading Direction in which the user is moving, in degrees
* @prop {Number} params.proximity_alert_radius Maximum distance for proximity alerts about the user, in meters
* @prop {Boolean} params.disable_notification Sends the message silently. Users will receive a notification with no sound.
* @prop {Boolean} params.protect_content Pass True, if content should be protected
* @prop {Number} params.reply_to_message_id If the message is a reply, ID of the original message
* @prop {Boolean} params.allow_sending_without_reply Pass True, if the message should be sent even if the specified replied-to message is not found
* @prop {Object} params.reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove keyboard or to force a reply from the user.
* @returns {Message} - A message with its fields filled.
*/
sendLocation(params = {
chat_id,
message_thread_id,
latitude,
longitude,
horizontal_accuracy,
live_period,
heading,
proximity_alert_radius,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendLocation', params)
);
}
/**
* Sends a venue to a chat.
* @param {Object} params - Parameters for the API call.
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @param {String} params.message_thread_id - Identifier of the message thread the message belongs to.
* @param {Number} params.latitude - Latitude of the venue.
* @param {Number} params.longitude - Longitude of the venue.
* @param {String} params.title - Name of the venue.
* @param {String} params.address - Address of the venue.
* @param {String} params.foursquare_id - Foursquare identifier of the venue.
* @param {String} params.foursquare_type - Foursquare type of the venue.
* @param {String} params.google_place_id - Google Places identifier of the venue.
* @param {String} params.google_place_type - Google Places type of the venue.
* @param {Boolean} params.disable_notification - Sends the message silently. Users will receive a notification with no sound.
* @param {Boolean} params.protect_content - Pass True, if the message should be sent with content protection.
* @param {Number} params.reply_to_message_id - If the message is a reply, ID of the original message.
* @param {Boolean} params.allow_sending_without_reply - Pass True, if the message should be sent even if the specified replied-to message is not found.
* @param {Object} params.reply_markup - 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.
* @return {Message} - On success, the sent Message is returned.
*/
sendVenue(params = {
chat_id,
message_thread_id,
latitude,
longitude,
title,
address,
foursquare_id,
foursquare_type,
google_place_id,
google_place_type,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendVenue', params)
);
}
/**
* Sends a contact to the specified chat.
* @param {Object} params - Parameters for the API call.
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @param {Number} [params.message_thread_id] - Identifier of the message thread the contact message belongs to.
* @param {String} params.phone_number - Contact's phone number.
* @param {String} params.first_name - Contact's first name.
* @param {String} [params.last_name] - Contact's last name.
* @param {String} [params.vcard] - Additional data about the contact in the form of a vCard, 0-2048 bytes.
* @param {Boolean} [params.disable_notification] - Sends the message silently. Users will receive a notification with no sound.
* @param {Boolean} [params.protect_content] - Pass True, if the message should be sent with content protection.
* @param {Number} [params.reply_to_message_id] - If the message is a reply, ID of the original message.
* @param {Boolean} [params.allow_sending_without_reply] - Pass True, if the message should be sent even if the specified replied-to message is not found.
* @param {Object} [params.reply_markup] - 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.
* @returns {Message} - On success, the sent Message is returned.
*/
sendContact(params = {
chat_id,
message_thread_id,
phone_number,
first_name,
last_name,
vcard,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendContact', params)
);
}
/**
* Sends a poll to a chat.
* @param {Object} params - Parameters for the API call.
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @param {Number} [params.message_thread_id] - Identifier of the message to reply to or 0.
* @param {String} params.question - Poll question, 1-255 characters.
* @param {Array} params.options - List of answer options, 2-10 strings 1-100 characters each.
* @param {Boolean} [params.is_anonymous] - True, if the poll needs to be anonymous, defaults to True.
* @param {String} [params.type] - Poll type, “quiz” or “regular”, defaults to “regular”.
* @param {Boolean} [params.allows_multiple_answers] - True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False.
* @param {Number} [params.correct_option_id] - 0-based identifier of the correct answer option, required for polls in quiz mode.
* @param {String} [params.explanation] - Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing.
* @param {String} [params.explanation_parse_mode] - Mode for parsing entities in the explanation.
* @param {Array} [params.explanation_entities] - List of special entities that appear in the explanation, which can be specified instead of parse_mode.
* @param {Number} [params.open_period] - Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
* @param {Number} [params.close_date] - Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
* @param {Boolean} [params.is_closed] - Pass True, if the poll needs to be immediately closed. This can be useful for poll preview.
* @param {Boolean} [params.disable_notification] - Sends the message silently. Users will receive a notification with no sound.
* @param {Boolean} [params.protect_content] - Pass True, if the message should be sent with content protection.
* @param {Number} [params.reply_to_message_id] - If the message is a reply, ID of the original message.
* @param {Boolean} [params.allow_sending_without_reply] - Pass True, if the message should be sent even if the specified replied-to message is not found.
* @param {Object} [params.reply_markup] - 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.
* @returns {Message} - On success, the sent Message is returned.
*/
sendPoll(params = {
chat_id,
message_thread_id,
question,
options,
is_anonymous,
type,
allows_multiple_answers,
correct_option_id,
explanation,
explanation_parse_mode,
explanation_entities,
open_period,
close_date,
is_closed,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendPoll', params)
);
}
/**
* Sends a dice message to the specified chat.
* @param {Object} params - Parameters for the API call.
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @param {String} [params.message_thread_id] - Identifier of the message thread the dice message belongs to.
* @param {String} [params.emoji] - Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, or “🏀”. Defaults to “🎲”.
* @param {Boolean} [params.disable_notification] - Sends the message silently. Users will receive a notification with no sound.
* @param {Boolean} [params.protect_content] - Disables link previews for links in this message.
* @param {Number} [params.reply_to_message_id] - If the message is a reply, ID of the original message.
* @param {Boolean} [params.allow_sending_without_reply] - Pass True, if the message should be sent even if the specified replied-to message is not found.
* @param {Object} [params.reply_markup] - 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.
* @returns {Object} - Returns the sent Message.
*/
sendDice(params = {
chat_id,
message_thread_id,
emoji,
disable_notification,
protect_content,
reply_to_message_id,
allow_sending_without_reply,
reply_markup
}) {
return this.Type().Message(
this.apiCall(this.token, 'sendDice', params)
);
}
/**
* Sends a chat action to the specified chat.
* @param {Object} params - Parameters for the API call.
* @param {string} params.chat_id - Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* @param {string} [params.message_thread_id] - Identifier of the message thread the action should be sent in.
* @param {string} params.action - Type of action to broadcast.
* @returns {Object} - Returns the API call.
*/
sendChatAction(params = {
chat_id,
message_thread_id,
action
}) {
return this.apiCall(this.token, 'sendChatAction', params);
}
/**
* Retrieves a user's profile photos.
* @param {Object} params - Parameters for the request.
* @param {number} params.user_id - Unique identifier of the target user.
* @param {number} [params.offset] - Sequential number of the first photo to be returned. By default, all photos are returned.
* @param {number} [params.limit] - Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
* @returns {UserProfilePhotos} - The user's profile photos.
*/
getUserProfilePhotos(params = {
user_id,
offset,
limit
}) {
return this.Type().UserProfilePhotos(
this.apiCall(this.token, 'getUserProfilePhotos', params)
);
}
/**
* Retrieves information about a file and its download link.
* @param {Object} params - Parameters for the API call.
* @param {string} params.file_id - Unique identifier for the file.
* @returns {Object} - A promise that resolves with the API call response.
*/
getFile(params = {
file_id
}) {
return this.apiCall(this.token, 'getFile', params);
}
/**
* Bans a user from a chat.
* @param {Object} params - Parameters for the API call.
* @param {Number} params.chat_id - Unique identifier for the target chat.
* @param {Number} params.user_id - Unique identifier of the target user.
* @param {Number} [params.until_date] - 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.
* @param {Boolean} [params.revoke_messages] - Pass true, if the messages sent by the user in the chat should be deleted.
* @returns {True}
*/
banChatMember(params = {
chat_id,
user_id,
until_date,
revoke_messages
}) {
return this.apiCall(this.token, 'banChatMember', params);
}
/**
* Unban a user from a chat
* @param {Object} params - Parameters for the API call
* @param {Number} params.chat_id - Unique identifier for the target chat
* @param {Number} params.user_id - Unique identifier of the target user
* @param {Boolean} [params.only_if_banned] - Optional. Pass true to unban only if the user is currently banned
* @returns {True}
*/
unbanChatMember(params = {
chat_id,
user_id,
only_if_banned
}) {
return this.apiCall(this.token, 'unbanChatMember', params);
}
/**
* Restricts a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
* @param {Object} params - Parameters for the API call
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
* @param {Number} params.user_id - Unique identifier of the target user
* @param {Object} params.permissions - New user permissions
* @param {Boolean} params.use_independent_chat_permissions - Pass True, if the user will not be able to change chat title, photo and other settings
* @param {Number} params.until_date - Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever
* @returns {True}
*/
restrictChatMember(params = {
chat_id,
user_id,
permissions,
use_independent_chat_permissions,
until_date
}) {
return this.apiCall(this.token, 'restrictChatMember', params);
}
/**
* Promote a user in a chat
* @param {Object} params - Parameters for the API call
* @param {Number} params.chat_id - Unique identifier for the target chat
* @param {Number} params.user_id - Unique identifier of the target user
* @param {Boolean} [params.is_anonymous] - Pass True, if the user's presence in the chat is hidden
* @param {Boolean} [params.can_manage_chat] - Pass True, if the user is allowed to manage the chat
* @param {Boolean} [params.can_post_messages] - Pass True, if the user is allowed to send messages, contacts, locations and venues
* @param {Boolean} [params.can_edit_messages] - Pass True, if the user is allowed to edit messages of other users and can pin messages
* @param {Boolean} [params.can_delete_messages] - Pass True, if the user is allowed to delete messages of other users
* @param {Boolean} [params.can_manage_video_chats] - Pass True, if the user is allowed to manage video chats
* @param {Boolean} [params.can_restrict_members] - Pass True, if the user is allowed to restrict, ban or unban chat members
* @param {Boolean} [params.can_promote_members] - Pass True, if the user is allowed to add new members to the chat
* @param {Boolean} [params.can_change_info] - Pass True, if the user is allowed to change the chat title, photo and other settings
* @param {Boolean} [params.can_invite_users] - Pass True, if the user is allowed to invite new users to the chat
* @param {Boolean} [params.can_pin_messages] - Pass True, if the user is allowed to pin messages
* @param {Boolean} [params.can_manage_topics] - Pass True, if the user is allowed to manage chat topics
* @returns {True}
*/
promoteChatMember(params = {
chat_id,
user_id,
is_anonymous,
can_manage_chat,
can_post_messages,
can_edit_messages,
can_delete_messages,
can_manage_video_chats,
can_restrict_members,
can_promote_members,
can_change_info,
can_invite_users,
can_pin_messages,
can_manage_topics
}) {
return this.apiCall(this.token, 'promoteChatMember', params);
}
/**
* Sets a custom title for an administrator in a chat.
* @param {Object} params - Parameters for the API call
* @param {Number} params.chat_id - Unique identifier for the target chat
* @param {Number} params.user_id - Unique identifier of the target user
* @param {String} params.custom_title - New custom title for the administrator; 0-16 characters, emoji are not allowed
* @returns {True}
*/
setChatAdministratorCustomTitle(params = {
chat_id,
user_id,
custom_title
}) {
return this.apiCall(this.token, 'setChatAdministratorCustomTitle', params);
}
/**
* Bans a user from a chat.
* @param {Object} params - Parameters for the API call.
* @param {Number} params.chat_id - Unique identifier for the target chat.
* @param {Number} params.sender_chat_id - Unique identifier of the user to be banned.
* @returns {True}
*/
banChatSenderChat(params = {
chat_id,
sender_chat_id
}) {
return this.apiCall(this.token, 'banChatSenderChat', params);
}
/**
* Unban a sender from a chat
* @param {Object} params - Parameters for unbanning a sender from a chat
* @param {Number} params.chat_id - The chat ID of the chat to unban the sender from
* @param {Number} params.sender_chat_id - The chat ID of the sender to unban
* @returns {True}
*/
unbanChatSenderChat(params = {
chat_id,
sender_chat_id
}) {
return this.apiCall(this.token, 'unbanChatSenderChat', params);
}
/**
* Sets the permissions for a chat.
* @param {Object} params - Parameters for setting chat permissions.
* @param {Number} params.chat_id - Unique identifier for the target chat or username of the target supergroup or channel.
* @param {Object} params.permissions - New default chat permissions.
* @param {Boolean} params.use_independent_chat_permissions - Pass true to use independent chat permissions.
* @returns {True}
*/
setChatPermissions(params = {
chat_id,
permissions,
use_independent_chat_permissions
}) {
return this.apiCall(this.token, 'setChatPermissions', params);
}
/**
* Generates a new invite link for a chat; any previously generated link is revoked.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns the new invite link as String on success.
* @param {Object} params - Parameters for the request
* @param {Number} params.chat_id - Unique identifier for the target chat
* @returns {String} - New invite link as String
*/
exportChatInviteLink(params = {
chat_id
}) {
return this.apiCall(this.token, 'exportChatInviteLink', params);
}
/**
* Creates a new invite link for a chat.
* @param {Object} params - Parameters for creating a chat invite link.
* @param {Number} params.chat_id - Unique identifier for the target chat.
* @param {String} [params.name] - Name of the chat.
* @param {Number} [params.expire_date] - Date when the link will expire in Unix time.
* @param {Number} [params.member_limit] - Maximum number of members allowed in the chat.
* @param {Boolean} [params.creates_join_request] - True, if the link will create a join request.
* @returns {ChatInviteLink} - The newly created chat invite link.
*/
createChatInviteLink(params = {
chat_id,
name,
expire_date,
member_limit,
creates_join_request
}) {
return this.Type().ChatInviteLink(
this.apiCall(this.token, 'createChatInviteLink', params)
);
}
/**
* Edits the invite link of a chat.
* @param {Object} params - Parameters for editing the invite link.
* @param {Number} params.chat_id - Unique identifier for the target chat.
* @param {String} params.invite_link - New invite link.
* @param {String} [params.name] - Name of the chat.
* @param {Number} [params.expire_date] - Expiration date of the invite link.
* @param {Number} [params.member_limit] - Maximum number of members allowed in the chat.
* @param {Boolean} [params.creates_join_request] - Whether the invite link should create a join request.
* @returns {ChatInviteLink} - The new invite link.
*/
editChatInviteLink(params = {
chat_id,
invite_link,
name,
expire_date,
member_limit,
creates_join_request
}) {
return this.Type().ChatInviteLink(
this.apiCall(this.token, 'editChatInviteLink', params)
);
}
/**
* Revoke an invite link for a chat
* @param {Object} params - Parameters for the API call