/
api.ts
1883 lines (1794 loc) · 85.1 KB
/
api.ts
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
// deno-lint-ignore-file camelcase
import {
BotCommand,
ChatPermissions,
InlineQueryResult,
InputFile,
InputMedia,
InputMediaAudio,
InputMediaDocument,
InputMediaPhoto,
InputMediaVideo,
LabeledPrice,
Opts,
PassportElementError,
} from '../platform.ts'
import {
createRawApi,
RawApi,
ApiClientOptions,
TransformerConsumer,
WebhookReplyEnvelope,
Transformer,
} from './client.ts'
type AlwaysOmittedInOther = 'chat_id'
/**
* Helper type to derive remaining properties of a given API method call M,
* given that some properties X have already been specified.
*/
export type Other<
M extends keyof RawApi,
X extends keyof Omit<Opts<M>, AlwaysOmittedInOther> = never
> = Omit<Opts<M>, AlwaysOmittedInOther | X>
/**
* This class provides access to the full Telegram Bot API. All methods of the
* API have an equivalent on this class, with the most important parameters
* pulled up into the function signature, and the other parameters captured by
* an object.
*
* In addition, this class has a property `raw` that provides raw access to the
* complete Telegram API, with the method signatures 1:1 represented as
* documented on the website (https://core.telegram.org/bots/api).
*
* Every method takes an optional `AbortSignal` object that allows you to cancel
* the request if desired.
*
* In advanced use cases, this class allows to install transformers that can
* modify the method and payload on the fly before sending it to the Telegram
* servers. Confer the `config` property for this.
*/
export class Api {
/**
* Provides access to all methods of the Telegram Bot API exactly as
* documented on the website (https://core.telegram.org/bots/api). No
* arguments are pulled up in the function signature for convenience.
*
* If you suppress compiler warnings, this also allows for raw api calls to
* undocumented methods with arbitrary parameters—use only if you know what
* you are doing.
*/
public readonly raw: RawApi
/**
* Configuration object for the API instance, used as a namespace to
* separate those API operations that are related to grammY from methods of
* the Telegram Bot API. Contains advanced options!
*/
public readonly config: {
/**
* Allows to install an API request transformer function. A transformer
* function has access to every API call before it is being performed.
* This includes the method as string, the payload as object and the
* upstream transformer function.
*
* _Note that using transformer functions is an advanced feature of
* grammY that most bots will not need to make use of._
*/
readonly use: TransformerConsumer
/**
* Provides read access to all currently installed transformers (those
* that have previously been passed to `config.use`).
*
* _Note that using transformer functions is an advanced feature of
* grammY that most bots will not need to make use of._
*/
readonly installedTransformers: () => Transformer[]
}
constructor(
token: string,
config?: ApiClientOptions,
webhookReplyEnvelope?: WebhookReplyEnvelope
) {
const { raw, use, installedTransformers } = createRawApi(
token,
config,
webhookReplyEnvelope
)
this.raw = raw
this.config = {
use,
installedTransformers: () => [...installedTransformers],
}
}
/**
* Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
*
* Notes
* 1. This method will not work if an outgoing webhook is set up.
* 2. In order to avoid getting duplicate updates, recalculate offset after each server response.
*
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#getupdates
*/
getUpdates(other?: Other<'getUpdates'>, signal?: AbortSignal) {
return this.raw.getUpdates({ ...other }, signal)
}
/**
* Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
*
* If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
*
* Notes
* 1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
* 2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
* 3. Ports currently supported for Webhooks: 443, 80, 88, 8443.
*
* NEW! If you're having any trouble setting up webhooks, please check out this amazing guide to Webhooks.
*
* @param url HTTPS url to send updates to. Use an empty string to remove webhook integration
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#setwebhook
*/
setWebhook(
url: string,
other?: Other<'setWebhook', 'url'>,
signal?: AbortSignal
) {
return this.raw.setWebhook({ url, ...other }, signal)
}
/**
* Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.
*
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#deletewebhook
*/
deleteWebhook(other?: Other<'deleteWebhook'>, signal?: AbortSignal) {
return this.raw.deleteWebhook({ ...other }, signal)
}
/**
* Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
*
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#getwebhookinfo
*/
getWebhookInfo(signal?: AbortSignal) {
return this.raw.getWebhookInfo(signal)
}
/**
* A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object.
*
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#getme
*/
getMe(signal?: AbortSignal) {
return this.raw.getMe(signal)
}
/**
* Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success. Requires no parameters.
*
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#logout
*/
logOut(signal?: AbortSignal) {
return this.raw.logOut(signal)
}
/**
* 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.
*
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#close
*/
close(signal?: AbortSignal) {
return this.raw.close(signal)
}
/**
* Use this method to send text messages. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param text Text of the message to be sent, 1-4096 characters after entities parsing
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendmessage
*/
sendMessage(
chat_id: number | string,
text: string,
other?: Other<'sendMessage', 'text'>,
signal?: AbortSignal
) {
return this.raw.sendMessage({ chat_id, text, ...other }, signal)
}
/**
* Use this method to forward messages of any kind. Service messages can't be forwarded. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
* @param message_id Message identifier in the chat specified in from_chat_id
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#forwardmessage
*/
forwardMessage(
chat_id: number | string,
from_chat_id: number | string,
message_id: number,
other?: Other<'forwardMessage', 'from_chat_id' | 'message_id'>,
signal?: AbortSignal
) {
return this.raw.forwardMessage(
{
chat_id,
from_chat_id,
message_id,
...other,
},
signal
)
}
/**
* Use this method to copy messages of any kind. Service messages and invoice messages can't be copied. 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.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
* @param message_id Message identifier in the chat specified in from_chat_id
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#copymessage
*/
copyMessage(
chat_id: number | string,
from_chat_id: number | string,
message_id: number,
other?: Other<'copyMessage', 'from_chat_id' | 'message_id'>,
signal?: AbortSignal
) {
return this.raw.copyMessage(
{
chat_id,
from_chat_id,
message_id,
...other,
},
signal
)
}
/**
* Use this method to send photos. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param photo Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20.
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendphoto
*/
sendPhoto(
chat_id: number | string,
photo: InputFile | string,
other?: Other<'sendPhoto', 'photo'>,
signal?: AbortSignal
) {
return this.raw.sendPhoto({ chat_id, photo, ...other }, signal)
}
/**
* Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
*
* For sending voice messages, use the sendVoice method instead.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param audio 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 other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendaudio
*/
sendAudio(
chat_id: number | string,
audio: InputFile | string,
other?: Other<'sendAudio', 'audio'>,
signal?: AbortSignal
) {
return this.raw.sendAudio({ chat_id, audio, ...other }, signal)
}
/**
* Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param 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, or upload a new one using multipart/form-data.
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#senddocument
*/
sendDocument(
chat_id: number | string,
document: InputFile | string,
other?: Other<'sendDocument', 'document'>,
signal?: AbortSignal
) {
return this.raw.sendDocument({ chat_id, document, ...other }, signal)
}
/**
* Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param video Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data.
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendvideo
*/
sendVideo(
chat_id: number | string,
video: InputFile | string,
other?: Other<'sendVideo', 'video'>,
signal?: AbortSignal
) {
return this.raw.sendVideo({ chat_id, video, ...other }, signal)
}
/**
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param animation Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data.
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendanimation
*/
sendAnimation(
chat_id: number | string,
animation: InputFile | string,
other?: Other<'sendAnimation', 'animation'>,
signal?: AbortSignal
) {
return this.raw.sendAnimation({ chat_id, animation, ...other }, signal)
}
/**
* Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param voice Audio 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, or upload a new one using multipart/form-data.
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendvoice
*/
sendVoice(
chat_id: number | string,
voice: InputFile | string,
other?: Other<'sendVoice', 'voice'>,
signal?: AbortSignal
) {
return this.raw.sendVoice({ chat_id, voice, ...other }, signal)
}
/**
* Use this method to send video messages. On success, the sent Message is returned.
* As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param 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.. Sending video notes by a URL is currently unsupported
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendvideonote
*/
sendVideoNote(
chat_id: number | string,
video_note: InputFile | string,
other?: Other<'sendVideoNote', 'video_note'>,
signal?: AbortSignal
) {
return this.raw.sendVideoNote({ chat_id, video_note, ...other }, signal)
}
/**
* Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param media An array describing messages to be sent, must include 2-10 items
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendmediagroup
*/
sendMediaGroup(
chat_id: number | string,
media: ReadonlyArray<
| InputMediaAudio
| InputMediaDocument
| InputMediaPhoto
| InputMediaVideo
>,
other?: Other<'sendMediaGroup', 'media'>,
signal?: AbortSignal
) {
return this.raw.sendMediaGroup({ chat_id, media, ...other }, signal)
}
/**
* Use this method to send point on the map. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param latitude Latitude of the location
* @param longitude Longitude of the location
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendlocation
*/
sendLocation(
chat_id: number | string,
latitude: number,
longitude: number,
other?: Other<'sendLocation', 'latitude' | 'longitude'>,
signal?: AbortSignal
) {
return this.raw.sendLocation(
{ chat_id, latitude, longitude, ...other },
signal
)
}
/**
* Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param message_id Identifier of the message to edit
* @param latitude Latitude of new location
* @param longitude Longitude of new location
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#editmessagelivelocation
*/
editMessageLiveLocation(
chat_id: number,
message_id: number,
latitude: number,
longitude: number,
other?: Other<
'editMessageLiveLocation',
'message_id' | 'inline_message_id' | 'latitude' | 'longitude'
>,
signal?: AbortSignal
) {
return this.raw.editMessageLiveLocation(
{
chat_id,
message_id,
latitude,
longitude,
...other,
},
signal
)
}
/**
* Use this method to edit live location inline messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
*
* @param inline_message_id Identifier of the inline message
* @param latitude Latitude of new location
* @param longitude Longitude of new location
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#editmessagelivelocation
*/
editMessageLiveLocationInline(
inline_message_id: string,
latitude: number,
longitude: number,
other?: Other<
'editMessageLiveLocation',
'message_id' | 'inline_message_id' | 'latitude' | 'longitude'
>,
signal?: AbortSignal
) {
return this.raw.editMessageLiveLocation(
{
inline_message_id,
latitude,
longitude,
...other,
},
signal
)
}
/**
* Use this method to stop updating a live location message before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param message_id Identifier of the message with live location to stop
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#stopmessagelivelocation
*/
stopMessageLiveLocation(
chat_id: number | string,
message_id: number,
other?: Other<
'stopMessageLiveLocation',
'message_id' | 'inline_message_id'
>,
signal?: AbortSignal
) {
return this.raw.stopMessageLiveLocation(
{
chat_id,
message_id,
...other,
},
signal
)
}
/**
* Use this method to stop updating a live location inline message before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.
*
* @param inline_message_id Identifier of the inline message
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#stopmessagelivelocation
*/
stopMessageLiveLocationInline(
inline_message_id: string,
other?: Other<
'stopMessageLiveLocation',
'message_id' | 'inline_message_id'
>,
signal?: AbortSignal
) {
return this.raw.stopMessageLiveLocation(
{ inline_message_id, ...other },
signal
)
}
/**
* Use this method to send information about a venue. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param latitude Latitude of the venue
* @param longitude Longitude of the venue
* @param title Name of the venue
* @param address Address of the venue
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendvenue
*/
sendVenue(
chat_id: number | string,
latitude: number,
longitude: number,
title: string,
address: string,
other?: Other<
'sendVenue',
'latitude' | 'longitude' | 'title' | 'address'
>,
signal?: AbortSignal
) {
return this.raw.sendVenue(
{
chat_id,
latitude,
longitude,
title,
address,
...other,
},
signal
)
}
/**
* Use this method to send phone contacts. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param phone_number Contact's phone number
* @param first_name Contact's first name
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendcontact
*/
sendContact(
chat_id: number | string,
phone_number: string,
first_name: string,
other?: Other<'sendContact', 'phone_number' | 'first_name'>,
signal?: AbortSignal
) {
return this.raw.sendContact(
{
chat_id,
phone_number,
first_name,
...other,
},
signal
)
}
/**
* Use this method to send a native poll. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param question Poll question, 1-300 characters
* @param options A list of answer options, 2-10 strings 1-100 characters each
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendpoll
*/
sendPoll(
chat_id: number | string,
question: string,
options: readonly string[],
other?: Other<'sendPoll', 'question' | 'options'>,
signal?: AbortSignal
) {
return this.raw.sendPoll(
{ chat_id, question, options, ...other },
signal
)
}
/**
* Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#senddice
*/
sendDice(
chat_id: number | string,
emoji: string,
other?: Other<'sendDice', 'emoji'>,
signal?: AbortSignal
) {
return this.raw.sendDice({ chat_id, emoji, ...other }, signal)
}
/**
* Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
*
* Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.
*
* We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, find_location for location data, record_video_note or upload_video_note for video notes.
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#sendchataction
*/
sendChatAction(
chat_id: number | string,
action:
| 'typing'
| 'upload_photo'
| 'record_video'
| 'upload_video'
| 'record_voice'
| 'upload_voice'
| 'upload_document'
| 'find_location'
| 'record_video_note'
| 'upload_video_note',
signal?: AbortSignal
) {
return this.raw.sendChatAction({ chat_id, action }, signal)
}
/**
* Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
*
* @param user_id Unique identifier of the target user
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#getuserprofilephotos
*/
getUserProfilePhotos(
user_id: number,
other?: Other<'getUserProfilePhotos', 'user_id'>,
signal?: AbortSignal
) {
return this.raw.getUserProfilePhotos({ user_id, ...other }, signal)
}
/**
* Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
*
* Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.
*
* @param file_id File identifier to get info about
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#getfile
*/
getFile(file_id: string, signal?: AbortSignal) {
return this.raw.getFile({ file_id }, signal)
}
/**
* Use this method to kick a user from 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 admin rights. Returns True on success.
*
* @param chat_id Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
* @param user_id Unique identifier of the target user
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#kickchatmember
*/
kickChatMember(
chat_id: number | string,
user_id: number,
other?: Other<'kickChatMember', 'user_id'>,
signal?: AbortSignal
) {
return this.raw.kickChatMember({ chat_id, user_id, ...other }, signal)
}
/**
* Use this method to unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don't want this, use the parameter only_if_banned. Returns True on success.
*
* @param chat_id Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
* @param user_id Unique identifier of the target user
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#unbanchatmember
*/
unbanChatMember(
chat_id: number | string,
user_id: number,
other?: Other<'unbanChatMember', 'user_id'>,
signal?: AbortSignal
) {
return this.raw.unbanChatMember({ chat_id, user_id, ...other }, signal)
}
/**
* Use this method to restrict 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. Pass True for all permissions to lift restrictions from a user. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
* @param user_id Unique identifier of the target user
* @param permissions An object for new user permissions
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#restrictchatmember
*/
restrictChatMember(
chat_id: number | string,
user_id: number,
permissions: ChatPermissions,
other?: Other<'restrictChatMember', 'user_id' | 'permissions'>,
signal?: AbortSignal
) {
return this.raw.restrictChatMember(
{
chat_id,
user_id,
permissions,
...other,
},
signal
)
}
/**
* Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param user_id Unique identifier of the target user
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#promotechatmember
*/
promoteChatMember(
chat_id: number | string,
user_id: number,
other?: Other<'promoteChatMember', 'user_id'>,
signal?: AbortSignal
) {
return this.raw.promoteChatMember(
{ chat_id, user_id, ...other },
signal
)
}
/**
* Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
* @param user_id Unique identifier of the target user
* @param custom_title New custom title for the administrator; 0-16 characters, emoji are not allowed
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#setchatadministratorcustomtitle
*/
setChatAdministratorCustomTitle(
chat_id: number | string,
user_id: number,
custom_title: string,
signal?: AbortSignal
) {
return this.raw.setChatAdministratorCustomTitle(
{
chat_id,
user_id,
custom_title,
},
signal
)
}
/**
* Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
* @param permissions New default chat permissions
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#setchatpermissions
*/
setChatPermissions(
chat_id: number | string,
permissions: ChatPermissions,
signal?: AbortSignal
) {
return this.raw.setChatPermissions({ chat_id, permissions }, signal)
}
/**
* Use this method to generate a new primary invite link for a chat; any previously generated primary 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.
*
* Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink or by calling the getChat method. If your bot needs to generate a new primary invite link replacing its previous one, use exportChatInviteLink again.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#exportchatinvitelink
*/
exportChatInviteLink(chat_id: number | string, signal?: AbortSignal) {
return this.raw.exportChatInviteLink({ chat_id }, signal)
}
/**
* 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 admin rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#createchatinvitelink
*/
createChatInviteLink(
chat_id: number | string,
other?: Other<'createChatInviteLink'>,
signal?: AbortSignal
) {
return this.raw.createChatInviteLink({ chat_id, ...other }, signal)
}
/**
* Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the edited invite link as a ChatInviteLink object.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param invite_link The invite link to edit
* @param other Remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#editchatinvitelink
*/
editChatInviteLink(
chat_id: number | string,
invite_link: string,
other?: Other<'editChatInviteLink', 'invite_link'>,
signal?: AbortSignal
) {
return this.raw.editChatInviteLink(
{ chat_id, invite_link, ...other },
signal
)
}
/**
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the revoked invite link as ChatInviteLink object.
*
* @param chat_id Unique identifier of the target chat or username of the target channel (in the format @channelusername)
* @param invite_link The invite link to revoke
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#revokechatinvitelink
*/
revokeChatInviteLink(
chat_id: number | string,
invite_link: string,
signal?: AbortSignal
) {
return this.raw.revokeChatInviteLink({ chat_id, invite_link }, signal)
}
/**
* Use this method to set a new profile photo for the chat. 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 admin rights. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param photo New chat photo, uploaded using multipart/form-data
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#setchatphoto
*/
setChatPhoto(
chat_id: number | string,
photo: InputFile,
signal?: AbortSignal
) {
return this.raw.setChatPhoto({ chat_id, photo }, signal)
}
/**
* 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 admin rights. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#deletechatphoto
*/
deleteChatPhoto(chat_id: number | string, signal?: AbortSignal) {
return this.raw.deleteChatPhoto({ chat_id }, signal)
}
/**
* Use this method to change the title of a chat. Titles 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 admin rights. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param title New chat title, 1-255 characters
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#setchattitle
*/
setChatTitle(
chat_id: number | string,
title: string,
signal?: AbortSignal