catto.js 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/TelegramBot.js +14 -1
- package/TelegramChannel.js +25 -2
- package/TelegramMessageBuilder.js +19 -0
- package/TelegramPayment.js +22 -0
- package/TelegramPaymentInProgress.js +18 -0
- package/index.js +1 -1
- package/package.json +1 -1
package/TelegramBot.js
CHANGED
|
@@ -3,6 +3,8 @@ var crypto = require("crypto");
|
|
|
3
3
|
var Telegraf = null;
|
|
4
4
|
var TelegramMessage = require("./TelegramMessage");
|
|
5
5
|
var TelegramInteraction = require("./TelegramInteraction");
|
|
6
|
+
var TelegramPaymentInProgress = require("./TelegramPaymentInProgress");
|
|
7
|
+
var TelegramPayment = require("./TelegramPayment");
|
|
6
8
|
var TelegramUser = require("./TelegramUser");
|
|
7
9
|
if (typeof EventEmitter === "undefined") {
|
|
8
10
|
var { EventEmitter } = events;
|
|
@@ -20,7 +22,9 @@ module.exports = class extends EventEmitter {
|
|
|
20
22
|
} else {
|
|
21
23
|
Telegraf = require("telegraf").Telegraf;
|
|
22
24
|
this.client = new Telegraf(this.options.token, {
|
|
23
|
-
"
|
|
25
|
+
"telegram": {
|
|
26
|
+
"testEnv": this.options.test
|
|
27
|
+
}
|
|
24
28
|
});
|
|
25
29
|
}
|
|
26
30
|
this.commands = new Map();
|
|
@@ -36,7 +40,13 @@ module.exports = class extends EventEmitter {
|
|
|
36
40
|
this.client.on("webhook_error", () => {});
|
|
37
41
|
}
|
|
38
42
|
this.client.on("message", message => {
|
|
43
|
+
if (message.message.successful_payment) {
|
|
44
|
+
return this.emit("paymentSuccess", new TelegramPayment(message, this));
|
|
45
|
+
}
|
|
39
46
|
message = new TelegramMessage(message, this);
|
|
47
|
+
if (!message.content) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
40
50
|
var args = message.content.split(" ");
|
|
41
51
|
var cmd = args.shift();
|
|
42
52
|
var command = this.slashCommands.get(cmd) || this.commands.get(cmd);
|
|
@@ -57,6 +67,9 @@ module.exports = class extends EventEmitter {
|
|
|
57
67
|
this.client.on("callback_query", interaction => {
|
|
58
68
|
this.emit("interaction", new TelegramInteraction(interaction, this));
|
|
59
69
|
});
|
|
70
|
+
this.client.on("pre_checkout_query", payment => {
|
|
71
|
+
this.emit("paymentProgress", new TelegramPaymentInProgress(payment, this));
|
|
72
|
+
});
|
|
60
73
|
}
|
|
61
74
|
command(basic, executor) {
|
|
62
75
|
if (typeof basic === "string") {
|
package/TelegramChannel.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = class {
|
|
|
30
30
|
if (data instanceof TelegramMessageBuilder) {
|
|
31
31
|
data = data.data;
|
|
32
32
|
}
|
|
33
|
-
await this.bot.client.telegram.sendMessage(this.id, data.content, {
|
|
33
|
+
await this.bot.client.telegram.sendMessage(this.id, data.content, Object.assign({
|
|
34
34
|
"reply_parameters": data.replyParameters ? {
|
|
35
35
|
"message_id": data.replyParameters.message.id,
|
|
36
36
|
"chat_id": (data.replyParameters.channel ? data.replyParameters.channel.id : this.id),
|
|
@@ -39,7 +39,30 @@ module.exports = class {
|
|
|
39
39
|
"reply_markup": data.replyMarkup ? data.replyMarkup : {
|
|
40
40
|
"remove_keyboard": !0
|
|
41
41
|
}
|
|
42
|
-
});
|
|
42
|
+
}, data.extra));
|
|
43
|
+
if (this.typingLoop !== null) {
|
|
44
|
+
await this.type();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async sendPayment(data) {
|
|
48
|
+
if (typeof data === "string") {
|
|
49
|
+
data = {
|
|
50
|
+
"content": data
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (data instanceof TelegramMessageBuilder) {
|
|
54
|
+
data = data.data;
|
|
55
|
+
}
|
|
56
|
+
await this.bot.client.telegram.sendInvoice(this.id, {
|
|
57
|
+
"reply_parameters": data.replyParameters ? {
|
|
58
|
+
"message_id": data.replyParameters.message.id,
|
|
59
|
+
"chat_id": (data.replyParameters.channel ? data.replyParameters.channel.id : this.id),
|
|
60
|
+
"allow_sending_without_reply": !1
|
|
61
|
+
} : void 0,
|
|
62
|
+
"reply_markup": data.replyMarkup ? data.replyMarkup : {
|
|
63
|
+
"remove_keyboard": !0
|
|
64
|
+
}
|
|
65
|
+
}, data.invoiceExtra);
|
|
43
66
|
if (this.typingLoop !== null) {
|
|
44
67
|
await this.type();
|
|
45
68
|
}
|
|
@@ -34,6 +34,12 @@ module.exports = class {
|
|
|
34
34
|
"callback_data": btn.data
|
|
35
35
|
};
|
|
36
36
|
break;
|
|
37
|
+
case "payment":
|
|
38
|
+
return {
|
|
39
|
+
"text": btn.label,
|
|
40
|
+
"pay": !0
|
|
41
|
+
};
|
|
42
|
+
break;
|
|
37
43
|
default:
|
|
38
44
|
break;
|
|
39
45
|
}
|
|
@@ -65,4 +71,17 @@ module.exports = class {
|
|
|
65
71
|
};
|
|
66
72
|
return this;
|
|
67
73
|
}
|
|
74
|
+
payment(data) {
|
|
75
|
+
this.data.invoiceExtra = {
|
|
76
|
+
"title": data.title,
|
|
77
|
+
"description": data.description,
|
|
78
|
+
"payload": data.data,
|
|
79
|
+
"currency": "XTR",
|
|
80
|
+
"prices": [{
|
|
81
|
+
"label": data.item,
|
|
82
|
+
"amount": data.price
|
|
83
|
+
}]
|
|
84
|
+
};
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
68
87
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var TelegramChannel = require("./TelegramChannel");
|
|
2
|
+
var TelegramUser = require("./TelegramUser");
|
|
3
|
+
|
|
4
|
+
module.exports = class {
|
|
5
|
+
constructor(data, bot) {
|
|
6
|
+
this._data = data;
|
|
7
|
+
this.bot = bot;
|
|
8
|
+
this.channel = new TelegramChannel(this._data.chat, bot);
|
|
9
|
+
this.user = this.bot.users.get(this._data.from.id) || new TelegramUser(this._data.from, bot);
|
|
10
|
+
this.user.data = this._data.from;
|
|
11
|
+
this.bot.users.set(this.user.id, this.user);
|
|
12
|
+
}
|
|
13
|
+
get id() {
|
|
14
|
+
return this._data.message.successful_payment.telegram_payment_charge_id;
|
|
15
|
+
}
|
|
16
|
+
get data() {
|
|
17
|
+
return this._data.message.successful_payment.invoice_payload;
|
|
18
|
+
}
|
|
19
|
+
get price() {
|
|
20
|
+
return this._data.message.successful_payment.total_amount;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = class {
|
|
2
|
+
constructor(data, bot) {
|
|
3
|
+
this._data = data;
|
|
4
|
+
this.bot = bot;
|
|
5
|
+
}
|
|
6
|
+
get id() {
|
|
7
|
+
return this._data.update.pre_checkout_query.id;
|
|
8
|
+
}
|
|
9
|
+
get data() {
|
|
10
|
+
return this._data.update.pre_checkout_query.invoice_payload;
|
|
11
|
+
}
|
|
12
|
+
async approve() {
|
|
13
|
+
await this.bot.client.telegram.answerPreCheckoutQuery(this.id, !0);
|
|
14
|
+
}
|
|
15
|
+
async decline(text) {
|
|
16
|
+
await this.bot.client.telegram.answerPreCheckoutQuery(this.id, !1, text);
|
|
17
|
+
}
|
|
18
|
+
};
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var mod = {};
|
|
2
2
|
var version = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
|
3
|
-
var parts = ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Application", "TelegramBot", "TelegramMessage", "TelegramChannel", "TelegramMessageBuilder", "TelegramInteraction", "TelegramUser", "TelegramFile"];
|
|
3
|
+
var parts = ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Application", "TelegramBot", "TelegramMessage", "TelegramChannel", "TelegramMessageBuilder", "TelegramInteraction", "TelegramPaymentInProgress", "TelegramPayment", "TelegramUser", "TelegramFile"];
|
|
4
4
|
if (version >= 18.20) {
|
|
5
5
|
parts.push("Bot", "MessageBuilder");
|
|
6
6
|
}
|