@aracna/telegram-bot 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/builders/button.builder.js +31 -0
  4. package/childs/add.js +10 -0
  5. package/childs/answer.js +19 -0
  6. package/childs/ban.js +10 -0
  7. package/childs/create.js +17 -0
  8. package/childs/delete.js +19 -0
  9. package/childs/download.js +32 -0
  10. package/childs/edit.js +22 -0
  11. package/childs/export.js +10 -0
  12. package/childs/forward.js +15 -0
  13. package/childs/get.js +37 -0
  14. package/childs/leave.js +10 -0
  15. package/childs/pin.js +10 -0
  16. package/childs/polling.js +34 -0
  17. package/childs/privates/send.private.js +19 -0
  18. package/childs/promote.js +10 -0
  19. package/childs/restrict.js +15 -0
  20. package/childs/send.js +130 -0
  21. package/childs/set.js +44 -0
  22. package/childs/stop.js +13 -0
  23. package/childs/unban.js +10 -0
  24. package/childs/unpin.js +10 -0
  25. package/childs/upload.js +10 -0
  26. package/childs/webhook.js +22 -0
  27. package/declarations/builders/button.builder.d.ts +11 -0
  28. package/declarations/childs/add.d.ts +6 -0
  29. package/declarations/childs/answer.d.ts +9 -0
  30. package/declarations/childs/ban.d.ts +6 -0
  31. package/declarations/childs/create.d.ts +6 -0
  32. package/declarations/childs/delete.d.ts +8 -0
  33. package/declarations/childs/download.d.ts +9 -0
  34. package/declarations/childs/edit.d.ts +10 -0
  35. package/declarations/childs/export.d.ts +5 -0
  36. package/declarations/childs/forward.d.ts +6 -0
  37. package/declarations/childs/get.d.ts +15 -0
  38. package/declarations/childs/leave.d.ts +5 -0
  39. package/declarations/childs/pin.d.ts +6 -0
  40. package/declarations/childs/polling.d.ts +9 -0
  41. package/declarations/childs/privates/send.private.d.ts +7 -0
  42. package/declarations/childs/promote.d.ts +6 -0
  43. package/declarations/childs/restrict.d.ts +6 -0
  44. package/declarations/childs/send.d.ts +31 -0
  45. package/declarations/childs/set.d.ts +17 -0
  46. package/declarations/childs/stop.d.ts +7 -0
  47. package/declarations/childs/unban.d.ts +5 -0
  48. package/declarations/childs/unpin.d.ts +5 -0
  49. package/declarations/childs/upload.d.ts +7 -0
  50. package/declarations/childs/webhook.d.ts +8 -0
  51. package/declarations/definitions/constants.d.ts +2 -0
  52. package/declarations/definitions/enums.d.ts +22 -0
  53. package/declarations/definitions/interfaces.d.ts +97 -0
  54. package/declarations/definitions/types.d.ts +4 -0
  55. package/declarations/index.d.ts +12 -0
  56. package/declarations/loggers/module.logger.d.ts +2 -0
  57. package/declarations/modules/api.d.ts +5 -0
  58. package/declarations/modules/builder.d.ts +4 -0
  59. package/declarations/modules/child.d.ts +5 -0
  60. package/declarations/modules/configuration.d.ts +8 -0
  61. package/declarations/modules/dummy.d.ts +9 -0
  62. package/declarations/modules/telegram.d.ts +87 -0
  63. package/declarations/utils/callback.query.utils.d.ts +5 -0
  64. package/declarations/utils/command.utils.d.ts +8 -0
  65. package/declarations/utils/context.utils.d.ts +13 -0
  66. package/declarations/utils/html.utils.d.ts +5 -0
  67. package/declarations/utils/inline.keyboard.utils.d.ts +4 -0
  68. package/declarations/utils/reply.to.message.utils.d.ts +6 -0
  69. package/declarations/utils/start.utils.d.ts +7 -0
  70. package/definitions/constants.js +11 -0
  71. package/definitions/enums.js +27 -0
  72. package/definitions/interfaces.js +3 -0
  73. package/definitions/types.js +2 -0
  74. package/index.d.ts +498 -0
  75. package/index.js +24 -0
  76. package/loggers/module.logger.js +6 -0
  77. package/modules/api.js +26 -0
  78. package/modules/builder.js +8 -0
  79. package/modules/child.js +10 -0
  80. package/modules/configuration.js +10 -0
  81. package/modules/dummy.js +56 -0
  82. package/modules/telegram.js +353 -0
  83. package/package.json +28 -0
  84. package/utils/callback.query.utils.js +26 -0
  85. package/utils/command.utils.js +29 -0
  86. package/utils/context.utils.js +43 -0
  87. package/utils/html.utils.js +20 -0
  88. package/utils/inline.keyboard.utils.js +26 -0
  89. package/utils/reply.to.message.utils.js +27 -0
  90. package/utils/start.utils.js +32 -0
