@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.
- package/LICENSE +20 -0
- package/dist/api.d.ts +42 -0
- package/dist/api.js +144 -0
- package/dist/bot.d.ts +26 -0
- package/dist/bot.js +70 -0
- package/dist/composer.d.ts +22 -0
- package/dist/composer.js +130 -0
- package/dist/context.d.ts +85 -0
- package/dist/context.js +252 -0
- package/dist/core/helpers/attachments.d.ts +70 -0
- package/dist/core/helpers/attachments.js +127 -0
- package/dist/core/helpers/buttons.d.ts +8 -0
- package/dist/core/helpers/buttons.js +33 -0
- package/dist/core/helpers/keyboard.d.ts +3 -0
- package/dist/core/helpers/keyboard.js +34 -0
- package/dist/core/helpers/types.d.ts +7 -0
- package/dist/core/helpers/types.js +2 -0
- package/dist/core/helpers/upload.d.ts +47 -0
- package/dist/core/helpers/upload.js +166 -0
- package/dist/core/network/api/base-api.d.ts +14 -0
- package/dist/core/network/api/base-api.js +35 -0
- package/dist/core/network/api/client.d.ts +23 -0
- package/dist/core/network/api/client.js +72 -0
- package/dist/core/network/api/error.d.ts +11 -0
- package/dist/core/network/api/error.js +17 -0
- package/dist/core/network/api/index.d.ts +5 -0
- package/dist/core/network/api/index.js +25 -0
- package/dist/core/network/api/modules/bots/api.d.ts +7 -0
- package/dist/core/network/api/modules/bots/api.js +16 -0
- package/dist/core/network/api/modules/bots/types.d.ts +11 -0
- package/dist/core/network/api/modules/bots/types.js +2 -0
- package/dist/core/network/api/modules/chats/api.d.ts +19 -0
- package/dist/core/network/api/modules/chats/api.js +83 -0
- package/dist/core/network/api/modules/chats/types.d.ts +109 -0
- package/dist/core/network/api/modules/chats/types.js +2 -0
- package/dist/core/network/api/modules/index.d.ts +12 -0
- package/dist/core/network/api/modules/index.js +34 -0
- package/dist/core/network/api/modules/messages/api.d.ts +17 -0
- package/dist/core/network/api/modules/messages/api.js +59 -0
- package/dist/core/network/api/modules/messages/types.d.ts +70 -0
- package/dist/core/network/api/modules/messages/types.js +2 -0
- package/dist/core/network/api/modules/subscriptions/api.d.ts +6 -0
- package/dist/core/network/api/modules/subscriptions/api.js +13 -0
- package/dist/core/network/api/modules/subscriptions/types.d.ts +13 -0
- package/dist/core/network/api/modules/subscriptions/types.js +2 -0
- package/dist/core/network/api/modules/types.d.ts +118 -0
- package/dist/core/network/api/modules/types.js +19 -0
- package/dist/core/network/api/modules/uploads/api.d.ts +6 -0
- package/dist/core/network/api/modules/uploads/api.js +13 -0
- package/dist/core/network/api/modules/uploads/types.d.ts +9 -0
- package/dist/core/network/api/modules/uploads/types.js +2 -0
- package/dist/core/network/api/raw-api.d.ts +169 -0
- package/dist/core/network/api/raw-api.js +29 -0
- package/dist/core/network/api/types/attachment-request.d.ts +68 -0
- package/dist/core/network/api/types/attachment-request.js +2 -0
- package/dist/core/network/api/types/attachment.d.ts +67 -0
- package/dist/core/network/api/types/attachment.js +2 -0
- package/dist/core/network/api/types/bot.d.ts +8 -0
- package/dist/core/network/api/types/bot.js +2 -0
- package/dist/core/network/api/types/chat.d.ts +41 -0
- package/dist/core/network/api/types/chat.js +2 -0
- package/dist/core/network/api/types/common.d.ts +9 -0
- package/dist/core/network/api/types/common.js +2 -0
- package/dist/core/network/api/types/index.d.ts +11 -0
- package/dist/core/network/api/types/index.js +27 -0
- package/dist/core/network/api/types/keyboard.d.ts +30 -0
- package/dist/core/network/api/types/keyboard.js +2 -0
- package/dist/core/network/api/types/markup.d.ts +13 -0
- package/dist/core/network/api/types/markup.js +2 -0
- package/dist/core/network/api/types/message.d.ts +38 -0
- package/dist/core/network/api/types/message.js +2 -0
- package/dist/core/network/api/types/subcription.d.ts +85 -0
- package/dist/core/network/api/types/subcription.js +2 -0
- package/dist/core/network/api/types/uploads.d.ts +1 -0
- package/dist/core/network/api/types/uploads.js +2 -0
- package/dist/core/network/api/types/user.d.ts +14 -0
- package/dist/core/network/api/types/user.js +2 -0
- package/dist/core/network/polling.d.ts +11 -0
- package/dist/core/network/polling.js +51 -0
- package/dist/filters.d.ts +2 -0
- package/dist/filters.js +17 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +45 -0
- package/dist/middleware.d.ts +9 -0
- package/dist/middleware.js +2 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +17 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +24 -0
- package/package.json +55 -0
- package/readme.md +62 -0
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Upload = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const node_crypto_1 = require("node:crypto");
|
|
32
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
33
|
+
const api_1 = require("../network/api");
|
|
34
|
+
const DEFAULT_UPLOAD_TIMEOUT = 20000; // ms
|
|
35
|
+
class Upload {
|
|
36
|
+
constructor(api) {
|
|
37
|
+
this.api = api;
|
|
38
|
+
this.getStreamFromSource = async (source) => {
|
|
39
|
+
if (typeof source === 'string') {
|
|
40
|
+
const stat = await fs.promises.stat(source);
|
|
41
|
+
const fileName = node_path_1.default.basename(source);
|
|
42
|
+
if (!stat.isFile()) {
|
|
43
|
+
throw new Error(`Failed to upload ${fileName}. Not a file`);
|
|
44
|
+
}
|
|
45
|
+
const stream = fs.createReadStream(source);
|
|
46
|
+
return {
|
|
47
|
+
stream,
|
|
48
|
+
fileName,
|
|
49
|
+
contentLength: stat.size,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (source instanceof Buffer) {
|
|
53
|
+
return {
|
|
54
|
+
buffer: source,
|
|
55
|
+
fileName: (0, node_crypto_1.randomUUID)(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const stat = await fs.promises.stat(source.path);
|
|
59
|
+
let fileName;
|
|
60
|
+
if (typeof source.path === 'string') {
|
|
61
|
+
fileName = node_path_1.default.basename(source.path);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
fileName = (0, node_crypto_1.randomUUID)();
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
stream: source,
|
|
68
|
+
contentLength: stat.size,
|
|
69
|
+
fileName,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
this.upload = async (type, file, options) => {
|
|
73
|
+
const { url: uploadUrl } = await this.api.raw.uploads.getUploadUrl({ type });
|
|
74
|
+
const uploadController = new AbortController();
|
|
75
|
+
const uploadInterval = setTimeout(() => {
|
|
76
|
+
uploadController.abort();
|
|
77
|
+
}, options?.timeout || DEFAULT_UPLOAD_TIMEOUT);
|
|
78
|
+
try {
|
|
79
|
+
if ('stream' in file) {
|
|
80
|
+
return await this.uploadFromStream({
|
|
81
|
+
file,
|
|
82
|
+
uploadUrl,
|
|
83
|
+
abortController: uploadController,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return await this.uploadFromBuffer({
|
|
87
|
+
file,
|
|
88
|
+
uploadUrl,
|
|
89
|
+
abortController: uploadController,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
clearTimeout(uploadInterval);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
this.uploadFromStream = async ({ file, uploadUrl, abortController }) => {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
let prevChunk = -1;
|
|
99
|
+
let uploadData = null;
|
|
100
|
+
file.stream.on('data', async (chunk) => {
|
|
101
|
+
file.stream.pause();
|
|
102
|
+
const startBite = prevChunk + 1;
|
|
103
|
+
const endBite = prevChunk + chunk.length;
|
|
104
|
+
const uploadRes = await fetch(uploadUrl, {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
body: chunk,
|
|
107
|
+
headers: {
|
|
108
|
+
'Content-Disposition': `attachment; filename="${file.fileName}"`,
|
|
109
|
+
'Content-Range': `bytes ${startBite}-${endBite}/${file.contentLength}`,
|
|
110
|
+
},
|
|
111
|
+
signal: abortController?.signal,
|
|
112
|
+
});
|
|
113
|
+
if (uploadRes.status >= 400) {
|
|
114
|
+
const error = await uploadRes.json();
|
|
115
|
+
throw new api_1.MaxError(uploadRes.status, error);
|
|
116
|
+
}
|
|
117
|
+
if (!uploadData) {
|
|
118
|
+
uploadData = await uploadRes.json();
|
|
119
|
+
}
|
|
120
|
+
file.stream.resume();
|
|
121
|
+
prevChunk += chunk.length;
|
|
122
|
+
});
|
|
123
|
+
file.stream.on('end', async () => {
|
|
124
|
+
if (!uploadData) {
|
|
125
|
+
reject(new Error('Failed to upload'));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
resolve(uploadData);
|
|
129
|
+
});
|
|
130
|
+
file.stream.on('error', (err) => {
|
|
131
|
+
reject(err);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
this.uploadFromBuffer = async ({ file, uploadUrl, abortController }) => {
|
|
136
|
+
const formData = new FormData();
|
|
137
|
+
formData.append('data', new Blob([file.buffer]), file.fileName);
|
|
138
|
+
const res = await fetch(uploadUrl, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
body: formData,
|
|
141
|
+
signal: abortController?.signal,
|
|
142
|
+
});
|
|
143
|
+
return await res.json();
|
|
144
|
+
};
|
|
145
|
+
this.image = async ({ timeout, ...source }) => {
|
|
146
|
+
if ('url' in source) {
|
|
147
|
+
return { url: source.url };
|
|
148
|
+
}
|
|
149
|
+
const fileBlob = await this.getStreamFromSource(source.source);
|
|
150
|
+
return this.upload('image', fileBlob, { timeout });
|
|
151
|
+
};
|
|
152
|
+
this.video = async ({ source, ...options }) => {
|
|
153
|
+
const fileBlob = await this.getStreamFromSource(source);
|
|
154
|
+
return this.upload('video', fileBlob, options);
|
|
155
|
+
};
|
|
156
|
+
this.file = async ({ source, ...options }) => {
|
|
157
|
+
const fileBlob = await this.getStreamFromSource(source);
|
|
158
|
+
return this.upload('file', fileBlob, options);
|
|
159
|
+
};
|
|
160
|
+
this.audio = async ({ source, ...options }) => {
|
|
161
|
+
const fileBlob = await this.getStreamFromSource(source);
|
|
162
|
+
return this.upload('audio', fileBlob, options);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.Upload = Upload;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Client } from './client';
|
|
2
|
+
import type { ApiMethods } from './modules/types';
|
|
3
|
+
type ApiCallFn<HTTPMethod extends keyof ApiMethods> = <Method extends keyof ApiMethods[HTTPMethod]>(method: Method, options: ApiMethods[HTTPMethod][Method]['req']) => Promise<ApiMethods[HTTPMethod][Method]['res']>;
|
|
4
|
+
export declare class BaseApi {
|
|
5
|
+
private readonly call;
|
|
6
|
+
constructor(client: Client);
|
|
7
|
+
private callApi;
|
|
8
|
+
protected _get: ApiCallFn<'GET'>;
|
|
9
|
+
protected _post: ApiCallFn<'POST'>;
|
|
10
|
+
protected _patch: ApiCallFn<'PATCH'>;
|
|
11
|
+
protected _put: ApiCallFn<'PUT'>;
|
|
12
|
+
protected _delete: ApiCallFn<'DELETE'>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseApi = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
class BaseApi {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.callApi = async (method, options) => {
|
|
8
|
+
const result = await this.call({
|
|
9
|
+
method,
|
|
10
|
+
options,
|
|
11
|
+
});
|
|
12
|
+
if (result.status !== 200) {
|
|
13
|
+
throw new error_1.MaxError(result.status, result.data);
|
|
14
|
+
}
|
|
15
|
+
return result.data;
|
|
16
|
+
};
|
|
17
|
+
this._get = async (method, options) => {
|
|
18
|
+
return this.callApi(method, { ...options, method: 'GET' });
|
|
19
|
+
};
|
|
20
|
+
this._post = async (method, options) => {
|
|
21
|
+
return this.callApi(method, { ...options, method: 'POST' });
|
|
22
|
+
};
|
|
23
|
+
this._patch = async (method, options) => {
|
|
24
|
+
return this.callApi(method, { ...options, method: 'PATCH' });
|
|
25
|
+
};
|
|
26
|
+
this._put = async (method, options) => {
|
|
27
|
+
return this.callApi(method, { ...options, method: 'PUT' });
|
|
28
|
+
};
|
|
29
|
+
this._delete = async (method, options) => {
|
|
30
|
+
return this.callApi(method, { ...options, method: 'DELETE' });
|
|
31
|
+
};
|
|
32
|
+
this.call = client.call;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.BaseApi = BaseApi;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare const defaultOptions: {
|
|
2
|
+
readonly baseUrl: "https://botapi.max.ru";
|
|
3
|
+
};
|
|
4
|
+
export type ClientOptions = Partial<typeof defaultOptions>;
|
|
5
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
6
|
+
export type ReqOptions = {
|
|
7
|
+
method?: HTTPMethod;
|
|
8
|
+
body?: object | null;
|
|
9
|
+
query?: Record<string, string | number | boolean | null | undefined>;
|
|
10
|
+
path?: Record<string, string | number>;
|
|
11
|
+
};
|
|
12
|
+
type CallOptions = {
|
|
13
|
+
method: string;
|
|
14
|
+
options: ReqOptions;
|
|
15
|
+
};
|
|
16
|
+
export declare const createClient: (token: string, options?: ClientOptions) => {
|
|
17
|
+
call: ({ method, options: callOptions }: CallOptions) => Promise<{
|
|
18
|
+
status: number;
|
|
19
|
+
data: any;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
export type Client = ReturnType<typeof createClient>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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.createClient = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const debug = (0, debug_1.default)('one-me:client');
|
|
9
|
+
const defaultOptions = {
|
|
10
|
+
baseUrl: 'https://botapi.max.ru',
|
|
11
|
+
};
|
|
12
|
+
const createClient = (token, options = {}) => {
|
|
13
|
+
const { baseUrl } = { ...defaultOptions, ...options };
|
|
14
|
+
const call = async ({ method, options: callOptions }) => {
|
|
15
|
+
const httpMethod = callOptions.method || 'GET';
|
|
16
|
+
debug(`Call method ${httpMethod} /${method}`, JSON.stringify(callOptions, null, 2));
|
|
17
|
+
if (!token) {
|
|
18
|
+
return {
|
|
19
|
+
status: 401,
|
|
20
|
+
data: {
|
|
21
|
+
code: 'verify.token',
|
|
22
|
+
message: 'Empty access_token',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const url = new URL(buildUrl(method, token, callOptions.path), baseUrl);
|
|
27
|
+
Object.keys(callOptions.query ?? {}).forEach((param) => {
|
|
28
|
+
const value = callOptions.query?.[param];
|
|
29
|
+
if (!value)
|
|
30
|
+
return;
|
|
31
|
+
url.searchParams.set(param, value.toString());
|
|
32
|
+
});
|
|
33
|
+
const init = { ...getResponseInit(callOptions?.body), method: httpMethod };
|
|
34
|
+
const res = await fetch(url.href, init);
|
|
35
|
+
if (res.status === 401) {
|
|
36
|
+
return {
|
|
37
|
+
status: 401,
|
|
38
|
+
data: {
|
|
39
|
+
code: 'verify.token',
|
|
40
|
+
message: 'Invalid access_token',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
status: res.status,
|
|
46
|
+
data: await res.json(),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
return { call };
|
|
50
|
+
};
|
|
51
|
+
exports.createClient = createClient;
|
|
52
|
+
const getResponseInit = (body) => {
|
|
53
|
+
if (!body)
|
|
54
|
+
return {};
|
|
55
|
+
return {
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
headers: {
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const buildUrl = (baseUrl, token, path) => {
|
|
63
|
+
let url = baseUrl;
|
|
64
|
+
if (path) {
|
|
65
|
+
Object.keys(path)?.forEach((key) => {
|
|
66
|
+
const regexp = new RegExp(`{${key}}`, 'g');
|
|
67
|
+
const value = path[key].toString();
|
|
68
|
+
url = url.replace(regexp, value);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return `${url}?access_token=${token}`;
|
|
72
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ErrorResponse = {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class MaxError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
private readonly response;
|
|
8
|
+
constructor(status: number, response: ErrorResponse);
|
|
9
|
+
get code(): string;
|
|
10
|
+
get description(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaxError = void 0;
|
|
4
|
+
class MaxError extends Error {
|
|
5
|
+
constructor(status, response) {
|
|
6
|
+
super(`${status}: ${response.message}`);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.response = response;
|
|
9
|
+
}
|
|
10
|
+
get code() {
|
|
11
|
+
return this.response.code;
|
|
12
|
+
}
|
|
13
|
+
get description() {
|
|
14
|
+
return this.response.message;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.MaxError = MaxError;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
exports.RawApi = exports.MaxError = exports.createClient = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./modules/types"), exports);
|
|
20
|
+
var client_1 = require("./client");
|
|
21
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
|
|
22
|
+
var error_1 = require("./error");
|
|
23
|
+
Object.defineProperty(exports, "MaxError", { enumerable: true, get: function () { return error_1.MaxError; } });
|
|
24
|
+
var raw_api_1 = require("./raw-api");
|
|
25
|
+
Object.defineProperty(exports, "RawApi", { enumerable: true, get: function () { return raw_api_1.RawApi; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseApi } from '../../base-api';
|
|
2
|
+
import type { FlattenReq } from '../types';
|
|
3
|
+
import type { EditMyInfoDTO } from './types';
|
|
4
|
+
export declare class BotsApi extends BaseApi {
|
|
5
|
+
getMyInfo: () => Promise<import("../..").BotInfo>;
|
|
6
|
+
editMyInfo: ({ ...body }: FlattenReq<EditMyInfoDTO>) => Promise<import("../..").BotInfo>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotsApi = void 0;
|
|
4
|
+
const base_api_1 = require("../../base-api");
|
|
5
|
+
class BotsApi extends base_api_1.BaseApi {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.getMyInfo = async () => {
|
|
9
|
+
return this._get('me', {});
|
|
10
|
+
};
|
|
11
|
+
this.editMyInfo = async ({ ...body }) => {
|
|
12
|
+
return this._patch('me', { body });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BotsApi = BotsApi;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BotCommand, BotInfo, PhotoAttachmentRequestPayload } from '../../types';
|
|
2
|
+
export type GetMyInfoResponse = BotInfo;
|
|
3
|
+
export type EditMyInfoDTO = {
|
|
4
|
+
body: {
|
|
5
|
+
name?: string | null;
|
|
6
|
+
description?: string | null;
|
|
7
|
+
commands?: BotCommand[] | null;
|
|
8
|
+
photo?: PhotoAttachmentRequestPayload;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type EditMyInfoResponse = BotInfo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseApi } from '../../base-api';
|
|
2
|
+
import type { FlattenReq } from '../types';
|
|
3
|
+
import type { AddChatMembersDTO, AddChatMembersResponse, EditChatInfoDTO, EditChatInfoResponse, GetAllChatsDTO, GetAllChatsResponse, GetChatAdminsDTO, GetChatAdminsResponse, GetChatByIdDTO, GetChatByIdResponse, GetChatByLinkDTO, GetChatByLinkResponse, GetChatMembersDTO, GetChatMembershipDTO, GetChatMembershipResponse, GetChatMembersResponse, GetPinnedMessageDTO, GetPinnedMessageResponse, LeaveChatDTO, LeaveChatResponse, PinMessageDTO, PinMessageResponse, RemoveChatMemberDTO, RemoveChatMemberResponse, SendActionDTO, SendActionResponse, UnpinMessageDTO, UnpinMessageResponse } from './types';
|
|
4
|
+
export declare class ChatsApi extends BaseApi {
|
|
5
|
+
getAll({ ...query }: FlattenReq<GetAllChatsDTO>): Promise<GetAllChatsResponse>;
|
|
6
|
+
getById({ chat_id }: FlattenReq<GetChatByIdDTO>): Promise<GetChatByIdResponse>;
|
|
7
|
+
getByLink({ chat_link }: FlattenReq<GetChatByLinkDTO>): Promise<GetChatByLinkResponse>;
|
|
8
|
+
edit({ chat_id, ...body }: FlattenReq<EditChatInfoDTO>): Promise<EditChatInfoResponse>;
|
|
9
|
+
getChatMembership({ chat_id }: FlattenReq<GetChatMembershipDTO>): Promise<GetChatMembershipResponse>;
|
|
10
|
+
getChatAdmins({ chat_id }: FlattenReq<GetChatAdminsDTO>): Promise<GetChatAdminsResponse>;
|
|
11
|
+
addChatMembers({ chat_id, ...body }: FlattenReq<AddChatMembersDTO>): Promise<AddChatMembersResponse>;
|
|
12
|
+
getChatMembers({ chat_id, ...query }: FlattenReq<GetChatMembersDTO>): Promise<GetChatMembersResponse>;
|
|
13
|
+
removeChatMember({ chat_id, ...body }: FlattenReq<RemoveChatMemberDTO>): Promise<RemoveChatMemberResponse>;
|
|
14
|
+
getPinnedMessage({ chat_id }: FlattenReq<GetPinnedMessageDTO>): Promise<GetPinnedMessageResponse>;
|
|
15
|
+
pinMessage({ chat_id, ...body }: FlattenReq<PinMessageDTO>): Promise<PinMessageResponse>;
|
|
16
|
+
unpinMessage({ chat_id }: FlattenReq<UnpinMessageDTO>): Promise<UnpinMessageResponse>;
|
|
17
|
+
sendAction({ chat_id, ...body }: FlattenReq<SendActionDTO>): Promise<SendActionResponse>;
|
|
18
|
+
leaveChat({ chat_id }: FlattenReq<LeaveChatDTO>): Promise<LeaveChatResponse>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatsApi = void 0;
|
|
4
|
+
const base_api_1 = require("../../base-api");
|
|
5
|
+
class ChatsApi extends base_api_1.BaseApi {
|
|
6
|
+
async getAll({ ...query }) {
|
|
7
|
+
return this._get('chats', {
|
|
8
|
+
query,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
async getById({ chat_id }) {
|
|
12
|
+
return this._get('chats/{chat_id}', {
|
|
13
|
+
path: { chat_id },
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async getByLink({ chat_link }) {
|
|
17
|
+
return this._get('chats/{chat_link}', {
|
|
18
|
+
path: { chat_link },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async edit({ chat_id, ...body }) {
|
|
22
|
+
return this._patch('chats/{chat_id}', {
|
|
23
|
+
path: { chat_id },
|
|
24
|
+
body,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async getChatMembership({ chat_id }) {
|
|
28
|
+
return this._get('chats/{chat_id}/members/me', {
|
|
29
|
+
path: { chat_id },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async getChatAdmins({ chat_id }) {
|
|
33
|
+
return this._get('chats/{chat_id}/members/admins', {
|
|
34
|
+
path: { chat_id },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async addChatMembers({ chat_id, ...body }) {
|
|
38
|
+
return this._post('chats/{chat_id}/members', {
|
|
39
|
+
path: { chat_id },
|
|
40
|
+
body,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async getChatMembers({ chat_id, ...query }) {
|
|
44
|
+
return this._get('chats/{chat_id}/members', {
|
|
45
|
+
path: { chat_id },
|
|
46
|
+
query,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async removeChatMember({ chat_id, ...body }) {
|
|
50
|
+
return this._delete('chats/{chat_id}/members', {
|
|
51
|
+
path: { chat_id },
|
|
52
|
+
body,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async getPinnedMessage({ chat_id }) {
|
|
56
|
+
return this._get('chats/{chat_id}/pin', {
|
|
57
|
+
path: { chat_id },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async pinMessage({ chat_id, ...body }) {
|
|
61
|
+
return this._put('chats/{chat_id}/pin', {
|
|
62
|
+
path: { chat_id },
|
|
63
|
+
body,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async unpinMessage({ chat_id }) {
|
|
67
|
+
return this._delete('chats/{chat_id}/pin', {
|
|
68
|
+
path: { chat_id },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async sendAction({ chat_id, ...body }) {
|
|
72
|
+
return this._post('chats/{chat_id}/actions', {
|
|
73
|
+
path: { chat_id },
|
|
74
|
+
body,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async leaveChat({ chat_id }) {
|
|
78
|
+
return this._delete('chats/{chat_id}/members/me', {
|
|
79
|
+
path: { chat_id },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ChatsApi = ChatsApi;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ActionResponse, Chat, ChatMember, Message, type PhotoAttachmentRequestPayload, SenderAction } from '../../types';
|
|
2
|
+
import { FlattenReq } from '../types';
|
|
3
|
+
export type GetAllChatsDTO = {
|
|
4
|
+
query: {
|
|
5
|
+
count?: number;
|
|
6
|
+
marker?: number | null;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export type GetAllChatsExtra = FlattenReq<GetAllChatsDTO>;
|
|
10
|
+
type DefaultPath = {
|
|
11
|
+
chat_id: number;
|
|
12
|
+
};
|
|
13
|
+
export type GetAllChatsResponse = {
|
|
14
|
+
chats: Chat[];
|
|
15
|
+
marker: number | null;
|
|
16
|
+
};
|
|
17
|
+
export type GetChatByIdDTO = {
|
|
18
|
+
path: DefaultPath;
|
|
19
|
+
};
|
|
20
|
+
export type GetChatByIdResponse = Chat;
|
|
21
|
+
export type GetChatByLinkDTO = {
|
|
22
|
+
path: {
|
|
23
|
+
chat_link: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type GetChatByLinkResponse = Chat;
|
|
27
|
+
export type EditChatInfoDTO = {
|
|
28
|
+
path: DefaultPath;
|
|
29
|
+
body: {
|
|
30
|
+
icon?: PhotoAttachmentRequestPayload | null;
|
|
31
|
+
title?: string | null;
|
|
32
|
+
pin?: string | null;
|
|
33
|
+
notify?: boolean | null;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type EditChatExtra = Omit<FlattenReq<EditChatInfoDTO>, 'chat_id'>;
|
|
37
|
+
export type EditChatInfoResponse = Chat;
|
|
38
|
+
export type SendActionDTO = {
|
|
39
|
+
path: DefaultPath;
|
|
40
|
+
body: {
|
|
41
|
+
action: SenderAction;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type SendActionResponse = ActionResponse;
|
|
45
|
+
export type GetPinnedMessageDTO = {
|
|
46
|
+
path: DefaultPath;
|
|
47
|
+
};
|
|
48
|
+
export type GetPinnedMessageResponse = {
|
|
49
|
+
message: Message | null;
|
|
50
|
+
};
|
|
51
|
+
export type PinMessageDTO = {
|
|
52
|
+
path: DefaultPath;
|
|
53
|
+
body: {
|
|
54
|
+
message_id: string;
|
|
55
|
+
notify?: boolean | null;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export type PinMessageExtra = Omit<FlattenReq<PinMessageDTO>, 'chat_id' | 'message_id'>;
|
|
59
|
+
export type PinMessageResponse = ActionResponse;
|
|
60
|
+
export type UnpinMessageDTO = {
|
|
61
|
+
path: DefaultPath;
|
|
62
|
+
};
|
|
63
|
+
export type UnpinMessageResponse = ActionResponse;
|
|
64
|
+
export type GetChatMembershipDTO = {
|
|
65
|
+
path: DefaultPath;
|
|
66
|
+
};
|
|
67
|
+
export type GetChatMembershipResponse = ChatMember;
|
|
68
|
+
export type LeaveChatDTO = {
|
|
69
|
+
path: DefaultPath;
|
|
70
|
+
};
|
|
71
|
+
export type LeaveChatResponse = ActionResponse;
|
|
72
|
+
export type GetChatAdminsDTO = {
|
|
73
|
+
path: DefaultPath;
|
|
74
|
+
};
|
|
75
|
+
export type GetChatAdminsResponse = {
|
|
76
|
+
members: ChatMember[];
|
|
77
|
+
marker?: number | null;
|
|
78
|
+
};
|
|
79
|
+
export type GetChatMembersDTO = {
|
|
80
|
+
path: DefaultPath;
|
|
81
|
+
query: {
|
|
82
|
+
user_ids?: string;
|
|
83
|
+
marker?: number;
|
|
84
|
+
count?: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export type GetChatMembersExtra = Omit<FlattenReq<GetChatMembersDTO>, 'chat_id' | 'user_ids'> & {
|
|
88
|
+
user_ids?: number[];
|
|
89
|
+
};
|
|
90
|
+
export type GetChatMembersResponse = {
|
|
91
|
+
members: ChatMember[];
|
|
92
|
+
marker?: number | null;
|
|
93
|
+
};
|
|
94
|
+
export type AddChatMembersDTO = {
|
|
95
|
+
path: DefaultPath;
|
|
96
|
+
body: {
|
|
97
|
+
user_ids: number[];
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
export type AddChatMembersResponse = ActionResponse;
|
|
101
|
+
export type RemoveChatMemberDTO = {
|
|
102
|
+
path: DefaultPath;
|
|
103
|
+
body: {
|
|
104
|
+
user_id: number;
|
|
105
|
+
block?: boolean;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
export type RemoveChatMemberResponse = ActionResponse;
|
|
109
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { BaseApi } from '../base-api';
|
|
2
|
+
export { FlattenReq } from './types';
|
|
3
|
+
export { BotsApi } from './bots/api';
|
|
4
|
+
export * from './bots/types';
|
|
5
|
+
export { MessagesApi } from './messages/api';
|
|
6
|
+
export * from './messages/types';
|
|
7
|
+
export { SubscriptionsApi } from './subscriptions/api';
|
|
8
|
+
export * from './subscriptions/types';
|
|
9
|
+
export { UploadsApi } from './uploads/api';
|
|
10
|
+
export * from './uploads/types';
|
|
11
|
+
export { ChatsApi } from './chats/api';
|
|
12
|
+
export * from './chats/types';
|