@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,252 @@
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.Context = void 0;
7
+ const vcf_1 = __importDefault(require("vcf"));
8
+ class Context {
9
+ constructor(update, api, botInfo) {
10
+ this.update = update;
11
+ this.api = api;
12
+ this.botInfo = botInfo;
13
+ }
14
+ has(filters) {
15
+ for (const filter of Array.isArray(filters) ? filters : [filters]) {
16
+ if (typeof filter === 'function'
17
+ ? filter(this.update)
18
+ : filter === this.update.update_type) {
19
+ return true;
20
+ }
21
+ }
22
+ return false;
23
+ }
24
+ assert(value, method) {
25
+ if (value === undefined) {
26
+ throw new TypeError(`Max: "${method}" isn't available for "${this.updateType}"`);
27
+ }
28
+ }
29
+ get updateType() {
30
+ return this.update.update_type;
31
+ }
32
+ get myId() {
33
+ return this.botInfo?.user_id;
34
+ }
35
+ get startPayload() {
36
+ return getStartPayload(this.update);
37
+ }
38
+ get chat() {
39
+ return getChat(this.update);
40
+ }
41
+ get chatId() {
42
+ return getChatId(this.update);
43
+ }
44
+ get message() {
45
+ return getMessage(this.update);
46
+ }
47
+ get messageId() {
48
+ return getMessageId(this.update);
49
+ }
50
+ get callback() {
51
+ return getCallback(this.update);
52
+ }
53
+ get user() {
54
+ return getUser(this.update);
55
+ }
56
+ get contactInfo() {
57
+ return (this._contactInfo ?? (this._contactInfo = getContactInfo(this.update)));
58
+ }
59
+ get location() {
60
+ return (this._location ?? (this._location = getLocation(this.update)));
61
+ }
62
+ get sticker() {
63
+ return (this._sticker ?? (this._sticker = getSticker(this.update)));
64
+ }
65
+ async reply(text, extra) {
66
+ this.assert(this.chatId, 'reply');
67
+ return this.api.sendMessageToChat(this.chatId, text, extra);
68
+ }
69
+ async getAllChats(extra) {
70
+ return this.api.getAllChats(extra);
71
+ }
72
+ async getChat(chatId) {
73
+ if (chatId !== undefined) {
74
+ return this.api.getChat(chatId);
75
+ }
76
+ this.assert(this.chatId, 'getChat');
77
+ return this.api.getChat(this.chatId);
78
+ }
79
+ async getChatByLink(link) {
80
+ return this.api.getChatByLink(link);
81
+ }
82
+ async editChatInfo(extra) {
83
+ this.assert(this.chatId, 'editChatInfo');
84
+ return this.api.editChatInfo(this.chatId, extra);
85
+ }
86
+ async getMessage(id) {
87
+ return this.api.getMessage(id);
88
+ }
89
+ async getMessages(extra) {
90
+ this.assert(this.chatId, 'getMessages');
91
+ return this.api.getMessages(this.chatId, extra);
92
+ }
93
+ async getPinnedMessage() {
94
+ this.assert(this.chatId, 'getPinnedMessage');
95
+ return this.api.getPinnedMessage(this.chatId);
96
+ }
97
+ async editMessage(extra) {
98
+ this.assert(this.messageId, 'editMessage');
99
+ return this.api.editMessage(this.messageId, extra);
100
+ }
101
+ async deleteMessage(messageId) {
102
+ if (messageId !== undefined) {
103
+ return this.api.deleteMessage(messageId);
104
+ }
105
+ this.assert(this.messageId, 'deleteMessage');
106
+ return this.api.deleteMessage(this.messageId);
107
+ }
108
+ async answerOnCallback(extra) {
109
+ this.assert(this.callback, 'answerOnCallback');
110
+ return this.api.answerOnCallback(this.callback.callback_id, extra);
111
+ }
112
+ async getChatMembership() {
113
+ this.assert(this.chatId, 'getChatMembership');
114
+ return this.api.getChatMembership(this.chatId);
115
+ }
116
+ async getChatAdmins() {
117
+ this.assert(this.chatId, 'getChatAdmins');
118
+ return this.api.getChatAdmins(this.chatId);
119
+ }
120
+ async addChatMembers(userIds) {
121
+ this.assert(this.chatId, 'addChatMembers');
122
+ return this.api.addChatMembers(this.chatId, userIds);
123
+ }
124
+ async getChatMembers(extra) {
125
+ this.assert(this.chatId, 'getChatMembers');
126
+ return this.api.getChatMembers(this.chatId, extra);
127
+ }
128
+ async removeChatMember(userId) {
129
+ this.assert(this.chatId, 'removeChatMember');
130
+ return this.api.removeChatMember(this.chatId, userId);
131
+ }
132
+ async pinMessage(messageId, extra) {
133
+ this.assert(this.chatId, 'pinMessage');
134
+ return this.api.pinMessage(this.chatId, messageId, extra);
135
+ }
136
+ async unpinMessage() {
137
+ this.assert(this.chatId, 'unpinMessage');
138
+ return this.api.unpinMessage(this.chatId);
139
+ }
140
+ async sendAction(action) {
141
+ this.assert(this.chatId, 'sendAction');
142
+ return this.api.sendAction(this.chatId, action);
143
+ }
144
+ async leaveChat() {
145
+ this.assert(this.chatId, 'leaveChat');
146
+ return this.api.leaveChat(this.chatId);
147
+ }
148
+ }
149
+ exports.Context = Context;
150
+ const getChatId = (update) => {
151
+ if ('chat_id' in update) {
152
+ return update.chat_id;
153
+ }
154
+ if ('message' in update && update.message && 'recipient' in update.message) {
155
+ return update.message.recipient.chat_id;
156
+ }
157
+ if ('chat' in update) {
158
+ return update.chat.chat_id;
159
+ }
160
+ return undefined;
161
+ };
162
+ const getChat = (update) => {
163
+ if ('chat' in update) {
164
+ return update.chat;
165
+ }
166
+ return undefined;
167
+ };
168
+ const getMessage = (update) => {
169
+ if ('message' in update) {
170
+ return update.message;
171
+ }
172
+ return undefined;
173
+ };
174
+ const getMessageId = (update) => {
175
+ if ('message_id' in update) {
176
+ return update.message_id;
177
+ }
178
+ if ('message' in update) {
179
+ return update.message?.body.mid;
180
+ }
181
+ return undefined;
182
+ };
183
+ const getCallback = (update) => {
184
+ if ('callback' in update) {
185
+ return update.callback;
186
+ }
187
+ return undefined;
188
+ };
189
+ const getContactInfo = (update) => {
190
+ const message = getMessage(update);
191
+ if (!message)
192
+ return undefined;
193
+ const contact = message.body.attachments?.find((attachment) => {
194
+ return attachment.type === 'contact';
195
+ });
196
+ if (!contact?.payload.vcf_info)
197
+ return undefined;
198
+ // eslint-disable-next-line new-cap
199
+ const vcf = new vcf_1.default().parse(contact.payload.vcf_info);
200
+ return {
201
+ tel: vcf.get('tel').valueOf(),
202
+ fullName: vcf.get('fn').valueOf(),
203
+ };
204
+ };
205
+ const getLocation = (update) => {
206
+ const message = getMessage(update);
207
+ if (!message)
208
+ return undefined;
209
+ const location = message.body.attachments?.find((attachment) => {
210
+ return attachment.type === 'location';
211
+ });
212
+ if (!location)
213
+ return undefined;
214
+ return {
215
+ latitude: location.latitude,
216
+ longitude: location.longitude,
217
+ };
218
+ };
219
+ const getSticker = (update) => {
220
+ const message = getMessage(update);
221
+ if (!message)
222
+ return undefined;
223
+ const sticker = message.body.attachments?.find((attachment) => {
224
+ return attachment.type === 'sticker';
225
+ });
226
+ if (!sticker)
227
+ return undefined;
228
+ return {
229
+ width: sticker.width,
230
+ height: sticker.height,
231
+ url: sticker.payload.url,
232
+ code: sticker.payload.code,
233
+ };
234
+ };
235
+ const getUser = (update) => {
236
+ if ('user' in update) {
237
+ return update.user;
238
+ }
239
+ if (update.update_type === 'message_callback') {
240
+ return update.callback.user;
241
+ }
242
+ if (update.update_type === 'message_created') {
243
+ return update.message.sender || undefined;
244
+ }
245
+ return undefined;
246
+ };
247
+ const getStartPayload = (update) => {
248
+ if (update.update_type === 'bot_started') {
249
+ return update.payload;
250
+ }
251
+ return undefined;
252
+ };
@@ -0,0 +1,70 @@
1
+ import { AudioAttachmentRequest, FileAttachmentRequest, ImageAttachmentRequest, LocationAttachmentRequest, ShareAttachmentRequest, StickerAttachmentRequest, VideoAttachmentRequest } from '../network/api';
2
+ declare class Attachment {
3
+ toJson(): void;
4
+ }
5
+ export declare class MediaAttachment extends Attachment {
6
+ readonly token?: string;
7
+ constructor({ token }: {
8
+ token?: string;
9
+ });
10
+ get payload(): object;
11
+ }
12
+ export declare class VideoAttachment extends MediaAttachment {
13
+ readonly type = "video";
14
+ toJson(): VideoAttachmentRequest;
15
+ }
16
+ export type ImagePhotos = {
17
+ [key: string]: {
18
+ token: string;
19
+ };
20
+ };
21
+ export declare class ImageAttachment extends MediaAttachment {
22
+ readonly photos?: ImagePhotos;
23
+ readonly url?: string;
24
+ constructor(options: {
25
+ token?: string;
26
+ } | {
27
+ photos?: ImagePhotos;
28
+ } | {
29
+ url?: string;
30
+ });
31
+ get payload(): ImageAttachmentRequest['payload'];
32
+ toJson(): ImageAttachmentRequest;
33
+ }
34
+ export declare class AudioAttachment extends MediaAttachment {
35
+ toJson(): AudioAttachmentRequest;
36
+ }
37
+ export declare class FileAttachment extends MediaAttachment {
38
+ toJson(): FileAttachmentRequest;
39
+ }
40
+ export declare class StickerAttachment extends Attachment {
41
+ readonly code: string;
42
+ constructor({ code }: {
43
+ code: string;
44
+ });
45
+ get payload(): StickerAttachmentRequest['payload'];
46
+ toJson(): StickerAttachmentRequest;
47
+ }
48
+ export declare class LocationAttachment extends Attachment {
49
+ readonly longitude: number;
50
+ readonly latitude: number;
51
+ constructor({ lon, lat }: {
52
+ lon: number;
53
+ lat: number;
54
+ });
55
+ toJson(): LocationAttachmentRequest;
56
+ }
57
+ export declare class ShareAttachment extends Attachment {
58
+ readonly url?: string;
59
+ readonly token?: string;
60
+ constructor({ url, token }?: {
61
+ url?: string;
62
+ token?: string;
63
+ });
64
+ get payload(): {
65
+ url: string | undefined;
66
+ token: string | undefined;
67
+ };
68
+ toJson(): ShareAttachmentRequest;
69
+ }
70
+ export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShareAttachment = exports.LocationAttachment = exports.StickerAttachment = exports.FileAttachment = exports.AudioAttachment = exports.ImageAttachment = exports.VideoAttachment = exports.MediaAttachment = void 0;
4
+ class Attachment {
5
+ toJson() {
6
+ throw new Error('Attachment not implemented.');
7
+ }
8
+ }
9
+ class MediaAttachment extends Attachment {
10
+ constructor({ token }) {
11
+ super();
12
+ this.token = token;
13
+ }
14
+ get payload() {
15
+ return { token: this.token };
16
+ }
17
+ }
18
+ exports.MediaAttachment = MediaAttachment;
19
+ class VideoAttachment extends MediaAttachment {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.type = 'video';
23
+ }
24
+ toJson() {
25
+ return {
26
+ type: this.type,
27
+ payload: this.payload,
28
+ };
29
+ }
30
+ }
31
+ exports.VideoAttachment = VideoAttachment;
32
+ class ImageAttachment extends MediaAttachment {
33
+ constructor(options) {
34
+ super({ token: 'token' in options ? options.token : undefined });
35
+ if ('photos' in options) {
36
+ this.photos = options.photos;
37
+ }
38
+ if ('url' in options) {
39
+ this.url = options.url;
40
+ }
41
+ }
42
+ get payload() {
43
+ if (this.token) {
44
+ return { token: this.token };
45
+ }
46
+ if (this.url) {
47
+ return { url: this.url };
48
+ }
49
+ return { photos: this.photos };
50
+ }
51
+ toJson() {
52
+ return {
53
+ type: 'image',
54
+ payload: this.payload,
55
+ };
56
+ }
57
+ }
58
+ exports.ImageAttachment = ImageAttachment;
59
+ class AudioAttachment extends MediaAttachment {
60
+ toJson() {
61
+ return {
62
+ type: 'audio',
63
+ payload: this.payload,
64
+ };
65
+ }
66
+ }
67
+ exports.AudioAttachment = AudioAttachment;
68
+ class FileAttachment extends MediaAttachment {
69
+ toJson() {
70
+ return {
71
+ type: 'file',
72
+ payload: this.payload,
73
+ };
74
+ }
75
+ }
76
+ exports.FileAttachment = FileAttachment;
77
+ class StickerAttachment extends Attachment {
78
+ constructor({ code }) {
79
+ super();
80
+ this.code = code;
81
+ }
82
+ get payload() {
83
+ return { code: this.code };
84
+ }
85
+ toJson() {
86
+ return {
87
+ type: 'sticker',
88
+ payload: this.payload,
89
+ };
90
+ }
91
+ }
92
+ exports.StickerAttachment = StickerAttachment;
93
+ class LocationAttachment extends Attachment {
94
+ constructor({ lon, lat }) {
95
+ super();
96
+ this.longitude = lon;
97
+ this.latitude = lat;
98
+ }
99
+ toJson() {
100
+ return {
101
+ type: 'location',
102
+ latitude: this.latitude,
103
+ longitude: this.longitude,
104
+ };
105
+ }
106
+ }
107
+ exports.LocationAttachment = LocationAttachment;
108
+ class ShareAttachment extends Attachment {
109
+ constructor({ url, token } = {}) {
110
+ super();
111
+ this.url = url;
112
+ this.token = token;
113
+ }
114
+ get payload() {
115
+ return {
116
+ url: this.url,
117
+ token: this.token,
118
+ };
119
+ }
120
+ toJson() {
121
+ return {
122
+ type: 'share',
123
+ payload: this.payload,
124
+ };
125
+ }
126
+ }
127
+ exports.ShareAttachment = ShareAttachment;
@@ -0,0 +1,8 @@
1
+ import { Button, CallbackButton, ChatButton, LinkButton, RequestContactButton, RequestGeoLocationButton } from '../network/api';
2
+ type MakeExtra<T extends Button, O extends keyof Omit<T, 'text' | 'type'> | '' = ''> = Omit<T, 'text' | 'type' | O>;
3
+ export declare const callback: (text: string, payload: string, extra?: MakeExtra<CallbackButton, "payload">) => CallbackButton;
4
+ export declare const link: (text: string, url: string) => LinkButton;
5
+ export declare const requestContact: (text: string) => RequestContactButton;
6
+ export declare const requestGeoLocation: (text: string, extra?: MakeExtra<RequestGeoLocationButton>) => RequestGeoLocationButton;
7
+ export declare const chat: (text: string, chatTitle: string, extra?: MakeExtra<ChatButton, "chat_title">) => ChatButton;
8
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chat = exports.requestGeoLocation = exports.requestContact = exports.link = exports.callback = void 0;
4
+ const callback = (text, payload, extra) => {
5
+ return {
6
+ type: 'callback', text, payload, ...extra,
7
+ };
8
+ };
9
+ exports.callback = callback;
10
+ const link = (text, url) => {
11
+ return {
12
+ type: 'link', text, url,
13
+ };
14
+ };
15
+ exports.link = link;
16
+ const requestContact = (text) => {
17
+ return {
18
+ type: 'request_contact', text,
19
+ };
20
+ };
21
+ exports.requestContact = requestContact;
22
+ const requestGeoLocation = (text, extra) => {
23
+ return {
24
+ type: 'request_geo_location', text, ...extra,
25
+ };
26
+ };
27
+ exports.requestGeoLocation = requestGeoLocation;
28
+ const chat = (text, chatTitle, extra) => {
29
+ return {
30
+ type: 'chat', text, chat_title: chatTitle, ...extra,
31
+ };
32
+ };
33
+ exports.chat = chat;
@@ -0,0 +1,3 @@
1
+ import { InlineKeyboardAttachmentRequest } from '../network/api';
2
+ export declare const inlineKeyboard: (buttons: InlineKeyboardAttachmentRequest["payload"]["buttons"]) => InlineKeyboardAttachmentRequest;
3
+ export * as button from './buttons';
@@ -0,0 +1,34 @@
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.button = exports.inlineKeyboard = void 0;
27
+ const inlineKeyboard = (buttons) => {
28
+ return {
29
+ type: 'inline_keyboard',
30
+ payload: { buttons },
31
+ };
32
+ };
33
+ exports.inlineKeyboard = inlineKeyboard;
34
+ exports.button = __importStar(require("./buttons"));
@@ -0,0 +1,7 @@
1
+ export type NullableObject<T> = {
2
+ [K in keyof T]: T[K] | null;
3
+ };
4
+ export type MaybeArray<T> = T | T[];
5
+ export type MaybePromise<T> = T | Promise<T>;
6
+ export type Guard<X = unknown, Y extends X = X> = (x: X) => x is Y;
7
+ export type Guarded<F> = F extends (x: any) => x is infer T ? T : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,47 @@
1
+ import * as fs from 'fs';
2
+ import { type Api } from '../../api';
3
+ type FileSource = string | fs.ReadStream | Buffer;
4
+ type DefaultOptions = {
5
+ timeout?: number;
6
+ };
7
+ type UploadFromSourceOptions = {
8
+ source: FileSource;
9
+ };
10
+ type UploadFromUrlOptions = {
11
+ url: string;
12
+ };
13
+ type UploadFromUrlOrSourceOptions = UploadFromSourceOptions | UploadFromUrlOptions;
14
+ export type UploadImageOptions = UploadFromUrlOrSourceOptions & DefaultOptions;
15
+ export type UploadVideoOptions = UploadFromSourceOptions & DefaultOptions;
16
+ export type UploadFileOptions = UploadFromSourceOptions & DefaultOptions;
17
+ export type UploadAudioOptions = UploadFromSourceOptions & DefaultOptions;
18
+ export declare class Upload {
19
+ private readonly api;
20
+ constructor(api: Api);
21
+ private getStreamFromSource;
22
+ private upload;
23
+ private uploadFromStream;
24
+ private uploadFromBuffer;
25
+ image: ({ timeout, ...source }: UploadImageOptions) => Promise<{
26
+ photos: {
27
+ [key: string]: {
28
+ token: string;
29
+ };
30
+ };
31
+ } | {
32
+ url: string;
33
+ }>;
34
+ video: ({ source, ...options }: UploadVideoOptions) => Promise<{
35
+ id: number;
36
+ token: string;
37
+ }>;
38
+ file: ({ source, ...options }: UploadFileOptions) => Promise<{
39
+ id: number;
40
+ token: string;
41
+ }>;
42
+ audio: ({ source, ...options }: UploadAudioOptions) => Promise<{
43
+ id: number;
44
+ token: string;
45
+ }>;
46
+ }
47
+ export {};