package/index.d.ts ADDED
@@ -0,0 +1,498 @@
1
+ /// <reference types="node" />
2
+
3
+ import { AddStickerToSet } from '@aracna/telegram-bot-types';
4
+ import { AnswerCallbackQuery } from '@aracna/telegram-bot-types';
5
+ import { AnswerInlineQuery } from '@aracna/telegram-bot-types';
6
+ import { AnswerPreCheckoutQuery } from '@aracna/telegram-bot-types';
7
+ import { AnswerShippingQuery } from '@aracna/telegram-bot-types';
8
+ import { API as API_2 } from '@aracna/core';
9
+ import { APIConfig } from '@aracna/core';
10
+ import { BanChatMember } from '@aracna/telegram-bot-types';
11
+ import { BotCommand } from '@aracna/telegram-bot-types';
12
+ import { CallbackQuery as CallbackQuery_2 } from '@aracna/telegram-bot-types';
13
+ import { Chat } from '@aracna/telegram-bot-types';
14
+ import { ChatJoinRequest } from '@aracna/telegram-bot-types';
15
+ import { ChatMember } from '@aracna/telegram-bot-types';
16
+ import { ChatMemberUpdated } from '@aracna/telegram-bot-types';
17
+ import { ChatPermissions } from '@aracna/telegram-bot-types';
18
+ import { ChosenInlineResult } from '@aracna/telegram-bot-types';
19
+ import { Context as Context_2 } from 'vm';
20
+ import { CreateNewStickerSet } from '@aracna/telegram-bot-types';
21
+ import { EditMessageCaption } from '@aracna/telegram-bot-types';
22
+ import { EditMessageLiveLocation } from '@aracna/telegram-bot-types';
23
+ import { EditMessageMedia } from '@aracna/telegram-bot-types';
24
+ import { EditMessageReplyMarkup } from '@aracna/telegram-bot-types';
25
+ import { EditMessageText } from '@aracna/telegram-bot-types';
26
+ import { FetchError } from '@aracna/core';
27
+ import { File as File_2 } from '@aracna/telegram-bot-types';
28
+ import { ForwardMessage } from '@aracna/telegram-bot-types';
29
+ import { GameHighScore } from '@aracna/telegram-bot-types';
30
+ import { GetGameHighScores } from '@aracna/telegram-bot-types';
31
+ import { GetUpdates } from '@aracna/telegram-bot-types';
32
+ import { GetUserProfilePhotos } from '@aracna/telegram-bot-types';
33
+ import { InlineKeyboardButton } from '@aracna/telegram-bot-types';
34
+ import { InlineQuery } from '@aracna/telegram-bot-types';
35
+ import { InlineQueryResult } from '@aracna/telegram-bot-types';
36
+ import { InputMedia } from '@aracna/telegram-bot-types';
37
+ import { InputMediaAudio } from '@aracna/telegram-bot-types';
38
+ import { InputMediaDocument } from '@aracna/telegram-bot-types';
39
+ import { InputMediaPhoto } from '@aracna/telegram-bot-types';
40
+ import { InputMediaVideo } from '@aracna/telegram-bot-types';
41
+ import { InputSticker } from '@aracna/telegram-bot-types';
42
+ import { LabeledPrice } from '@aracna/telegram-bot-types';
43
+ import { LoginUrl } from '@aracna/telegram-bot-types';
44
+ import { Message } from '@aracna/telegram-bot-types';
45
+ import { MessageEntity } from '@aracna/telegram-bot-types';
46
+ import { PassportElementError } from '@aracna/telegram-bot-types';
47
+ import { PinChatMessage } from '@aracna/telegram-bot-types';
48
+ import { Poll } from '@aracna/telegram-bot-types';
49
+ import { PollAnswer } from '@aracna/telegram-bot-types';
50
+ import { PreCheckoutQuery } from '@aracna/telegram-bot-types';
51
+ import { PromoteChatMember } from '@aracna/telegram-bot-types';
52
+ import { RequestMethod } from '@aracna/core';
53
+ import { RestrictChatMember } from '@aracna/telegram-bot-types';
54
+ import { SendAnimation } from '@aracna/telegram-bot-types';
55
+ import { SendAudio } from '@aracna/telegram-bot-types';
56
+ import { SendContact } from '@aracna/telegram-bot-types';
57
+ import { SendDice } from '@aracna/telegram-bot-types';
58
+ import { SendDocument } from '@aracna/telegram-bot-types';
59
+ import { SendGame } from '@aracna/telegram-bot-types';
60
+ import { SendInvoice } from '@aracna/telegram-bot-types';
61
+ import { SendLocation } from '@aracna/telegram-bot-types';
62
+ import { SendMediaGroup } from '@aracna/telegram-bot-types';
63
+ import { SendMessage } from '@aracna/telegram-bot-types';
64
+ import { SendPhoto } from '@aracna/telegram-bot-types';
65
+ import { SendPoll } from '@aracna/telegram-bot-types';
66
+ import { SendSticker } from '@aracna/telegram-bot-types';
67
+ import { SendVenue } from '@aracna/telegram-bot-types';
68
+ import { SendVideo } from '@aracna/telegram-bot-types';
69
+ import { SendVideoNote } from '@aracna/telegram-bot-types';
70
+ import { SendVoice } from '@aracna/telegram-bot-types';
71
+ import { SetGameScore } from '@aracna/telegram-bot-types';
72
+ import { SetMyCommands } from '@aracna/telegram-bot-types';
73
+ import { SetStickerSetThumbnail } from '@aracna/telegram-bot-types';
74
+ import { SetWebhook } from '@aracna/telegram-bot-types';
75
+ import { ShippingQuery } from '@aracna/telegram-bot-types';
76
+ import { StickerSet } from '@aracna/telegram-bot-types';
77
+ import { StopMessageLiveLocation } from '@aracna/telegram-bot-types';
78
+ import { StopPoll } from '@aracna/telegram-bot-types';
79
+ import { Update } from '@aracna/telegram-bot-types';
80
+ import { User } from '@aracna/telegram-bot-types';
81
+ import { UserProfilePhotos } from '@aracna/telegram-bot-types';
82
+
83
+ declare class _ {
84
+ api: ConfigurationAPI;
85
+ default: ConfigurationDefault;
86
+ handler: ConfigurationHandler;
87
+ }
88
+
89
+ declare class Add extends Child {
90
+ stickerToSet(userID: number, name: string, sticker: InputSticker, parameters: Partial<AddStickerToSet>): Promise<Message | FetchError>;
91
+ }
92
+
93
+ declare class Answer extends Child {
94
+ callbackQuery(id: string, parameters?: Partial<AnswerCallbackQuery>): Promise<boolean | FetchError>;
95
+ inlineQuery(id: string, results: InlineQueryResult[], parameters?: Partial<AnswerInlineQuery>): Promise<boolean | FetchError>;
96
+ preCheckoutQuery(id: string, ok: boolean, parameters?: Partial<AnswerPreCheckoutQuery>): Promise<boolean | FetchError>;
97
+ shippingQuery(id: string, ok: boolean, parameters?: Partial<AnswerShippingQuery>): Promise<boolean | FetchError>;
98
+ }
99
+
100
+ declare class API extends API_2 {
101
+ post<V, W, X = undefined>(path: string, body?: W, config?: APIConfig<void>): Promise<V | FetchError<X>>;
102
+ transformBody<V>(method: RequestMethod, path: string, body: V, config: APIConfig<void>): Promise<FormData>;
103
+ }
104
+
105
+ declare class Ban extends Child {
106
+ chatMember(chatID: number, userID: number, parameters?: Partial<BanChatMember>): Promise<boolean | FetchError>;
107
+ }
108
+
109
+ declare class Builder {
110
+ button: ButtonBuilder;
111
+ }
112
+
113
+ declare class ButtonBuilder {
114
+ callback<T>(text: string, data: T, type: string, chatID?: number): InlineKeyboardButton;
115
+ game(text: string, game: string): InlineKeyboardButton;
116
+ login(text: string, url: string, fields?: Partial<LoginUrl>): InlineKeyboardButton;
117
+ pay(text: string): InlineKeyboardButton;
118
+ query(text: string, query: string): InlineKeyboardButton;
119
+ queryCurrentChat(text: string, query: string): InlineKeyboardButton;
120
+ text(text: string): InlineKeyboardButton;
121
+ url(text: string, url: string): InlineKeyboardButton;
122
+ }
123
+
124
+ export declare interface CallbackQuery<T = any> extends CallbackQuery_2 {
125
+ body: CallbackQueryBody<T>;
126
+ }
127
+
128
+ export declare interface CallbackQueryBody<T = any> {
129
+ c?: number;
130
+ d: T;
131
+ t: string;
132
+ }
133
+
134
+ export declare class CallbackQueryUtils {
135
+ static decodeBody<T>(data?: string): CallbackQueryBody<T>;
136
+ static encodeBody<T>(data: T, type: string, chatID?: number): string;
137
+ }
138
+
139
+ declare class Child {
140
+ protected telegram: Telegram;
141
+ constructor(telegram: Telegram);
142
+ }
143
+
144
+ export declare class CommandUtils {
145
+ static getByContext<T extends UpdateType>(context: Context_2[T]): string;
146
+ static get(string?: string): string;
147
+ static omit(string: string): string;
148
+ }
149
+
150
+ declare interface ConfigurationAPI {
151
+ post: {
152
+ callback: {
153
+ success: <T, U>(body: T, result: U | Error) => void;
154
+ };
155
+ };
156
+ }
157
+
158
+ declare interface ConfigurationDefault {
159
+ buttons: {
160
+ text: (chatID: number) => Promise<InlineKeyboardButton[]>;
161
+ url: (chatID: number) => Promise<InlineKeyboardButton[]>;
162
+ login: (chatID: number) => Promise<InlineKeyboardButton[]>;
163
+ callback: (chatID: number) => Promise<InlineKeyboardButton[]>;
164
+ query: (chatID: number) => Promise<InlineKeyboardButton[]>;
165
+ queryCurrentChat: (chatID: number) => Promise<InlineKeyboardButton[]>;
166
+ game: (chatID: number) => Promise<InlineKeyboardButton[]>;
167
+ pay: (chatID: number) => Promise<InlineKeyboardButton[]>;
168
+ };
169
+ }
170
+
171
+ declare interface ConfigurationHandler {
172
+ send: {
173
+ buttons: {
174
+ empty: (chatID: number) => Error;
175
+ };
176
+ };
177
+ }
178
+
179
+ export declare interface Context {
180
+ [UpdateType.CALLBACK_QUERY]: CallbackQuery;
181
+ [UpdateType.CHANNEL_POST]: Message;
182
+ [UpdateType.CHAT_JOIN_REQUEST]: ChatJoinRequest;
183
+ [UpdateType.CHAT_MEMBER]: ChatMemberUpdated;
184
+ [UpdateType.CHOSEN_INLINE_RESULT]: ChosenInlineResult;
185
+ [UpdateType.DOCUMENT]: Message;
186
+ [UpdateType.EDITED_CHANNEL_POST]: Message;
187
+ [UpdateType.EDITED_MESSAGE]: Message;
188
+ [UpdateType.INLINE_QUERY]: InlineQuery;
189
+ [UpdateType.MESSAGE]: Message;
190
+ [UpdateType.MY_CHAT_MEMBER]: ChatMemberUpdated;
191
+ [UpdateType.POLL]: Poll;
192
+ [UpdateType.POLL_ANSWER]: PollAnswer;
193
+ [UpdateType.PRE_CHECKOUT_QUERY]: PreCheckoutQuery;
194
+ [UpdateType.REPLY_TO_MESSAGE]: ReplyToMessage;
195
+ [UpdateType.SHIPPING_QUERY]: ShippingQuery;
196
+ [UpdateType.START]: Start;
197
+ }
198
+
199
+ export declare class ContextUtils {
200
+ static getChatID<T extends UpdateType>(context: Context[T]): number;
201
+ static getChatType<T extends UpdateType>(context: Context[T]): string;
202
+ static getChat<T extends UpdateType>(context: Context[T]): Chat;
203
+ static getUserID<T extends UpdateType>(context: Context[T]): number;
204
+ static getUserFirstName<T extends UpdateType>(context: Context[T]): string;
205
+ static getUserLastName<T extends UpdateType>(context: Context[T]): string;
206
+ static getUserUsername<T extends UpdateType>(context: Context[T]): string;
207
+ static getUser<T extends UpdateType>(context: Context[T]): User;
208
+ }
209
+
210
+ declare class Create extends Child {
211
+ stickerSet(userID: number, format: string, name: string, title: string, stickers: InputSticker[], parameters: Partial<CreateNewStickerSet>): Promise<boolean | FetchError>;
212
+ }
213
+
214
+ declare class Delete extends Child {
215
+ chatPhoto(chatID: number): Promise<boolean | FetchError>;
216
+ chatStickerSet(chatID: number): Promise<boolean | FetchError>;
217
+ message(chatID: number, message: number): Promise<boolean | FetchError>;
218
+ stickerFromSet(sticker: string): Promise<boolean | FetchError>;
219
+ }
220
+
221
+ declare class Download extends Child {
222
+ api: API;
223
+ file(id: string): Promise<Buffer | FetchError>;
224
+ userFirstProfilePhoto(id: number): Promise<Buffer | FetchError | Error>;
225
+ }
226
+
227
+ declare class Edit extends Child {
228
+ messageCaption(parameters: EditMessageCaption): Promise<Message | FetchError>;
229
+ messageLiveLocation(latitude: number, longitude: number, parameters: Partial<EditMessageLiveLocation>): Promise<Message | FetchError>;
230
+ messageMedia(media: InputMedia, parameters: Partial<EditMessageMedia>): Promise<Message | FetchError>;
231
+ messageReplyMarkup(parameters: EditMessageReplyMarkup): Promise<Message | FetchError>;
232
+ messageText(text: string, parameters: Partial<EditMessageText>): Promise<Message | FetchError>;
233
+ }
234
+
235
+ declare class Export extends Child {
236
+ chatInviteLink(chatID: number): Promise<string | FetchError>;
237
+ }
238
+
239
+ declare class Forward extends Child {
240
+ message(chatID: number, fromChatID: number, messageID: number, parameters?: Partial<ForwardMessage>): Promise<Message | FetchError>;
241
+ }
242
+
243
+ declare class Get extends Child {
244
+ chat(id: number): Promise<Chat | FetchError>;
245
+ chatAdministrators(id: number): Promise<ChatMember[] | FetchError>;
246
+ chatMember(chatID: number, userID: number): Promise<ChatMember | FetchError>;
247
+ chatMemberCount(id: number): Promise<number | FetchError>;
248
+ commands(): Promise<BotCommand[] | FetchError>;
249
+ file(id: string): Promise<File_2 | FetchError>;
250
+ gameHighScores(userID: number, parameters?: Partial<GetGameHighScores>): Promise<GameHighScore | FetchError>;
251
+ me(): Promise<User | FetchError>;
252
+ stickerSet(name: string): Promise<StickerSet | FetchError>;
253
+ userProfilePhotos(id: number, parameters?: Partial<GetUserProfilePhotos>): Promise<UserProfilePhotos | FetchError>;
254
+ }
255
+
256
+ export declare interface Handler<T extends UpdateType = any, U extends HandlerOptions = HandlerOptions> {
257
+ description?: string;
258
+ id: string;
259
+ key?: string;
260
+ middleware: HandlerMiddleware<T>;
261
+ options: U;
262
+ type: UpdateType;
263
+ }
264
+
265
+ export declare type HandlerMiddleware<T extends UpdateType> = (context: Context[T]) => any;
266
+
267
+ export declare interface HandlerOptions {
268
+ deleteOnCallbackQuery?: boolean;
269
+ deleteOnReply?: boolean;
270
+ deleteOnMessageStart?: boolean;
271
+ }
272
+
273
+ export declare class HTMLUtils {
274
+ static tags: string[];
275
+ static sanitize(text: string): string;
276
+ static progress(value: number, minimum?: number, maximum?: number, size?: number): string;
277
+ }
278
+
279
+ export declare class InlineKeyboardUtils {
280
+ static getButtonsType(buttons: InlineKeyboardButton[]): string;
281
+ }
282
+
283
+ export declare type InputFile = File | string;
284
+
285
+ declare interface InputMediaAlternative extends Omit<InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo, 'media'> {
286
+ media: InputFile;
287
+ }
288
+
289
+ declare class Leave extends Child {
290
+ chat(id: number): Promise<boolean | FetchError>;
291
+ }
292
+
293
+ export declare interface MessageBody<T = any> {
294
+ chatID?: number;
295
+ data: T;
296
+ type: string;
297
+ }
298
+
299
+ declare class Pin extends Child {
300
+ chatMessage(chatID: number, message: number, parameters?: Partial<PinChatMessage>): Promise<boolean | FetchError>;
301
+ }
302
+
303
+ declare class Polling extends Child {
304
+ active: boolean;
305
+ offset: number;
306
+ start(ms: number | undefined, parameters: Partial<GetUpdates>): void;
307
+ stop(): void;
308
+ private get;
309
+ }
310
+
311
+ declare class Promote extends Child {
312
+ chatMember(chatID: number, userID: number, parameters?: Partial<PromoteChatMember>): Promise<boolean | FetchError>;
313
+ }
314
+
315
+ export declare interface ReplyToMessage<T = any> extends Message {
316
+ body: MessageBody<T>;
317
+ }
318
+
319
+ export declare class ReplyToMessageUtils {
320
+ static decodeBody<T>(entities: MessageEntity[]): MessageBody<T>;
321
+ static encodeBody<T>(data: T, type: string, chatID?: number): string;
322
+ }
323
+
324
+ declare class Restrict extends Child {
325
+ chatMember(chatID: number, userID: number, permissions: ChatPermissions, parameters?: Partial<RestrictChatMember>): Promise<boolean | FetchError>;
326
+ }
327
+
328
+ declare class Send extends Child {
329
+ private: SendPrivate;
330
+ animation(chatID: number, file: InputFile, parameters?: Partial<SendAnimation>): Promise<Message | FetchError>;
331
+ audio(chatID: number, file: InputFile, parameters?: Partial<SendAudio>): Promise<Message | FetchError>;
332
+ document(chatID: number, file: InputFile, parameters?: Partial<SendDocument>): Promise<Message | FetchError>;
333
+ buttons(chatID: number, text: string, buttons: InlineKeyboardButton[], parameters?: Partial<SendMessage>): Promise<Message | FetchError | Error>;
334
+ chatAction(chatID: number, action: string): Promise<boolean | FetchError>;
335
+ contact(chatID: number, phoneNumber: string, firstName: string, parameters?: Partial<SendContact>): Promise<Message | FetchError>;
336
+ dice(chatID: number, parameters?: Partial<SendDice>): Promise<Message | FetchError>;
337
+ game(chatID: number, gameShortName: string, parameters?: Partial<SendGame>): Promise<Message | FetchError>;
338
+ html(chatID: number, text: string, parameters?: Partial<SendMessage>): Promise<Message | FetchError>;
339
+ invoice(chatID: number, title: string, description: string, payload: string, providerToken: string, startParameter: string, currency: string, prices: LabeledPrice[], parameters?: Partial<SendInvoice>): Promise<Message | FetchError>;
340
+ location(chatID: number, latitude: number, longitude: number, parameters?: Partial<SendLocation>): Promise<Message | FetchError>;
341
+ mediaGroup(chatID: number, media: InputMediaAlternative[], parameters?: Partial<SendMediaGroup>): Promise<Message | FetchError>;
342
+ message(chatID: number, text: string, parameters?: Partial<SendMessage>): Promise<Message | FetchError>;
343
+ photo(chatID: number, file: InputFile, parameters?: Partial<SendPhoto>): Promise<Message | FetchError>;
344
+ poll(chatID: number, question: string, options: string[], parameters?: Partial<SendPoll>): Promise<Message | FetchError>;
345
+ repliable<T>(chatID: number, text: string, data: T, type: string, parameters?: Partial<SendMessage>, fromChatID?: number): Promise<Message | FetchError>;
346
+ sticker(chatID: number, file: InputFile, parameters?: Partial<SendSticker>): Promise<Message | FetchError>;
347
+ venue(chatID: number, latitude: number, longitude: number, title: string, address: string, parameters?: Partial<SendVenue>): Promise<Message | FetchError>;
348
+ video(chatID: number, file: InputFile, parameters?: Partial<SendVideo>): Promise<Message | FetchError>;
349
+ videoNote(chatID: number, file: InputFile, parameters?: Partial<SendVideoNote>): Promise<Message | FetchError>;
350
+ voice(chatID: number, file: InputFile, parameters?: Partial<SendVoice>): Promise<Message | FetchError>;
351
+ private file;
352
+ }
353
+
354
+ declare class SendPrivate extends Child {
355
+ buttons(chatIDs: [number, number], text: string, buttons: InlineKeyboardButton[], parameters?: Partial<SendMessage>): Promise<Message | FetchError | Error>;
356
+ repliable<T>(chatIDs: [number, number], text: string, data: T, type: string, parameters?: Partial<SendMessage>): Promise<Message | FetchError | Error>;
357
+ }
358
+
359
+ declare class Set_2 extends Child {
360
+ chatAdministratorCustomTitle(chatID: number, userID: number, customTitle: string): Promise<boolean | FetchError>;
361
+ chatDescription(chatID: number, description: string): Promise<boolean | FetchError>;
362
+ chatPermissions(chatID: number, permissions: ChatPermissions): Promise<boolean | FetchError>;
363
+ chatPhoto(chatID: number, photo: InputFile): Promise<boolean | FetchError>;
364
+ chatStickerSet(chatID: number, stickerSetName: string): Promise<boolean | FetchError>;
365
+ chatTitle(chatID: number, title: string): Promise<boolean | FetchError>;
366
+ commands(commands: BotCommand[], parameters?: Partial<SetMyCommands>): Promise<boolean | FetchError>;
367
+ gameScore(userID: number, score: number, parameters?: Partial<SetGameScore>): Promise<boolean | FetchError>;
368
+ passportDataErrors(userID: number, errors: PassportElementError[]): Promise<boolean | FetchError>;
369
+ stickerPositionInSet(sticker: string, position: number): Promise<boolean | FetchError>;
370
+ stickerSetThumb(name: string, userID: number, parameters?: Partial<SetStickerSetThumbnail>): Promise<boolean | FetchError>;
371
+ }
372
+
373
+ export declare interface Start<T = any> extends Message {
374
+ body: MessageBody<T>;
375
+ }
376
+
377
+ export declare class StartUtils {
378
+ static decodeBody<T>(text?: string): MessageBody<T>;
379
+ static encodeBody<T>(data: T, type: string, chatID?: number): string;
380
+ static encodeBodyToHREF<T>(username: string, data: T, type: string, chatID?: number): string;
381
+ static encodeBodyToAnchorTag<T>(username: string, data: T, type: string, children: string, chatID?: number): string;
382
+ }
383
+
384
+ declare class Stop extends Child {
385
+ messageLiveLocation(parameters: StopMessageLiveLocation): Promise<Message | boolean | FetchError>;
386
+ poll(chatID: number, message: number, parameters?: Partial<StopPoll>): Promise<Poll | FetchError>;
387
+ }
388
+
389
+ export declare class Telegram {
390
+ /** INTERNAL */
391
+ api: API;
392
+ handlers: Handler[];
393
+ hostname: string;
394
+ id: number;
395
+ name: TelegramName;
396
+ port: number;
397
+ token: string;
398
+ username: string;
399
+ /** BUILDERS */
400
+ builder: Builder;
401
+ /** CHILDS */
402
+ add: Add;
403
+ answer: Answer;
404
+ create: Create;
405
+ delete: Delete;
406
+ download: Download;
407
+ edit: Edit;
408
+ export: Export;
409
+ forward: Forward;
410
+ get: Get;
411
+ ban: Ban;
412
+ leave: Leave;
413
+ pin: Pin;
414
+ polling: Polling;
415
+ promote: Promote;
416
+ restrict: Restrict;
417
+ send: Send;
418
+ set: Set_2;
419
+ stop: Stop;
420
+ unban: Unban;
421
+ unpin: Unpin;
422
+ upload: Upload;
423
+ webhook: Webhook;
424
+ constructor(token: string, hostname?: string, port?: number);
425
+ on<T extends UpdateType, U extends HandlerOptions>(type: T, middleware: HandlerMiddleware<T>, key?: string, description?: string, options?: U): void;
426
+ handle(update: Update): void;
427
+ handleCallbackQuery(query: CallbackQuery_2): Handler;
428
+ handleChannelPost(post: Message): Handler;
429
+ handleChatJoinRequest(request: ChatJoinRequest): Handler;
430
+ handleChatMember(member: ChatMemberUpdated): Handler;
431
+ handleChosenInlineResult(result: ChosenInlineResult): Handler;
432
+ handleDocument(document: Message): Handler;
433
+ handleEditedChannelPost(post: Message): Handler;
434
+ handleEditedMessage(message: Message): Handler;
435
+ handleInlineQuery(query: InlineQuery): Handler;
436
+ handleMessage(message: Message): Handler;
437
+ handleMyChatMember(member: ChatMemberUpdated): Handler;
438
+ handlePoll(poll: Poll): Handler;
439
+ handlePollAnswer(answer: PollAnswer): Handler;
440
+ handlePreCheckoutQuery(query: PreCheckoutQuery): Handler;
441
+ handleReplyToMessage(reply: Message): Handler;
442
+ handleShippingQuery(query: ShippingQuery): Handler;
443
+ handleStart(start: Message): Handler;
444
+ private findMatchingHandler;
445
+ get commands(): BotCommand[];
446
+ private get handlerIDs();
447
+ }
448
+
449
+ export declare const TelegramConfiguration: _;
450
+
451
+ export declare enum TelegramLoggerName {
452
+ MODULE = "TELEGRAM_MODULE"
453
+ }
454
+
455
+ declare interface TelegramName {
456
+ first: string;
457
+ last: string;
458
+ }
459
+
460
+ declare class Unban extends Child {
461
+ chatMember(chatID: number, userID: number): Promise<boolean | FetchError>;
462
+ }
463
+
464
+ declare class Unpin extends Child {
465
+ chatMessage(chatID: number): Promise<boolean | FetchError>;
466
+ }
467
+
468
+ export declare enum UpdateType {
469
+ CALLBACK_QUERY = "CALLBACK_QUERY",
470
+ CHANNEL_POST = "CHANNEL_POST",
471
+ CHAT_JOIN_REQUEST = "CHAT_JOIN_REQUEST",
472
+ CHAT_MEMBER = "CHAT_MEMBER",
473
+ CHOSEN_INLINE_RESULT = "CHOSEN_INLINE_RESULT",
474
+ DOCUMENT = "DOCUMENT",
475
+ EDITED_CHANNEL_POST = "EDITED_CHANNEL_POST",
476
+ EDITED_MESSAGE = "EDITED_MESSAGE",
477
+ INLINE_QUERY = "INLINE_QUERY",
478
+ MESSAGE = "MESSAGE",
479
+ MY_CHAT_MEMBER = "MY_CHAT_MEMBER",
480
+ POLL = "POLL",
481
+ POLL_ANSWER = "POLL_ANSWER",
482
+ PRE_CHECKOUT_QUERY = "PRE_CHECKOUT_QUERY",
483
+ REPLY_TO_MESSAGE = "REPLY_TO_MESSAGE",
484
+ SHIPPING_QUERY = "SHIPPING_QUERY",
485
+ START = "START"
486
+ }
487
+
488
+ declare class Upload extends Child {
489
+ stickerFile(userID: number, format: string, sticker: InputFile): Promise<File_2 | FetchError>;
490
+ }
491
+
492
+ declare class Webhook extends Child {
493
+ delete(): Promise<boolean | FetchError>;
494
+ set(route?: string, parameters?: Partial<SetWebhook>): Promise<boolean | FetchError>;
495
+ url(route: string): string;
496
+ }
497
+
498
+ export { }
package/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartUtils = exports.ReplyToMessageUtils = exports.InlineKeyboardUtils = exports.HTMLUtils = exports.ContextUtils = exports.CommandUtils = exports.CallbackQueryUtils = exports.Telegram = exports.TelegramConfiguration = exports.UpdateType = exports.TelegramLoggerName = void 0;
4
+ var enums_1 = require("./definitions/enums");
5
+ Object.defineProperty(exports, "TelegramLoggerName", { enumerable: true, get: function () { return enums_1.LoggerName; } });
6
+ Object.defineProperty(exports, "UpdateType", { enumerable: true, get: function () { return enums_1.UpdateType; } });
7
+ var configuration_1 = require("./modules/configuration");
8
+ Object.defineProperty(exports, "TelegramConfiguration", { enumerable: true, get: function () { return configuration_1.Configuration; } });
9
+ var telegram_1 = require("./modules/telegram");
10
+ Object.defineProperty(exports, "Telegram", { enumerable: true, get: function () { return telegram_1.Telegram; } });
11
+ var callback_query_utils_1 = require("./utils/callback.query.utils");
12
+ Object.defineProperty(exports, "CallbackQueryUtils", { enumerable: true, get: function () { return callback_query_utils_1.CallbackQueryUtils; } });
13
+ var command_utils_1 = require("./utils/command.utils");
14
+ Object.defineProperty(exports, "CommandUtils", { enumerable: true, get: function () { return command_utils_1.CommandUtils; } });
15
+ var context_utils_1 = require("./utils/context.utils");
16
+ Object.defineProperty(exports, "ContextUtils", { enumerable: true, get: function () { return context_utils_1.ContextUtils; } });
17
+ var html_utils_1 = require("./utils/html.utils");
18
+ Object.defineProperty(exports, "HTMLUtils", { enumerable: true, get: function () { return html_utils_1.HTMLUtils; } });
19
+ var inline_keyboard_utils_1 = require("./utils/inline.keyboard.utils");
20
+ Object.defineProperty(exports, "InlineKeyboardUtils", { enumerable: true, get: function () { return inline_keyboard_utils_1.InlineKeyboardUtils; } });
21
+ var reply_to_message_utils_1 = require("./utils/reply.to.message.utils");
22
+ Object.defineProperty(exports, "ReplyToMessageUtils", { enumerable: true, get: function () { return reply_to_message_utils_1.ReplyToMessageUtils; } });
23
+ var start_utils_1 = require("./utils/start.utils");
24
+ Object.defineProperty(exports, "StartUtils", { enumerable: true, get: function () { return start_utils_1.StartUtils; } });
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModuleLogger = void 0;
4
+ const core_1 = require("@aracna/core");
5
+ const enums_1 = require("../definitions/enums");
6
+ exports.ModuleLogger = new core_1.Logger(enums_1.LoggerName.MODULE);
package/modules/api.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.API = void 0;
4
+ const core_1 = require("@aracna/core");
5
+ class API extends core_1.API {
6
+ async post(path, body, config) {
7
+ let response;
8
+ response = await this.handle(core_1.RequestMethod.POST, path, body, config);
9
+ if (response instanceof Error)
10
+ return response;
11
+ return response.data.result;
12
+ }
13
+ async transformBody(method, path, body, config) {
14
+ switch (method) {
15
+ case core_1.RequestMethod.GET:
16
+ case core_1.RequestMethod.POST:
17
+ await core_1.Polyfill.blob();
18
+ await core_1.Polyfill.file();
19
+ await core_1.Polyfill.formData();
20
+ return (0, core_1.serializeFormData)(typeof body === 'object' ? body : {});
21
+ default:
22
+ return (0, core_1.serializeFormData)({});
23
+ }
24
+ }
25
+ }
26
+ exports.API = API;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Builder = void 0;
4
+ const button_builder_1 = require("../builders/button.builder");
5
+ class Builder {
6
+ button = new button_builder_1.ButtonBuilder();
7
+ }
8
+ exports.Builder = Builder;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Child = void 0;
4
+ class Child {
5
+ telegram;
6
+ constructor(telegram) {
7
+ this.telegram = telegram;
8
+ }
9
+ }
10
+ exports.Child = Child;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Configuration = void 0;
4
+ const dummy_1 = require("./dummy");
5
+ class _ {
6
+ api = dummy_1.Dummy.configurationAPI;
7
+ default = dummy_1.Dummy.configurationDefault;
8
+ handler = dummy_1.Dummy.configurationHandler;
9
+ }
10
+ exports.Configuration = new _();
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Dummy = void 0;
4
+ const enums_1 = require("../definitions/enums");
5
+ class Dummy {
6
+ static get callbackQueryBody() {
7
+ return {
8
+ c: undefined,
9
+ d: 0,
10
+ t: ''
11
+ };
12
+ }
13
+ static get configurationAPI() {
14
+ return {
15
+ post: {
16
+ callback: {
17
+ success: () => null
18
+ }
19
+ }
20
+ };
21
+ }
22
+ static get configurationDefault() {
23
+ return {
24
+ buttons: {
25
+ callback: async () => [],
26
+ game: async () => [],
27
+ login: async () => [],
28
+ pay: async () => [],
29
+ query: async () => [],
30
+ queryCurrentChat: async () => [],
31
+ text: async () => [],
32
+ url: async () => []
33
+ }
34
+ };
35
+ }
36
+ static get configurationHandler() {
37
+ return { send: { buttons: { empty: () => new Error() } } };
38
+ }
39
+ static get handler() {
40
+ return {
41
+ id: '',
42
+ key: '',
43
+ middleware: () => null,
44
+ options: {
45
+ deleteOnCallbackQuery: true,
46
+ deleteOnMessageStart: true,
47
+ deleteOnReply: true
48
+ },
49
+ type: enums_1.UpdateType.MESSAGE
50
+ };
51
+ }
52
+ static get messageBody() {
53
+ return { chatID: undefined, data: undefined, type: '' };
54
+ }
55
+ }
56
+ exports.Dummy = Dummy;