telegram-botbuilder 1.0.15 → 1.0.17
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/lib/bot-service.js +23 -13
- package/package.json +1 -1
- package/src/bot-service.ts +5 -2
package/lib/bot-service.js
CHANGED
|
@@ -78,7 +78,10 @@ var BotBuilder = /** @class */ (function () {
|
|
|
78
78
|
var chat;
|
|
79
79
|
return __generator(this, function (_a) {
|
|
80
80
|
switch (_a.label) {
|
|
81
|
-
case 0:
|
|
81
|
+
case 0:
|
|
82
|
+
if (!this._userdialogs[msg.chat.id])
|
|
83
|
+
this._userdialogs[msg.chat.id] = { dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' } };
|
|
84
|
+
return [4 /*yield*/, this._runmw(msg.chat.id, msg)];
|
|
82
85
|
case 1:
|
|
83
86
|
if (_a.sent())
|
|
84
87
|
return [2 /*return*/];
|
|
@@ -111,7 +114,10 @@ var BotBuilder = /** @class */ (function () {
|
|
|
111
114
|
var _this = this;
|
|
112
115
|
return __generator(this, function (_a) {
|
|
113
116
|
switch (_a.label) {
|
|
114
|
-
case 0:
|
|
117
|
+
case 0:
|
|
118
|
+
if (!this._userdialogs[msg.chat.id])
|
|
119
|
+
this._userdialogs[msg.chat.id] = { dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' } };
|
|
120
|
+
return [4 /*yield*/, this._runmw(msg.chat.id, msg)];
|
|
115
121
|
case 1:
|
|
116
122
|
if (_a.sent())
|
|
117
123
|
return [2 /*return*/];
|
|
@@ -149,33 +155,37 @@ var BotBuilder = /** @class */ (function () {
|
|
|
149
155
|
var _loop_1 = function (cmd) {
|
|
150
156
|
this_1._bot.onText(new RegExp("\\/".concat(cmd.text, "(?:\\s+(.*))?$")), function (msg, match) { return __awaiter(_this, void 0, void 0, function () {
|
|
151
157
|
var chat, _i, _a, act;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
var _b, _c;
|
|
159
|
+
return __generator(this, function (_d) {
|
|
160
|
+
switch (_d.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
if (!this._userdialogs[msg.chat.id])
|
|
163
|
+
this._userdialogs[msg.chat.id] = { dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' } };
|
|
164
|
+
return [4 /*yield*/, this._runmw(msg.chat.id, msg)];
|
|
155
165
|
case 1:
|
|
156
|
-
if (
|
|
166
|
+
if (_d.sent())
|
|
157
167
|
return [2 /*return*/];
|
|
158
168
|
chat = msg.chat.id;
|
|
159
169
|
if (!Array.isArray(cmd === null || cmd === void 0 ? void 0 : cmd.action)) return [3 /*break*/, 6];
|
|
160
170
|
_i = 0, _a = cmd === null || cmd === void 0 ? void 0 : cmd.action;
|
|
161
|
-
|
|
171
|
+
_d.label = 2;
|
|
162
172
|
case 2:
|
|
163
173
|
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
164
174
|
act = _a[_i];
|
|
165
|
-
return [4 /*yield*/, act(chat, this,
|
|
175
|
+
return [4 /*yield*/, act(chat, this, (_b = msg.text) === null || _b === void 0 ? void 0 : _b.split(' ').pop())];
|
|
166
176
|
case 3:
|
|
167
|
-
|
|
168
|
-
|
|
177
|
+
_d.sent();
|
|
178
|
+
_d.label = 4;
|
|
169
179
|
case 4:
|
|
170
180
|
_i++;
|
|
171
181
|
return [3 /*break*/, 2];
|
|
172
182
|
case 5: return [3 /*break*/, 8];
|
|
173
183
|
case 6:
|
|
174
184
|
if (!(cmd === null || cmd === void 0 ? void 0 : cmd.action)) return [3 /*break*/, 8];
|
|
175
|
-
return [4 /*yield*/, (cmd === null || cmd === void 0 ? void 0 : cmd.action)(chat, this,
|
|
185
|
+
return [4 /*yield*/, (cmd === null || cmd === void 0 ? void 0 : cmd.action)(chat, this, (_c = msg.text) === null || _c === void 0 ? void 0 : _c.split(' ').pop())];
|
|
176
186
|
case 7:
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
_d.sent();
|
|
188
|
+
_d.label = 8;
|
|
179
189
|
case 8: return [2 /*return*/];
|
|
180
190
|
}
|
|
181
191
|
});
|
package/package.json
CHANGED
package/src/bot-service.ts
CHANGED
|
@@ -68,6 +68,7 @@ export class BotBuilder {
|
|
|
68
68
|
this._userdialogs = {};
|
|
69
69
|
|
|
70
70
|
this._bot.onText(/.+/g, async (msg) => {
|
|
71
|
+
if (!this._userdialogs[msg.chat.id]) this._userdialogs[msg.chat.id] = {dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' }}
|
|
71
72
|
if (await this._runmw(msg.chat.id, msg)) return;
|
|
72
73
|
|
|
73
74
|
let chat = msg.chat.id;
|
|
@@ -86,6 +87,7 @@ export class BotBuilder {
|
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
this._bot.on('document', async (msg) => {
|
|
90
|
+
if (!this._userdialogs[msg.chat.id]) this._userdialogs[msg.chat.id] = {dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' }}
|
|
89
91
|
if (await this._runmw(msg.chat.id, msg)) return;
|
|
90
92
|
|
|
91
93
|
if (!msg.document) return;
|
|
@@ -110,15 +112,16 @@ export class BotBuilder {
|
|
|
110
112
|
|
|
111
113
|
for (let cmd of this._schema.commands) {
|
|
112
114
|
this._bot.onText(new RegExp(`\\/${cmd.text}(?:\\s+(.*))?$`), async (msg, match) => {
|
|
115
|
+
if (!this._userdialogs[msg.chat.id]) this._userdialogs[msg.chat.id] = {dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' }}
|
|
113
116
|
if (await this._runmw(msg.chat.id, msg)) return;
|
|
114
117
|
|
|
115
118
|
let chat = msg.chat.id;
|
|
116
119
|
if (Array.isArray(cmd?.action)) {
|
|
117
120
|
for (let act of (cmd?.action as Action[])) {
|
|
118
|
-
await act(chat, this,
|
|
121
|
+
await act(chat, this, msg.text?.split(' ').pop());
|
|
119
122
|
}
|
|
120
123
|
} else if (cmd?.action as Action) {
|
|
121
|
-
await (cmd?.action as Action)(chat, this,
|
|
124
|
+
await (cmd?.action as Action)(chat, this, msg.text?.split(' ').pop());
|
|
122
125
|
}
|
|
123
126
|
});
|
|
124
127
|
}
|