rubjs 3.1.4 → 3.2.0
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/README.md +3 -0
- package/lib/core/bot/bot.d.ts +2 -2
- package/lib/core/bot/bot.js +3 -3
- package/lib/core/bot/contexts/message.context.d.ts +3 -3
- package/lib/core/bot/contexts/message.context.js +2 -2
- package/lib/core/bot/contexts/update.context.d.ts +17 -0
- package/lib/core/bot/contexts/update.context.js +39 -0
- package/lib/core/bot/filters.d.ts +1 -1
- package/lib/core/bot/methods/files/_sendFile.d.ts +4 -0
- package/lib/core/bot/methods/files/_sendFile.js +37 -0
- package/lib/core/bot/methods/files/index.d.ts +2 -1
- package/lib/core/bot/methods/files/index.js +3 -1
- package/lib/core/bot/methods/files/uploadFile.d.ts +1 -1
- package/lib/core/bot/methods/files/uploadFile.js +10 -12
- package/lib/core/bot/methods/index.d.ts +20 -13
- package/lib/core/bot/methods/index.js +21 -0
- package/lib/core/bot/methods/messages/index.d.ts +7 -1
- package/lib/core/bot/methods/messages/index.js +13 -1
- package/lib/core/bot/methods/messages/sendFile.d.ts +4 -0
- package/lib/core/bot/methods/messages/sendFile.js +7 -0
- package/lib/core/bot/methods/messages/sendGif.d.ts +4 -0
- package/lib/core/bot/methods/messages/sendGif.js +7 -0
- package/lib/core/bot/methods/messages/sendImage.d.ts +4 -0
- package/lib/core/bot/methods/messages/sendImage.js +7 -0
- package/lib/core/bot/methods/messages/sendMessage.js +10 -5
- package/lib/core/bot/methods/messages/sendMusic.d.ts +4 -0
- package/lib/core/bot/methods/messages/sendMusic.js +7 -0
- package/lib/core/bot/methods/messages/sendVideo.d.ts +4 -0
- package/lib/core/bot/methods/messages/sendVideo.js +7 -0
- package/lib/core/bot/methods/messages/sendVoice.d.ts +4 -0
- package/lib/core/bot/methods/messages/sendVoice.js +7 -0
- package/lib/core/bot/methods/utilities/handleUpdates.js +3 -3
- package/lib/core/bot/types/bot.type.d.ts +2 -2
- package/lib/core/bot/types/models.d.ts +7 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,9 @@ bot.run();
|
|
|
72
72
|
### ابزارهای داخلی توسعه
|
|
73
73
|
مثل `Utils.Bold`, `Utils.Italic` و ... برای زیباتر کردن پاسخها به کاربر.
|
|
74
74
|
|
|
75
|
+
### راه اندازی وبسایت همزمان با ربات
|
|
76
|
+
با rubjs میتوانید ربات را همزمان با وبسایت استقرار کنید | [اموزش](https://hadi-rostami.github.io/rubjs-docs/blog/running-website-and-bot-simultaneously-with-rubjs)
|
|
77
|
+
|
|
75
78
|
|
|
76
79
|
</div>
|
|
77
80
|
|
package/lib/core/bot/bot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import SessionManager from '../../utils/session';
|
|
2
|
-
import Message from './contexts/
|
|
2
|
+
import Message from './contexts/update.context';
|
|
3
3
|
import Methods from './methods';
|
|
4
4
|
import Network from './network';
|
|
5
5
|
import { BotType, ContextMap, Handler, NestedFilter, SessionType } from './types/bot.type';
|
|
@@ -20,6 +20,6 @@ declare class Bot extends Methods {
|
|
|
20
20
|
on<T extends keyof typeof this.handlers>(type: T, handler: (ctx: ContextMap[T]) => Promise<void>): void;
|
|
21
21
|
on<T extends keyof typeof this.handlers>(type: T, filters: NestedFilter<ContextMap[T]>, handler: (ctx: ContextMap[T]) => Promise<void>): void;
|
|
22
22
|
command(prefix: string | RegExp, handler: (ctx: Message) => Promise<void>): void;
|
|
23
|
-
command(prefix: string | RegExp, filters: NestedFilter<ContextMap['
|
|
23
|
+
command(prefix: string | RegExp, filters: NestedFilter<ContextMap['update']>, handler: (ctx: Message) => Promise<void>): void;
|
|
24
24
|
}
|
|
25
25
|
export default Bot;
|
package/lib/core/bot/bot.js
CHANGED
|
@@ -14,7 +14,7 @@ class Bot extends methods_1.default {
|
|
|
14
14
|
this.BASE_URL = `https://botapi.rubika.ir/v3`;
|
|
15
15
|
this.initialize = false;
|
|
16
16
|
this.sendToken = '';
|
|
17
|
-
this.handlers = { inline: [],
|
|
17
|
+
this.handlers = { inline: [], update: [] };
|
|
18
18
|
this.sessionDB = new session_1.default(token, undefined, 'BOT');
|
|
19
19
|
this.network = new network_1.default(this);
|
|
20
20
|
this.server = (0, fastify_1.default)();
|
|
@@ -36,14 +36,14 @@ class Bot extends methods_1.default {
|
|
|
36
36
|
}
|
|
37
37
|
command(prefix, filtersOrHandler, maybeHandler) {
|
|
38
38
|
if (typeof filtersOrHandler === 'function') {
|
|
39
|
-
this.handlers.
|
|
39
|
+
this.handlers.update.push({
|
|
40
40
|
filters: [],
|
|
41
41
|
handler: filtersOrHandler,
|
|
42
42
|
prefix,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
else if (Array.isArray(filtersOrHandler) && maybeHandler) {
|
|
46
|
-
this.handlers.
|
|
46
|
+
this.handlers.update.push({
|
|
47
47
|
filters: filtersOrHandler,
|
|
48
48
|
handler: maybeHandler,
|
|
49
49
|
prefix,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bot } from '../../..';
|
|
2
|
-
import { PaymentStatus, Update, UpdateTypeEnum, Message as MessageUpdate, Keypad, ChatKeypadTypeEnum, InlineKeypad } from '../types/models';
|
|
3
|
-
declare class
|
|
2
|
+
import { PaymentStatus, Update as UpdateMessage, UpdateTypeEnum, Message as MessageUpdate, Keypad, ChatKeypadTypeEnum, InlineKeypad } from '../types/models';
|
|
3
|
+
declare class Update implements UpdateMessage {
|
|
4
4
|
type: UpdateTypeEnum;
|
|
5
5
|
chat_id: string;
|
|
6
6
|
removed_message_id?: string;
|
|
@@ -14,4 +14,4 @@ declare class Message implements Update {
|
|
|
14
14
|
forward(to_chat_id: string, disable_notification?: boolean): Promise<import("../types/models").SendMessage | undefined>;
|
|
15
15
|
delete(): Promise<import("../types/models").SendMessage | undefined>;
|
|
16
16
|
}
|
|
17
|
-
export default
|
|
17
|
+
export default Update;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class
|
|
3
|
+
class Update {
|
|
4
4
|
constructor(bot, update) {
|
|
5
5
|
this.store = {};
|
|
6
6
|
Object.defineProperty(this, 'bot', {
|
|
@@ -36,4 +36,4 @@ class Message {
|
|
|
36
36
|
return await this.bot.deleteMessage(this.chat_id, message_id);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
exports.default =
|
|
39
|
+
exports.default = Update;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Bot } from '../../..';
|
|
2
|
+
import { PaymentStatus, Update as UpdateMessage, UpdateTypeEnum, Message as MessageUpdate, Keypad, ChatKeypadTypeEnum, InlineKeypad } from '../types/models';
|
|
3
|
+
declare class Update implements UpdateMessage {
|
|
4
|
+
type: UpdateTypeEnum;
|
|
5
|
+
chat_id: string;
|
|
6
|
+
removed_message_id?: string;
|
|
7
|
+
new_message?: MessageUpdate;
|
|
8
|
+
updated_message?: MessageUpdate;
|
|
9
|
+
updated_payment?: PaymentStatus;
|
|
10
|
+
store: Record<string, any>;
|
|
11
|
+
bot: Bot;
|
|
12
|
+
constructor(bot: Bot, update: Update);
|
|
13
|
+
reply(text: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../types/models").SendMessage>;
|
|
14
|
+
forward(to_chat_id: string, disable_notification?: boolean): Promise<import("../types/models").SendMessage | undefined>;
|
|
15
|
+
delete(): Promise<import("../types/models").SendMessage | undefined>;
|
|
16
|
+
}
|
|
17
|
+
export default Update;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Update {
|
|
4
|
+
constructor(bot, update) {
|
|
5
|
+
this.store = {};
|
|
6
|
+
Object.defineProperty(this, 'bot', {
|
|
7
|
+
value: bot,
|
|
8
|
+
enumerable: false,
|
|
9
|
+
writable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
});
|
|
12
|
+
this.type = update.type;
|
|
13
|
+
this.chat_id = update.chat_id;
|
|
14
|
+
if (update?.new_message)
|
|
15
|
+
this.new_message = update?.new_message;
|
|
16
|
+
if (update?.updated_message)
|
|
17
|
+
this.updated_message = update?.updated_message;
|
|
18
|
+
if (update?.updated_payment)
|
|
19
|
+
this.updated_payment = update?.updated_payment;
|
|
20
|
+
if (update.removed_message_id)
|
|
21
|
+
this.removed_message_id = update.removed_message_id;
|
|
22
|
+
}
|
|
23
|
+
async reply(text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
24
|
+
return await this.bot.sendMessage(this.chat_id, text, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
25
|
+
}
|
|
26
|
+
async forward(to_chat_id, disable_notification = false) {
|
|
27
|
+
const message_id = this.new_message?.message_id || this.updated_message?.message_id;
|
|
28
|
+
if (!message_id)
|
|
29
|
+
return;
|
|
30
|
+
return await this.bot.forwardMessage(this.chat_id, message_id, to_chat_id, disable_notification);
|
|
31
|
+
}
|
|
32
|
+
async delete() {
|
|
33
|
+
const message_id = this.new_message?.message_id || this.updated_message?.message_id;
|
|
34
|
+
if (!message_id)
|
|
35
|
+
return;
|
|
36
|
+
return await this.bot.deleteMessage(this.chat_id, message_id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = Update;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, FileTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function _sendFile(this: Bot, chat_id: string, path_file: string, text?: string, type?: FileTypeEnum, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<any>;
|
|
4
|
+
export default _sendFile;
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const models_1 = require("../../types/models");
|
|
8
|
+
async function _sendFile(chat_id, path_file, text, type = models_1.FileTypeEnum.File, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
9
|
+
if (!fs_1.default.existsSync(path_file)) {
|
|
10
|
+
throw new Error('');
|
|
11
|
+
}
|
|
12
|
+
const { upload_url } = await this.requestSendFile(type);
|
|
13
|
+
const { data: { file_id }, } = await this.uploadFile(upload_url, path_file);
|
|
14
|
+
const data = {
|
|
15
|
+
chat_id,
|
|
16
|
+
file_id,
|
|
17
|
+
disable_notification,
|
|
18
|
+
};
|
|
19
|
+
if (text)
|
|
20
|
+
data.text = text;
|
|
21
|
+
if (chat_keypad)
|
|
22
|
+
data.chat_keypad = chat_keypad;
|
|
23
|
+
if (inline_keypad)
|
|
24
|
+
data.inline_keypad = inline_keypad;
|
|
25
|
+
if (chat_keypad_type)
|
|
26
|
+
data.chat_keypad_type = chat_keypad_type;
|
|
27
|
+
if (reply_to_message_id)
|
|
28
|
+
data.reply_to_message_id = reply_to_message_id;
|
|
29
|
+
if (chat_keypad && !chat_keypad_type) {
|
|
30
|
+
data.chat_keypad_type = models_1.ChatKeypadTypeEnum.New;
|
|
31
|
+
}
|
|
32
|
+
if (inline_keypad && chat_keypad_type) {
|
|
33
|
+
data.chat_keypad_type = models_1.ChatKeypadTypeEnum.None;
|
|
34
|
+
}
|
|
35
|
+
return await this.builder('sendFile', data);
|
|
36
|
+
}
|
|
37
|
+
exports.default = _sendFile;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import getFile from './getFile';
|
|
2
2
|
import requestSendFile from './requestSendFile';
|
|
3
|
+
import _sendFile from './_sendFile';
|
|
3
4
|
import uploadFile from './uploadFile';
|
|
4
|
-
export { getFile, requestSendFile, uploadFile };
|
|
5
|
+
export { getFile, requestSendFile, uploadFile, _sendFile };
|
|
@@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.uploadFile = exports.requestSendFile = exports.getFile = void 0;
|
|
6
|
+
exports._sendFile = exports.uploadFile = exports.requestSendFile = exports.getFile = void 0;
|
|
7
7
|
const getFile_1 = __importDefault(require("./getFile"));
|
|
8
8
|
exports.getFile = getFile_1.default;
|
|
9
9
|
const requestSendFile_1 = __importDefault(require("./requestSendFile"));
|
|
10
10
|
exports.requestSendFile = requestSendFile_1.default;
|
|
11
|
+
const _sendFile_1 = __importDefault(require("./_sendFile"));
|
|
12
|
+
exports._sendFile = _sendFile_1.default;
|
|
11
13
|
const uploadFile_1 = __importDefault(require("./uploadFile"));
|
|
12
14
|
exports.uploadFile = uploadFile_1.default;
|
|
@@ -6,27 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const undici_1 = require("undici");
|
|
8
8
|
const form_data_1 = __importDefault(require("form-data"));
|
|
9
|
-
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
async function uploadFile(url, filePath) {
|
|
10
11
|
if (!fs_1.default.existsSync(filePath)) {
|
|
11
12
|
console.error('[ uploadFile ] File not found at:', filePath);
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
15
|
+
const stream = fs_1.default.createReadStream(filePath);
|
|
14
16
|
const form = new form_data_1.default();
|
|
15
|
-
form.append('file',
|
|
16
|
-
|
|
17
|
-
filename: fileName,
|
|
18
|
-
});
|
|
19
|
-
const res = await (0, undici_1.fetch)(url, {
|
|
17
|
+
form.append('file', stream, { filename: (0, path_1.basename)(filePath) });
|
|
18
|
+
const res = await (0, undici_1.request)(url, {
|
|
20
19
|
method: 'POST',
|
|
21
20
|
body: form,
|
|
22
21
|
headers: form.getHeaders(),
|
|
23
|
-
dispatcher: this.network.agent,
|
|
24
22
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const response = await res.body.json();
|
|
24
|
+
if (res.statusCode !== 200 || response.status !== 'OK') {
|
|
25
|
+
const text = await res.body.text();
|
|
26
|
+
throw new Error(`HTTP ${res.statusCode}: ${text}`);
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
return data.data.file_id;
|
|
28
|
+
return response;
|
|
31
29
|
}
|
|
32
30
|
exports.default = uploadFile;
|
|
@@ -6,25 +6,32 @@ import * as Files from './files';
|
|
|
6
6
|
import * as Messages from './messages';
|
|
7
7
|
import * as Chat from './chat';
|
|
8
8
|
import * as Settings from './settings';
|
|
9
|
-
import
|
|
9
|
+
import * as Types from '../types/models';
|
|
10
10
|
export default class Methods {
|
|
11
11
|
builder(this: Bot, ...args: Parameters<typeof Advanced.builder>): Promise<any>;
|
|
12
|
-
getMe(this: Bot, ...args: Parameters<typeof BotMethods.getMe>): Promise<
|
|
12
|
+
getMe(this: Bot, ...args: Parameters<typeof BotMethods.getMe>): Promise<Types.Bot>;
|
|
13
13
|
getFile(this: Bot, ...args: Parameters<typeof Files.getFile>): Promise<any>;
|
|
14
14
|
requestSendFile(this: Bot, ...args: Parameters<typeof Files.requestSendFile>): Promise<{
|
|
15
15
|
upload_url: string;
|
|
16
16
|
}>;
|
|
17
|
-
uploadFile(this: Bot, ...args: Parameters<typeof Files.uploadFile>): Promise<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
uploadFile(this: Bot, ...args: Parameters<typeof Files.uploadFile>): Promise<Types.UploadFile>;
|
|
18
|
+
_sendFile(this: Bot, ...args: Parameters<typeof Files._sendFile>): Promise<Types.SendMessage>;
|
|
19
|
+
sendMessage(this: Bot, ...args: Parameters<typeof Messages.sendMessage>): Promise<Types.SendMessage>;
|
|
20
|
+
sendMusic(this: Bot, ...args: Parameters<typeof Messages.sendMusic>): Promise<Types.SendMessage>;
|
|
21
|
+
sendFile(this: Bot, ...args: Parameters<typeof Messages.sendFile>): Promise<Types.SendMessage>;
|
|
22
|
+
sendGif(this: Bot, ...args: Parameters<typeof Messages.sendGif>): Promise<Types.SendMessage>;
|
|
23
|
+
sendImage(this: Bot, ...args: Parameters<typeof Messages.sendImage>): Promise<Types.SendMessage>;
|
|
24
|
+
sendVideo(this: Bot, ...args: Parameters<typeof Messages.sendVideo>): Promise<Types.SendMessage>;
|
|
25
|
+
sendVoice(this: Bot, ...args: Parameters<typeof Messages.sendVoice>): Promise<Types.SendMessage>;
|
|
26
|
+
sendPoll(this: Bot, ...args: Parameters<typeof Messages.sendPoll>): Promise<Types.SendMessage>;
|
|
27
|
+
sendLocation(this: Bot, ...args: Parameters<typeof Messages.sendLocation>): Promise<Types.SendMessage>;
|
|
28
|
+
sendContact(this: Bot, ...args: Parameters<typeof Messages.sendContact>): Promise<Types.SendMessage>;
|
|
29
|
+
forwardMessage(this: Bot, ...args: Parameters<typeof Messages.forwardMessage>): Promise<Types.SendMessage>;
|
|
30
|
+
editMessageText(this: Bot, ...args: Parameters<typeof Messages.editMessageText>): Promise<Types.SendMessage>;
|
|
31
|
+
deleteMessage(this: Bot, ...args: Parameters<typeof Messages.deleteMessage>): Promise<Types.SendMessage>;
|
|
32
|
+
editMessageKeypad(this: Bot, ...args: Parameters<typeof Messages.editMessageKeypad>): Promise<Types.SendMessage>;
|
|
33
|
+
editChatKeypad(this: Bot, ...args: Parameters<typeof Messages.editChatKeypad>): Promise<Types.SendMessage>;
|
|
34
|
+
getChat(this: Bot, ...args: Parameters<typeof Chat.getChat>): Promise<Types.Chat>;
|
|
28
35
|
start(this: Bot, ...args: Parameters<typeof Utilities.start>): Promise<any>;
|
|
29
36
|
run(this: Bot, ...args: Parameters<typeof Utilities.run>): Promise<any>;
|
|
30
37
|
getUpdates(this: Bot, ...args: Parameters<typeof Utilities.getUpdates>): Promise<any>;
|
|
@@ -60,10 +60,31 @@ class Methods {
|
|
|
60
60
|
async uploadFile(...args) {
|
|
61
61
|
return Files.uploadFile.apply(this, args);
|
|
62
62
|
}
|
|
63
|
+
async _sendFile(...args) {
|
|
64
|
+
return Files._sendFile.apply(this, args);
|
|
65
|
+
}
|
|
63
66
|
// messages
|
|
64
67
|
async sendMessage(...args) {
|
|
65
68
|
return Messages.sendMessage.apply(this, args);
|
|
66
69
|
}
|
|
70
|
+
async sendMusic(...args) {
|
|
71
|
+
return Messages.sendMusic.apply(this, args);
|
|
72
|
+
}
|
|
73
|
+
async sendFile(...args) {
|
|
74
|
+
return Messages.sendFile.apply(this, args);
|
|
75
|
+
}
|
|
76
|
+
async sendGif(...args) {
|
|
77
|
+
return Messages.sendGif.apply(this, args);
|
|
78
|
+
}
|
|
79
|
+
async sendImage(...args) {
|
|
80
|
+
return Messages.sendImage.apply(this, args);
|
|
81
|
+
}
|
|
82
|
+
async sendVideo(...args) {
|
|
83
|
+
return Messages.sendVideo.apply(this, args);
|
|
84
|
+
}
|
|
85
|
+
async sendVoice(...args) {
|
|
86
|
+
return Messages.sendVoice.apply(this, args);
|
|
87
|
+
}
|
|
67
88
|
async sendPoll(...args) {
|
|
68
89
|
return Messages.sendPoll.apply(this, args);
|
|
69
90
|
}
|
|
@@ -4,7 +4,13 @@ import editMessageKeypad from './editMessageKeypad';
|
|
|
4
4
|
import editMessageText from './editMessageText';
|
|
5
5
|
import forwardMessage from './forwardMessage';
|
|
6
6
|
import sendContact from './sendContact';
|
|
7
|
+
import sendFile from './sendFile';
|
|
8
|
+
import sendGif from './sendGif';
|
|
9
|
+
import sendImage from './sendImage';
|
|
7
10
|
import sendLocation from './sendLocation';
|
|
8
11
|
import sendMessage from './sendMessage';
|
|
12
|
+
import sendMusic from './sendMusic';
|
|
9
13
|
import sendPoll from './sendPoll';
|
|
10
|
-
|
|
14
|
+
import sendVideo from './sendVideo';
|
|
15
|
+
import sendVoice from './sendVoice';
|
|
16
|
+
export { sendMessage, sendPoll, sendLocation, sendContact, forwardMessage, editMessageText, deleteMessage, editMessageKeypad, editChatKeypad, sendMusic, sendFile, sendGif, sendImage, sendVideo, sendVoice, };
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.editChatKeypad = exports.editMessageKeypad = exports.deleteMessage = exports.editMessageText = exports.forwardMessage = exports.sendContact = exports.sendLocation = exports.sendPoll = exports.sendMessage = void 0;
|
|
6
|
+
exports.sendVoice = exports.sendVideo = exports.sendImage = exports.sendGif = exports.sendFile = exports.sendMusic = exports.editChatKeypad = exports.editMessageKeypad = exports.deleteMessage = exports.editMessageText = exports.forwardMessage = exports.sendContact = exports.sendLocation = exports.sendPoll = exports.sendMessage = void 0;
|
|
7
7
|
const deleteMessage_1 = __importDefault(require("./deleteMessage"));
|
|
8
8
|
exports.deleteMessage = deleteMessage_1.default;
|
|
9
9
|
const editChatKeypad_1 = __importDefault(require("./editChatKeypad"));
|
|
@@ -16,9 +16,21 @@ const forwardMessage_1 = __importDefault(require("./forwardMessage"));
|
|
|
16
16
|
exports.forwardMessage = forwardMessage_1.default;
|
|
17
17
|
const sendContact_1 = __importDefault(require("./sendContact"));
|
|
18
18
|
exports.sendContact = sendContact_1.default;
|
|
19
|
+
const sendFile_1 = __importDefault(require("./sendFile"));
|
|
20
|
+
exports.sendFile = sendFile_1.default;
|
|
21
|
+
const sendGif_1 = __importDefault(require("./sendGif"));
|
|
22
|
+
exports.sendGif = sendGif_1.default;
|
|
23
|
+
const sendImage_1 = __importDefault(require("./sendImage"));
|
|
24
|
+
exports.sendImage = sendImage_1.default;
|
|
19
25
|
const sendLocation_1 = __importDefault(require("./sendLocation"));
|
|
20
26
|
exports.sendLocation = sendLocation_1.default;
|
|
21
27
|
const sendMessage_1 = __importDefault(require("./sendMessage"));
|
|
22
28
|
exports.sendMessage = sendMessage_1.default;
|
|
29
|
+
const sendMusic_1 = __importDefault(require("./sendMusic"));
|
|
30
|
+
exports.sendMusic = sendMusic_1.default;
|
|
23
31
|
const sendPoll_1 = __importDefault(require("./sendPoll"));
|
|
24
32
|
exports.sendPoll = sendPoll_1.default;
|
|
33
|
+
const sendVideo_1 = __importDefault(require("./sendVideo"));
|
|
34
|
+
exports.sendVideo = sendVideo_1.default;
|
|
35
|
+
const sendVoice_1 = __importDefault(require("./sendVoice"));
|
|
36
|
+
exports.sendVoice = sendVoice_1.default;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function sendFile(this: Bot, chat_id: string, path_file: string, text?: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../../types/models").SendMessage>;
|
|
4
|
+
export default sendFile;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../../types/models");
|
|
4
|
+
async function sendFile(chat_id, path_file, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
|
+
return await this._sendFile(chat_id, path_file, text, models_1.FileTypeEnum.File, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
6
|
+
}
|
|
7
|
+
exports.default = sendFile;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function sendGif(this: Bot, chat_id: string, path_file: string, text?: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../../types/models").SendMessage>;
|
|
4
|
+
export default sendGif;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../../types/models");
|
|
4
|
+
async function sendGif(chat_id, path_file, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
|
+
return await this._sendFile(chat_id, path_file, text, models_1.FileTypeEnum.Gif, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
6
|
+
}
|
|
7
|
+
exports.default = sendGif;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function sendImage(this: Bot, chat_id: string, path_file: string, text?: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../../types/models").SendMessage>;
|
|
4
|
+
export default sendImage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../../types/models");
|
|
4
|
+
async function sendImage(chat_id, path_file, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
|
+
return await this._sendFile(chat_id, path_file, text, models_1.FileTypeEnum.Image, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
6
|
+
}
|
|
7
|
+
exports.default = sendImage;
|
|
@@ -4,13 +4,18 @@ const models_1 = require("../../types/models");
|
|
|
4
4
|
async function sendMessage(chat_id, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
5
|
const data = {
|
|
6
6
|
chat_id,
|
|
7
|
-
text,
|
|
8
|
-
chat_keypad,
|
|
9
|
-
inline_keypad,
|
|
10
7
|
disable_notification,
|
|
11
|
-
reply_to_message_id,
|
|
12
|
-
chat_keypad_type,
|
|
13
8
|
};
|
|
9
|
+
if (text)
|
|
10
|
+
data.text = text;
|
|
11
|
+
if (chat_keypad)
|
|
12
|
+
data.chat_keypad = chat_keypad;
|
|
13
|
+
if (inline_keypad)
|
|
14
|
+
data.inline_keypad = inline_keypad;
|
|
15
|
+
if (chat_keypad_type)
|
|
16
|
+
data.chat_keypad_type = chat_keypad_type;
|
|
17
|
+
if (reply_to_message_id)
|
|
18
|
+
data.reply_to_message_id = reply_to_message_id;
|
|
14
19
|
if (chat_keypad && !chat_keypad_type) {
|
|
15
20
|
data.chat_keypad_type = models_1.ChatKeypadTypeEnum.New;
|
|
16
21
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function sendMusic(this: Bot, chat_id: string, path_file: string, text?: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../../types/models").SendMessage>;
|
|
4
|
+
export default sendMusic;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../../types/models");
|
|
4
|
+
async function sendMusic(chat_id, path_file, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
|
+
return await this._sendFile(chat_id, path_file, text, models_1.FileTypeEnum.Music, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
6
|
+
}
|
|
7
|
+
exports.default = sendMusic;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function sendVideo(this: Bot, chat_id: string, path_file: string, text?: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../../types/models").SendMessage>;
|
|
4
|
+
export default sendVideo;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../../types/models");
|
|
4
|
+
async function sendVideo(chat_id, path_file, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
|
+
return await this._sendFile(chat_id, path_file, text, models_1.FileTypeEnum.Video, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
6
|
+
}
|
|
7
|
+
exports.default = sendVideo;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Bot from '../../bot';
|
|
2
|
+
import { ChatKeypadTypeEnum, InlineKeypad, Keypad } from '../../types/models';
|
|
3
|
+
declare function sendVoice(this: Bot, chat_id: string, path_file: string, text?: string, chat_keypad?: Keypad, inline_keypad?: InlineKeypad, disable_notification?: boolean, reply_to_message_id?: string, chat_keypad_type?: ChatKeypadTypeEnum): Promise<import("../../types/models").SendMessage>;
|
|
4
|
+
export default sendVoice;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../../types/models");
|
|
4
|
+
async function sendVoice(chat_id, path_file, text, chat_keypad, inline_keypad, disable_notification = false, reply_to_message_id, chat_keypad_type) {
|
|
5
|
+
return await this._sendFile(chat_id, path_file, text, models_1.FileTypeEnum.Voice, chat_keypad, inline_keypad, disable_notification, reply_to_message_id, chat_keypad_type);
|
|
6
|
+
}
|
|
7
|
+
exports.default = sendVoice;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const update_context_1 = __importDefault(require("../../contexts/update.context"));
|
|
7
7
|
const inline_context_1 = __importDefault(require("../../contexts/inline.context"));
|
|
8
8
|
const models_1 = require("../../types/models");
|
|
9
9
|
const checkFilters_1 = require("../../../../utils/checkFilters");
|
|
@@ -11,8 +11,8 @@ const checkTypes = [models_1.UpdateTypeEnum.UpdatedMessage, models_1.UpdateTypeE
|
|
|
11
11
|
async function handleUpdates(req, res) {
|
|
12
12
|
const data = req.body;
|
|
13
13
|
if (data?.update) {
|
|
14
|
-
for (let { prefix, filters, handler } of this.handlers.
|
|
15
|
-
const ctx = new
|
|
14
|
+
for (let { prefix, filters, handler } of this.handlers.update) {
|
|
15
|
+
const ctx = new update_context_1.default(this, data.update);
|
|
16
16
|
const passed = await (0, checkFilters_1.checkFilters)(ctx, filters);
|
|
17
17
|
if (passed) {
|
|
18
18
|
if (prefix) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import InlineMessage from '../contexts/inline.context';
|
|
2
|
-
import
|
|
2
|
+
import Update from '../contexts/update.context';
|
|
3
3
|
export interface Session {
|
|
4
4
|
iv: string;
|
|
5
5
|
enData: string;
|
|
@@ -16,7 +16,7 @@ export interface BotType {
|
|
|
16
16
|
start_message: string;
|
|
17
17
|
}
|
|
18
18
|
export interface ContextMap {
|
|
19
|
-
|
|
19
|
+
update: Update;
|
|
20
20
|
inline: InlineMessage;
|
|
21
21
|
}
|
|
22
22
|
export type FilterFn<T> = (ctx: T) => boolean | Promise<boolean>;
|
|
@@ -297,6 +297,13 @@ export interface InlineMessage {
|
|
|
297
297
|
export interface SendMessage {
|
|
298
298
|
message_id: string;
|
|
299
299
|
}
|
|
300
|
+
export interface UploadFile {
|
|
301
|
+
status: string;
|
|
302
|
+
status_det: string;
|
|
303
|
+
data: {
|
|
304
|
+
file_id: string;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
300
307
|
export interface Commend {
|
|
301
308
|
command: string;
|
|
302
309
|
description: string;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ import ClientFilters from './core/client/filters';
|
|
|
3
3
|
import ClientUtils from './utils/utils';
|
|
4
4
|
import Bot from './core/bot/bot';
|
|
5
5
|
import BotFilters from './core/bot/filters';
|
|
6
|
-
import { RubPlugin } from './core/client/types/client.type';
|
|
6
|
+
import type { RubPlugin } from './core/client/types/client.type';
|
|
7
7
|
import type MessageType from './core/client/contexts/message.type';
|
|
8
8
|
import type ActivitiesType from './core/client/contexts/activities.type';
|
|
9
9
|
import type ChatType from './core/client/contexts/chat.type';
|
|
10
10
|
import type NotificationsType from './core/client/contexts/notifications.type';
|
|
11
|
+
import type InlineMessageType from './core/bot/contexts/inline.context';
|
|
12
|
+
import type UpdateType from './core/bot/contexts/update.context';
|
|
11
13
|
import * as Clients from './clients';
|
|
12
|
-
export { Client, ClientFilters, ClientUtils, Bot, BotFilters,
|
|
14
|
+
export { Client, ClientFilters, ClientUtils, Bot, BotFilters, Clients };
|
|
15
|
+
export type { ChatType, MessageType, ActivitiesType, NotificationsType, RubPlugin, InlineMessageType, UpdateType, };
|
|
13
16
|
export default Client;
|
package/lib/index.js
CHANGED