@maxhub/max-bot-api 0.2.1

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 (91) hide show
  1. package/LICENSE +20 -0
  2. package/dist/api.d.ts +42 -0
  3. package/dist/api.js +144 -0
  4. package/dist/bot.d.ts +26 -0
  5. package/dist/bot.js +70 -0
  6. package/dist/composer.d.ts +22 -0
  7. package/dist/composer.js +130 -0
  8. package/dist/context.d.ts +85 -0
  9. package/dist/context.js +252 -0
  10. package/dist/core/helpers/attachments.d.ts +70 -0
  11. package/dist/core/helpers/attachments.js +127 -0
  12. package/dist/core/helpers/buttons.d.ts +8 -0
  13. package/dist/core/helpers/buttons.js +33 -0
  14. package/dist/core/helpers/keyboard.d.ts +3 -0
  15. package/dist/core/helpers/keyboard.js +34 -0
  16. package/dist/core/helpers/types.d.ts +7 -0
  17. package/dist/core/helpers/types.js +2 -0
  18. package/dist/core/helpers/upload.d.ts +47 -0
  19. package/dist/core/helpers/upload.js +166 -0
  20. package/dist/core/network/api/base-api.d.ts +14 -0
  21. package/dist/core/network/api/base-api.js +35 -0
  22. package/dist/core/network/api/client.d.ts +23 -0
  23. package/dist/core/network/api/client.js +72 -0
  24. package/dist/core/network/api/error.d.ts +11 -0
  25. package/dist/core/network/api/error.js +17 -0
  26. package/dist/core/network/api/index.d.ts +5 -0
  27. package/dist/core/network/api/index.js +25 -0
  28. package/dist/core/network/api/modules/bots/api.d.ts +7 -0
  29. package/dist/core/network/api/modules/bots/api.js +16 -0
  30. package/dist/core/network/api/modules/bots/types.d.ts +11 -0
  31. package/dist/core/network/api/modules/bots/types.js +2 -0
  32. package/dist/core/network/api/modules/chats/api.d.ts +19 -0
  33. package/dist/core/network/api/modules/chats/api.js +83 -0
  34. package/dist/core/network/api/modules/chats/types.d.ts +109 -0
  35. package/dist/core/network/api/modules/chats/types.js +2 -0
  36. package/dist/core/network/api/modules/index.d.ts +12 -0
  37. package/dist/core/network/api/modules/index.js +34 -0
  38. package/dist/core/network/api/modules/messages/api.d.ts +17 -0
  39. package/dist/core/network/api/modules/messages/api.js +59 -0
  40. package/dist/core/network/api/modules/messages/types.d.ts +70 -0
  41. package/dist/core/network/api/modules/messages/types.js +2 -0
  42. package/dist/core/network/api/modules/subscriptions/api.d.ts +6 -0
  43. package/dist/core/network/api/modules/subscriptions/api.js +13 -0
  44. package/dist/core/network/api/modules/subscriptions/types.d.ts +13 -0
  45. package/dist/core/network/api/modules/subscriptions/types.js +2 -0
  46. package/dist/core/network/api/modules/types.d.ts +118 -0
  47. package/dist/core/network/api/modules/types.js +19 -0
  48. package/dist/core/network/api/modules/uploads/api.d.ts +6 -0
  49. package/dist/core/network/api/modules/uploads/api.js +13 -0
  50. package/dist/core/network/api/modules/uploads/types.d.ts +9 -0
  51. package/dist/core/network/api/modules/uploads/types.js +2 -0
  52. package/dist/core/network/api/raw-api.d.ts +169 -0
  53. package/dist/core/network/api/raw-api.js +29 -0
  54. package/dist/core/network/api/types/attachment-request.d.ts +68 -0
  55. package/dist/core/network/api/types/attachment-request.js +2 -0
  56. package/dist/core/network/api/types/attachment.d.ts +67 -0
  57. package/dist/core/network/api/types/attachment.js +2 -0
  58. package/dist/core/network/api/types/bot.d.ts +8 -0
  59. package/dist/core/network/api/types/bot.js +2 -0
  60. package/dist/core/network/api/types/chat.d.ts +41 -0
  61. package/dist/core/network/api/types/chat.js +2 -0
  62. package/dist/core/network/api/types/common.d.ts +9 -0
  63. package/dist/core/network/api/types/common.js +2 -0
  64. package/dist/core/network/api/types/index.d.ts +11 -0
  65. package/dist/core/network/api/types/index.js +27 -0
  66. package/dist/core/network/api/types/keyboard.d.ts +30 -0
  67. package/dist/core/network/api/types/keyboard.js +2 -0
  68. package/dist/core/network/api/types/markup.d.ts +13 -0
  69. package/dist/core/network/api/types/markup.js +2 -0
  70. package/dist/core/network/api/types/message.d.ts +38 -0
  71. package/dist/core/network/api/types/message.js +2 -0
  72. package/dist/core/network/api/types/subcription.d.ts +85 -0
  73. package/dist/core/network/api/types/subcription.js +2 -0
  74. package/dist/core/network/api/types/uploads.d.ts +1 -0
  75. package/dist/core/network/api/types/uploads.js +2 -0
  76. package/dist/core/network/api/types/user.d.ts +14 -0
  77. package/dist/core/network/api/types/user.js +2 -0
  78. package/dist/core/network/polling.d.ts +11 -0
  79. package/dist/core/network/polling.js +51 -0
  80. package/dist/filters.d.ts +2 -0
  81. package/dist/filters.js +17 -0
  82. package/dist/index.d.ts +9 -0
  83. package/dist/index.js +45 -0
  84. package/dist/middleware.d.ts +9 -0
  85. package/dist/middleware.js +2 -0
  86. package/dist/types.d.ts +1 -0
  87. package/dist/types.js +17 -0
  88. package/dist/utils.d.ts +3 -0
  89. package/dist/utils.js +24 -0
  90. package/package.json +55 -0
  91. package/readme.md +62 -0
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,67 @@
1
+ import { NullableObject } from '../../../helpers/types';
2
+ import { Button } from './keyboard';
3
+ import { User } from './user';
4
+ type MediaPayload = {
5
+ url: string;
6
+ token: string;
7
+ };
8
+ export type PhotoAttachment = {
9
+ type: 'image';
10
+ payload: MediaPayload & {
11
+ photo_id: number;
12
+ };
13
+ };
14
+ export type VideoAttachment = {
15
+ type: 'video';
16
+ payload: MediaPayload;
17
+ thumbnail?: string | null;
18
+ width?: number | null;
19
+ height?: number | null;
20
+ duration?: number | null;
21
+ };
22
+ export type AudioAttachment = {
23
+ type: 'audio';
24
+ payload: MediaPayload;
25
+ };
26
+ export type FileAttachment = {
27
+ type: 'file';
28
+ payload: MediaPayload;
29
+ filename: string;
30
+ size: number;
31
+ };
32
+ export type StickerAttachment = {
33
+ type: 'sticker';
34
+ payload: {
35
+ url: string;
36
+ code: string;
37
+ };
38
+ width: number;
39
+ height: number;
40
+ };
41
+ export type ContactAttachment = {
42
+ type: 'contact';
43
+ payload: {
44
+ vcf_info?: string | null;
45
+ tam_info?: User | null;
46
+ };
47
+ };
48
+ export type ShareAttachment = {
49
+ type: 'share';
50
+ payload: Partial<NullableObject<MediaPayload>>;
51
+ title?: string | null;
52
+ description?: string | null;
53
+ image_url?: string | null;
54
+ };
55
+ export type LocationAttachment = {
56
+ type: 'location';
57
+ latitude: number;
58
+ longitude: number;
59
+ };
60
+ export type InlineKeyboardAttachment = {
61
+ type: 'inline_keyboard';
62
+ payload: {
63
+ buttons: Button[][];
64
+ };
65
+ };
66
+ export type Attachment = PhotoAttachment | VideoAttachment | AudioAttachment | FileAttachment | StickerAttachment | ContactAttachment | InlineKeyboardAttachment | ShareAttachment | LocationAttachment;
67
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { UserWithPhoto } from './user';
2
+ export type BotCommand = {
3
+ name: string;
4
+ description?: string | null;
5
+ };
6
+ export type BotInfo = UserWithPhoto & {
7
+ commands?: BotCommand[] | null;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,41 @@
1
+ export type ChatType = 'dialog' | 'chat' | 'channel';
2
+ export type ChatStatus = 'active' | 'removed' | 'left' | 'closed' | 'suspended';
3
+ export type Chat = {
4
+ chat_id: number;
5
+ type: ChatType;
6
+ status: ChatStatus;
7
+ title: string | null;
8
+ icon: {
9
+ url: string;
10
+ } | null;
11
+ last_event_time: number;
12
+ participants_count: number;
13
+ owner_id?: number | null;
14
+ participants?: {
15
+ [key: string]: number | undefined;
16
+ } | null;
17
+ is_public: boolean;
18
+ link?: string | null;
19
+ description?: string | null;
20
+ dialog_with_user?: {} | null;
21
+ messages_count?: number | null;
22
+ chat_message_id?: string | null;
23
+ pinned_message?: object | null;
24
+ };
25
+ export type SenderAction = 'typing_on' | 'sending_photo' | 'sending_video' | 'sending_audio' | 'sending_file' | 'mark_seen';
26
+ export type ChatPermissions = 'read_all_messages' | 'add_remove_members' | 'add_admins' | 'change_chat_info' | 'pin_message' | 'write';
27
+ export type ChatMember = {
28
+ user_id: number;
29
+ name: string;
30
+ username: string | null;
31
+ is_bot: boolean;
32
+ last_activity_time: number;
33
+ description?: string | null;
34
+ avatar_url?: string;
35
+ full_avatar_url?: string;
36
+ last_access_time: number;
37
+ is_owner: boolean;
38
+ is_admin: boolean;
39
+ join_time: number;
40
+ permissions: ChatPermissions[] | null;
41
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ type SuccessResponse = {
2
+ success: true;
3
+ };
4
+ type ErrorResponse = {
5
+ success: false;
6
+ message: string;
7
+ };
8
+ export type ActionResponse = SuccessResponse | ErrorResponse;
9
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export * from './attachment';
2
+ export * from './attachment-request';
3
+ export * from './bot';
4
+ export * from './chat';
5
+ export * from './common';
6
+ export * from './keyboard';
7
+ export * from './markup';
8
+ export * from './message';
9
+ export * from './subcription';
10
+ export * from './uploads';
11
+ export * from './user';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./attachment"), exports);
18
+ __exportStar(require("./attachment-request"), exports);
19
+ __exportStar(require("./bot"), exports);
20
+ __exportStar(require("./chat"), exports);
21
+ __exportStar(require("./common"), exports);
22
+ __exportStar(require("./keyboard"), exports);
23
+ __exportStar(require("./markup"), exports);
24
+ __exportStar(require("./message"), exports);
25
+ __exportStar(require("./subcription"), exports);
26
+ __exportStar(require("./uploads"), exports);
27
+ __exportStar(require("./user"), exports);
@@ -0,0 +1,30 @@
1
+ export type ButtonIntent = 'default' | 'positive' | 'negative';
2
+ export type CallbackButton = {
3
+ type: 'callback';
4
+ text: string;
5
+ payload: string;
6
+ intent?: ButtonIntent;
7
+ };
8
+ export type LinkButton = {
9
+ type: 'link';
10
+ text: string;
11
+ url: string;
12
+ };
13
+ export type RequestContactButton = {
14
+ type: 'request_contact';
15
+ text: string;
16
+ };
17
+ export type RequestGeoLocationButton = {
18
+ type: 'request_geo_location';
19
+ text: string;
20
+ quick?: boolean;
21
+ };
22
+ export type ChatButton = {
23
+ type: 'chat';
24
+ text: string;
25
+ chat_title: string;
26
+ chat_description?: string | null;
27
+ start_payload?: string | null;
28
+ uuid?: string | null;
29
+ };
30
+ export type Button = CallbackButton | LinkButton | RequestContactButton | RequestGeoLocationButton | ChatButton;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ type MakeMarkup<Type extends string, Data extends object> = {
2
+ type: Type;
3
+ from: number;
4
+ length: number;
5
+ } & {
6
+ [key in keyof Data]: Data[key];
7
+ };
8
+ export type UserMentionMarkup = MakeMarkup<'user_mention', {
9
+ user_link?: string | null;
10
+ user_id?: number | null;
11
+ }>;
12
+ export type MarkupElement = UserMentionMarkup;
13
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ import { Attachment } from './attachment';
2
+ import { ChatType } from './chat';
3
+ import { MarkupElement } from './markup';
4
+ import { User } from './user';
5
+ export type MessageSender = User;
6
+ export type MessageRecipient = {
7
+ chat_id: number | null;
8
+ chat_type: ChatType;
9
+ };
10
+ export type MessageBody = {
11
+ mid: string;
12
+ seq: number;
13
+ text: string | null;
14
+ attachments: Attachment[] | null;
15
+ markup?: MarkupElement[] | null;
16
+ };
17
+ export type MessageLinkType = 'forward' | 'reply';
18
+ export type LinkedMessage = {
19
+ type: MessageLinkType;
20
+ sender?: MessageSender | null;
21
+ chat_id?: number;
22
+ message: MessageBody;
23
+ };
24
+ export type MessageStat = {
25
+ views: number;
26
+ };
27
+ export type MessageConstructor = User;
28
+ export type Message = {
29
+ sender?: MessageSender | null;
30
+ recipient: MessageRecipient;
31
+ timestamp: number;
32
+ link?: LinkedMessage | null;
33
+ body: MessageBody;
34
+ stat?: MessageStat | null;
35
+ url?: string | null;
36
+ constructor?: MessageConstructor | null;
37
+ };
38
+ export type ConstructedMessage = Pick<Message, 'sender' | 'timestamp' | 'link' | 'body'>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,85 @@
1
+ import { Chat } from './chat';
2
+ import { ConstructedMessage, Message } from './message';
3
+ import { User, UserLocale } from './user';
4
+ type MakeUpdate<Type extends string, Payload extends object> = {
5
+ update_type: Type;
6
+ timestamp: number;
7
+ } & {
8
+ [key in keyof Payload]: Payload[key];
9
+ };
10
+ export type MessageCallbackUpdate = MakeUpdate<'message_callback', {
11
+ callback: {
12
+ timestamp: number;
13
+ callback_id: string;
14
+ payload?: string;
15
+ user: User;
16
+ };
17
+ message?: Message | null;
18
+ user_locale?: UserLocale | null;
19
+ }>;
20
+ export type MessageCreatedUpdate = MakeUpdate<'message_created', {
21
+ message: Message;
22
+ user_locale?: UserLocale | null;
23
+ }>;
24
+ export type MessageRemovedUpdate = MakeUpdate<'message_removed', {
25
+ message_id: string;
26
+ chat_id: number;
27
+ user_id: number;
28
+ }>;
29
+ export type MessageEditedUpdate = MakeUpdate<'message_edited', {
30
+ message: Message;
31
+ }>;
32
+ export type BotAddedUpdate = MakeUpdate<'bot_added', {
33
+ chat_id: number;
34
+ user: User;
35
+ is_channel: boolean;
36
+ }>;
37
+ export type BotRemovedUpdate = MakeUpdate<'bot_removed', {
38
+ chat_id: number;
39
+ user: User;
40
+ is_channel: boolean;
41
+ }>;
42
+ export type UserAddedUpdate = MakeUpdate<'user_added', {
43
+ chat_id: number;
44
+ user: User;
45
+ inviter_id?: number | null;
46
+ is_channel: boolean;
47
+ }>;
48
+ export type UserRemovedUpdate = MakeUpdate<'user_removed', {
49
+ chat_id: number;
50
+ user: User;
51
+ admin_id?: number | null;
52
+ is_channel: boolean;
53
+ }>;
54
+ export type BotStartedUpdate = MakeUpdate<'bot_started', {
55
+ chat_id: number;
56
+ user: User;
57
+ payload?: string | null;
58
+ user_locale?: UserLocale;
59
+ }>;
60
+ export type ChatTitleChangedUpdate = MakeUpdate<'chat_title_changed', {
61
+ chat_id: number;
62
+ user: User;
63
+ title: string;
64
+ }>;
65
+ export type MessageConstructionRequestUpdate = MakeUpdate<'message_construction_request', {
66
+ user: User;
67
+ user_locale?: UserLocale;
68
+ session_id: string;
69
+ data?: string | null;
70
+ input: unknown;
71
+ }>;
72
+ export type MessageConstructedUpdate = MakeUpdate<'message_constructed', {
73
+ user: User;
74
+ session_id: string;
75
+ message: ConstructedMessage;
76
+ }>;
77
+ export type MessageChatCreatedUpdate = MakeUpdate<'message_chat_created', {
78
+ chat: Chat;
79
+ message_id: string;
80
+ start_payload?: string | null;
81
+ }>;
82
+ export type UpdateType = Update['update_type'];
83
+ export type FilteredUpdate<Type extends UpdateType> = Type extends 'message_callback' ? MessageCallbackUpdate : Type extends 'message_created' ? MessageCreatedUpdate : Type extends 'message_removed' ? MessageRemovedUpdate : Type extends 'message_edited' ? MessageEditedUpdate : Type extends 'bot_added' ? BotAddedUpdate : Type extends 'bot_removed' ? BotRemovedUpdate : Type extends 'user_added' ? UserAddedUpdate : Type extends 'user_removed' ? UserRemovedUpdate : Type extends 'bot_started' ? BotStartedUpdate : Type extends 'chat_title_changed' ? ChatTitleChangedUpdate : Type extends 'message_construction_request' ? MessageConstructionRequestUpdate : Type extends 'message_constructed' ? MessageConstructedUpdate : Type extends 'message_chat_created' ? MessageChatCreatedUpdate : never;
84
+ export type Update = MessageCallbackUpdate | MessageCreatedUpdate | MessageRemovedUpdate | MessageEditedUpdate | BotAddedUpdate | BotRemovedUpdate | UserAddedUpdate | UserRemovedUpdate | BotStartedUpdate | ChatTitleChangedUpdate | MessageConstructionRequestUpdate | MessageConstructedUpdate | MessageChatCreatedUpdate;
85
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type UploadType = 'image' | 'video' | 'audio' | 'file';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ export type User = {
2
+ user_id: number;
3
+ name: string;
4
+ username: string | null;
5
+ is_bot: boolean;
6
+ last_activity_time: number;
7
+ };
8
+ export type UserWithPhoto = User & {
9
+ description?: string | null;
10
+ avatar_url?: string;
11
+ full_avatar_url?: string;
12
+ };
13
+ export declare const enum UserLocale {
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import type { Api } from '../../api';
2
+ import { Update, UpdateType } from './api';
3
+ export declare class Polling {
4
+ private readonly api;
5
+ private readonly allowedUpdates;
6
+ private readonly abortController;
7
+ private marker?;
8
+ constructor(api: Api, allowedUpdates?: UpdateType[]);
9
+ loop: (handleUpdate: (updates: Update) => Promise<void>) => Promise<void>;
10
+ stop: () => void;
11
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Polling = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const api_1 = require("./api");
9
+ const debug = (0, debug_1.default)('one-me:polling');
10
+ const RETRY_INTERVAL = 5000; // ms
11
+ class Polling {
12
+ constructor(api, allowedUpdates = []) {
13
+ this.api = api;
14
+ this.allowedUpdates = allowedUpdates;
15
+ this.abortController = new AbortController();
16
+ this.loop = async (handleUpdate) => {
17
+ debug('Starting long polling');
18
+ while (!this.abortController.signal.aborted) {
19
+ try {
20
+ const { updates, marker } = await this.api.getUpdates(this.allowedUpdates, {
21
+ marker: this.marker,
22
+ });
23
+ this.marker = marker;
24
+ await Promise.all(updates.map(handleUpdate));
25
+ }
26
+ catch (err) {
27
+ if (err instanceof Error) {
28
+ if (err.name === 'AbortError')
29
+ return;
30
+ if (err.name === 'FetchError'
31
+ || (err instanceof api_1.MaxError && err.status === 429)
32
+ || (err instanceof api_1.MaxError && err.status >= 500)) {
33
+ debug(`Failed to fetch updates, retrying after ${RETRY_INTERVAL}ms.`, err);
34
+ await new Promise((resolve) => {
35
+ setTimeout(resolve, RETRY_INTERVAL);
36
+ });
37
+ return;
38
+ }
39
+ }
40
+ throw err;
41
+ }
42
+ }
43
+ debug('Long polling is done');
44
+ };
45
+ this.stop = () => {
46
+ debug('Stopping long polling');
47
+ this.abortController.abort();
48
+ };
49
+ }
50
+ }
51
+ exports.Polling = Polling;
@@ -0,0 +1,2 @@
1
+ import type { MessageBody, MessageCreatedUpdate, Update } from './core/network/api';
2
+ export declare const createdMessageBodyHas: <Keys extends Array<keyof MessageBody>>(...keys: Keys) => (update: Update) => update is MessageCreatedUpdate;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createdMessageBodyHas = void 0;
4
+ const createdMessageBodyHas = (...keys) => {
5
+ return (update) => {
6
+ if (update.update_type !== 'message_created')
7
+ return false;
8
+ for (const key of keys) {
9
+ if (!(key in update.message.body))
10
+ return false;
11
+ if (update.message.body[key] === undefined)
12
+ return false;
13
+ }
14
+ return true;
15
+ };
16
+ };
17
+ exports.createdMessageBodyHas = createdMessageBodyHas;
@@ -0,0 +1,9 @@
1
+ export { Api } from './api';
2
+ export { Bot } from './bot';
3
+ export { Composer } from './composer';
4
+ export { Context } from './context';
5
+ export type { FilteredContext } from './context';
6
+ export type { MiddlewareFn, Middleware, MiddlewareObj, NextFn, } from './middleware';
7
+ export { AudioAttachment, FileAttachment, ImageAttachment, StickerAttachment, VideoAttachment, LocationAttachment, ShareAttachment, } from './core/helpers/attachments';
8
+ export * as Keyboard from './core/helpers/keyboard';
9
+ export { MaxError } from './core/network/api';
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.MaxError = exports.Keyboard = exports.ShareAttachment = exports.LocationAttachment = exports.VideoAttachment = exports.StickerAttachment = exports.ImageAttachment = exports.FileAttachment = exports.AudioAttachment = exports.Context = exports.Composer = exports.Bot = exports.Api = void 0;
27
+ var api_1 = require("./api");
28
+ Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } });
29
+ var bot_1 = require("./bot");
30
+ Object.defineProperty(exports, "Bot", { enumerable: true, get: function () { return bot_1.Bot; } });
31
+ var composer_1 = require("./composer");
32
+ Object.defineProperty(exports, "Composer", { enumerable: true, get: function () { return composer_1.Composer; } });
33
+ var context_1 = require("./context");
34
+ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
35
+ var attachments_1 = require("./core/helpers/attachments");
36
+ Object.defineProperty(exports, "AudioAttachment", { enumerable: true, get: function () { return attachments_1.AudioAttachment; } });
37
+ Object.defineProperty(exports, "FileAttachment", { enumerable: true, get: function () { return attachments_1.FileAttachment; } });
38
+ Object.defineProperty(exports, "ImageAttachment", { enumerable: true, get: function () { return attachments_1.ImageAttachment; } });
39
+ Object.defineProperty(exports, "StickerAttachment", { enumerable: true, get: function () { return attachments_1.StickerAttachment; } });
40
+ Object.defineProperty(exports, "VideoAttachment", { enumerable: true, get: function () { return attachments_1.VideoAttachment; } });
41
+ Object.defineProperty(exports, "LocationAttachment", { enumerable: true, get: function () { return attachments_1.LocationAttachment; } });
42
+ Object.defineProperty(exports, "ShareAttachment", { enumerable: true, get: function () { return attachments_1.ShareAttachment; } });
43
+ exports.Keyboard = __importStar(require("./core/helpers/keyboard"));
44
+ var api_2 = require("./core/network/api");
45
+ Object.defineProperty(exports, "MaxError", { enumerable: true, get: function () { return api_2.MaxError; } });
@@ -0,0 +1,9 @@
1
+ import { Context } from './context';
2
+ type MaybePromise<T> = T | Promise<T>;
3
+ export type NextFn = () => Promise<void>;
4
+ export type MiddlewareFn<Ctx extends Context> = (ctx: Ctx, next: NextFn) => MaybePromise<unknown>;
5
+ export interface MiddlewareObj<Ctx extends Context> {
6
+ middleware: () => MiddlewareFn<Ctx>;
7
+ }
8
+ export type Middleware<Ctx extends Context> = MiddlewareFn<Ctx> | MiddlewareObj<Ctx>;
9
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './core/network/api/types';
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./core/network/api/types"), exports);
@@ -0,0 +1,3 @@
1
+ import fs from 'node:fs';
2
+ export declare const sleep: (ms: number) => Promise<void>;
3
+ export declare const streamToBlob: (stream: fs.ReadStream, mimeType?: string) => Promise<Blob>;
package/dist/utils.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.streamToBlob = exports.sleep = void 0;
4
+ const sleep = async (ms) => {
5
+ await new Promise((resolve) => {
6
+ setTimeout(resolve, ms);
7
+ });
8
+ };
9
+ exports.sleep = sleep;
10
+ const streamToBlob = async (stream, mimeType) => {
11
+ return new Promise((resolve, reject) => {
12
+ const chunks = [];
13
+ stream
14
+ .on('data', (chunk) => chunks.push(chunk))
15
+ .once('end', () => {
16
+ const blob = mimeType
17
+ ? new Blob(chunks, { type: mimeType })
18
+ : new Blob(chunks);
19
+ resolve(blob);
20
+ })
21
+ .once('error', reject);
22
+ });
23
+ };
24
+ exports.streamToBlob = streamToBlob;