telegram-botbuilder 1.0.7 → 1.0.9

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.
@@ -22,6 +22,6 @@ export declare class BotBuilder {
22
22
  Message(chat: number, content: string): Promise<TelegramBot.Message>;
23
23
  }
24
24
  export declare function ChangeDialog(id: string): Action;
25
- export declare function CallbackAction(descriptor: string): Action;
25
+ export declare function CallbackAction(descriptor: string, ...args: any[]): Action;
26
26
  export declare function WaitForData(descriptor: string): Action;
27
27
  export {};
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
38
47
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
49
  };
@@ -123,11 +132,17 @@ var BotBuilder = /** @class */ (function () {
123
132
  }); });
124
133
  this._bot.onText(/\/start/, function (msg) { return __awaiter(_this, void 0, void 0, function () {
125
134
  return __generator(this, function (_a) {
126
- if (!this._userdialogs[msg.chat.id])
127
- this._userdialogs[msg.chat.id] = { dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' } };
128
- this._bot.deleteMessage(msg.chat.id, msg.message_id).catch(function () { return undefined; });
129
- this.ChangeDialog(msg.chat.id, this._schema.start);
130
- return [2 /*return*/];
135
+ switch (_a.label) {
136
+ case 0: return [4 /*yield*/, this._runmw(msg.chat.id, msg)];
137
+ case 1:
138
+ if (_a.sent())
139
+ return [2 /*return*/];
140
+ if (!this._userdialogs[msg.chat.id])
141
+ this._userdialogs[msg.chat.id] = { dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' } };
142
+ this._bot.deleteMessage(msg.chat.id, msg.message_id).catch(function () { return undefined; });
143
+ this.ChangeDialog(msg.chat.id, this._schema.start);
144
+ return [2 /*return*/];
145
+ }
131
146
  });
132
147
  }); });
133
148
  var _loop_1 = function (cmd) {
@@ -135,29 +150,32 @@ var BotBuilder = /** @class */ (function () {
135
150
  var chat, _i, _a, act;
136
151
  return __generator(this, function (_b) {
137
152
  switch (_b.label) {
138
- case 0:
153
+ case 0: return [4 /*yield*/, this._runmw(msg.chat.id, msg)];
154
+ case 1:
155
+ if (_b.sent())
156
+ return [2 /*return*/];
139
157
  chat = msg.chat.id;
140
- if (!Array.isArray(cmd === null || cmd === void 0 ? void 0 : cmd.action)) return [3 /*break*/, 5];
158
+ if (!Array.isArray(cmd === null || cmd === void 0 ? void 0 : cmd.action)) return [3 /*break*/, 6];
141
159
  _i = 0, _a = cmd === null || cmd === void 0 ? void 0 : cmd.action;
142
- _b.label = 1;
143
- case 1:
144
- if (!(_i < _a.length)) return [3 /*break*/, 4];
160
+ _b.label = 2;
161
+ case 2:
162
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
145
163
  act = _a[_i];
146
164
  return [4 /*yield*/, act(chat, this, match[1])];
147
- case 2:
148
- _b.sent();
149
- _b.label = 3;
150
165
  case 3:
166
+ _b.sent();
167
+ _b.label = 4;
168
+ case 4:
151
169
  _i++;
152
- return [3 /*break*/, 1];
153
- case 4: return [3 /*break*/, 7];
154
- case 5:
155
- if (!(cmd === null || cmd === void 0 ? void 0 : cmd.action)) return [3 /*break*/, 7];
156
- return [4 /*yield*/, (cmd === null || cmd === void 0 ? void 0 : cmd.action)(chat, this, match[1])];
170
+ return [3 /*break*/, 2];
171
+ case 5: return [3 /*break*/, 8];
157
172
  case 6:
173
+ if (!(cmd === null || cmd === void 0 ? void 0 : cmd.action)) return [3 /*break*/, 8];
174
+ return [4 /*yield*/, (cmd === null || cmd === void 0 ? void 0 : cmd.action)(chat, this, match[1])];
175
+ case 7:
158
176
  _b.sent();
159
- _b.label = 7;
160
- case 7: return [2 /*return*/];
177
+ _b.label = 8;
178
+ case 8: return [2 /*return*/];
161
179
  }
162
180
  });
163
181
  }); });
@@ -337,10 +355,17 @@ function ChangeDialog(id) {
337
355
  }
338
356
  function CallbackAction(descriptor) {
339
357
  var _this = this;
340
- return function (chat, _bot) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
341
- _bot.ActionSystem.emit(descriptor, { chatid: chat });
342
- return [2 /*return*/];
343
- }); }); };
358
+ var args = [];
359
+ for (var _i = 1; _i < arguments.length; _i++) {
360
+ args[_i - 1] = arguments[_i];
361
+ }
362
+ return function (chat, _bot) { return __awaiter(_this, void 0, void 0, function () {
363
+ var _a;
364
+ return __generator(this, function (_b) {
365
+ (_a = _bot.ActionSystem).emit.apply(_a, __spreadArray([descriptor, chat], args, false));
366
+ return [2 /*return*/];
367
+ });
368
+ }); };
344
369
  }
345
370
  function WaitForData(descriptor) {
346
371
  return function (chat, _bot) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telegram-botbuilder",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "lib/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -84,6 +84,8 @@ export class BotBuilder {
84
84
  });
85
85
 
86
86
  this._bot.onText(/\/start/, async (msg) => {
87
+ if (await this._runmw(msg.chat.id, msg)) return;
88
+
87
89
  if (!this._userdialogs[msg.chat.id]) this._userdialogs[msg.chat.id] = {dialog: this._schema.start, lastid: -1, waiter: { statewait: false, descriptor: '' }}
88
90
  this._bot.deleteMessage(msg.chat.id, msg.message_id).catch(() => undefined);
89
91
  this.ChangeDialog(msg.chat.id, this._schema.start);
@@ -91,6 +93,8 @@ export class BotBuilder {
91
93
 
92
94
  for (let cmd of this._schema.commands) {
93
95
  this._bot.onText(new RegExp('\\/${cmd.text}(?:\\s+(.*))?$'), async (msg, match) => {
96
+ if (await this._runmw(msg.chat.id, msg)) return;
97
+
94
98
  let chat = msg.chat.id;
95
99
  if (Array.isArray(cmd?.action)) {
96
100
  for (let act of (cmd?.action as Action[])) {
@@ -163,8 +167,8 @@ export class BotBuilder {
163
167
  export function ChangeDialog(id: string): Action {
164
168
  return async (chat: number, _bot: BotBuilder) => { await _bot.ChangeDialog(chat, id); };
165
169
  }
166
- export function CallbackAction(descriptor: string): Action {
167
- return async (chat: number, _bot: BotBuilder) => { _bot.ActionSystem.emit(descriptor, {chatid: chat}); };
170
+ export function CallbackAction(descriptor: string, ...args: any[]): Action {
171
+ return async (chat: number, _bot: BotBuilder) => { _bot.ActionSystem.emit(descriptor, chat, ...args); };
168
172
  }
169
173
  export function WaitForData(descriptor: string): Action {
170
174
  return (chat: number, _bot: BotBuilder) => {