telegram-botbuilder 1.1.3 → 1.1.4

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.
@@ -26,5 +26,5 @@ export declare class BotBuilder {
26
26
  type CallbackActionFunc = ((chatid: number, ...args: any[]) => void) | ((chatid: number, ...args: any[]) => Promise<void>);
27
27
  export declare function ChangeDialog(id: string): Action;
28
28
  export declare function CallbackAction(descriptor: string | CallbackActionFunc, ...args: any[]): Action;
29
- export declare function WaitForData(descriptor: string): Action;
29
+ export declare function WaitForData(descriptor: string | CallbackActionFunc): Action;
30
30
  export {};
@@ -397,11 +397,28 @@ function CallbackAction(descriptor) {
397
397
  };
398
398
  }
399
399
  function WaitForData(descriptor) {
400
- return function (chat, _bot) {
401
- _bot.AttachDataWait(chat, descriptor);
402
- return new Promise(function (r) {
403
- _bot.ActionSystem.once(descriptor, r);
404
- _bot.ActionSystem.once("cancel_".concat(descriptor), r);
400
+ var _this = this;
401
+ return function (chat, _bot) { return __awaiter(_this, void 0, void 0, function () {
402
+ var desc_1;
403
+ return __generator(this, function (_a) {
404
+ if (typeof descriptor == 'string') {
405
+ _bot.AttachDataWait(chat, descriptor);
406
+ return [2 /*return*/, new Promise(function (r) {
407
+ _bot.ActionSystem.once(descriptor, r);
408
+ _bot.ActionSystem.once("cancel_".concat(descriptor), r);
409
+ })];
410
+ }
411
+ else {
412
+ desc_1 = crypto.randomUUID();
413
+ _bot.AttachDataWait(chat, desc_1);
414
+ return [2 /*return*/, new Promise(function (r) {
415
+ _bot.ActionSystem.once(desc_1, descriptor);
416
+ _bot.ActionSystem.once("cancel_".concat(desc_1), descriptor);
417
+ _bot.ActionSystem.once(desc_1, r);
418
+ _bot.ActionSystem.once("cancel_".concat(desc_1), r);
419
+ })];
420
+ }
421
+ return [2 /*return*/];
405
422
  });
406
- };
423
+ }); };
407
424
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telegram-botbuilder",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "main": "lib/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -193,12 +193,23 @@ export function ChangeDialog(id: string): Action {
193
193
  export function CallbackAction(descriptor: string | CallbackActionFunc, ...args: any[]): Action {
194
194
  return async (chat: number, _bot: BotBuilder, ..._args: any[]) => { return typeof descriptor == 'function' ? await descriptor(chat, ...args, ..._args) : _bot.ActionSystem.emit(descriptor, chat, ...args, ..._args); };
195
195
  }
196
- export function WaitForData(descriptor: string): Action {
197
- return (chat: number, _bot: BotBuilder) => {
198
- _bot.AttachDataWait(chat, descriptor);
199
- return new Promise(r => {
200
- _bot.ActionSystem.once(descriptor, r);
201
- _bot.ActionSystem.once(`cancel_${descriptor}`, r);
202
- });
196
+ export function WaitForData(descriptor: string | CallbackActionFunc): Action {
197
+ return async (chat: number, _bot: BotBuilder) => {
198
+ if (typeof descriptor == 'string') {
199
+ _bot.AttachDataWait(chat, descriptor);
200
+ return new Promise(r => {
201
+ _bot.ActionSystem.once(descriptor, r);
202
+ _bot.ActionSystem.once(`cancel_${descriptor}`, r);
203
+ });
204
+ } else {
205
+ let desc = crypto.randomUUID();
206
+ _bot.AttachDataWait(chat, desc);
207
+ return new Promise(r => {
208
+ _bot.ActionSystem.once(desc, descriptor);
209
+ _bot.ActionSystem.once(`cancel_${desc}`, descriptor);
210
+ _bot.ActionSystem.once(desc, r);
211
+ _bot.ActionSystem.once(`cancel_${desc}`, r);
212
+ });
213
+ }
203
214
  };
204
215
  }