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.
- package/lib/bot-service.d.ts +1 -1
- package/lib/bot-service.js +23 -6
- package/package.json +1 -1
- package/src/bot-service.ts +18 -7
package/lib/bot-service.d.ts
CHANGED
|
@@ -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 {};
|
package/lib/bot-service.js
CHANGED
|
@@ -397,11 +397,28 @@ function CallbackAction(descriptor) {
|
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
399
|
function WaitForData(descriptor) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
package/src/bot-service.ts
CHANGED
|
@@ -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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
}
|