telegram-botbuilder 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.
@@ -23,7 +23,8 @@ export declare class BotBuilder {
23
23
  AttachDataWait(chat: number, descriptor: string): void;
24
24
  Message(chat: number, content: string): Promise<TelegramBot.Message>;
25
25
  }
26
+ type CallbackActionFunc = ((chatid: number, ...args: any[]) => void) | ((chatid: number, ...args: any[]) => Promise<void>);
26
27
  export declare function ChangeDialog(id: string): Action;
27
- export declare function CallbackAction(descriptor: string): Action;
28
+ export declare function CallbackAction(descriptor: string | CallbackActionFunc, ...args: any[]): Action;
28
29
  export declare function WaitForData(descriptor: string): Action;
29
30
  export {};
@@ -322,7 +322,7 @@ var BotBuilder = /** @class */ (function () {
322
322
  return [3 /*break*/, 1];
323
323
  case 8:
324
324
  if (dialog == undefined)
325
- markup = [[{ text: "Меню", callback_data: this._schema.start }]];
325
+ markup = [[{ text: "Меню", callback_data: this._schema.start }]]; // FIX RAND BTN
326
326
  if (!(typeof (dialog === null || dialog === void 0 ? void 0 : dialog.text) === 'function')) return [3 /*break*/, 10];
327
327
  return [4 /*yield*/, (dialog === null || dialog === void 0 ? void 0 : dialog.text(chat))];
328
328
  case 9:
@@ -366,13 +366,34 @@ function ChangeDialog(id) {
366
366
  return function (chat, _bot) { return _bot.ChangeDialog(chat, id); };
367
367
  }
368
368
  function CallbackAction(descriptor) {
369
+ var _this = this;
370
+ var args = [];
371
+ for (var _i = 1; _i < arguments.length; _i++) {
372
+ args[_i - 1] = arguments[_i];
373
+ }
369
374
  return function (chat, _bot) {
370
- var _a;
371
- var args = [];
375
+ var _args = [];
372
376
  for (var _i = 2; _i < arguments.length; _i++) {
373
- args[_i - 2] = arguments[_i];
377
+ _args[_i - 2] = arguments[_i];
374
378
  }
375
- (_a = _bot.ActionSystem).emit.apply(_a, __spreadArray([descriptor, chat], args, false));
379
+ return __awaiter(_this, void 0, void 0, function () {
380
+ var _a;
381
+ var _b;
382
+ return __generator(this, function (_c) {
383
+ switch (_c.label) {
384
+ case 0:
385
+ if (!(typeof descriptor == 'function')) return [3 /*break*/, 2];
386
+ return [4 /*yield*/, descriptor.apply(void 0, __spreadArray(__spreadArray([chat], args, false), _args, false))];
387
+ case 1:
388
+ _a = _c.sent();
389
+ return [3 /*break*/, 3];
390
+ case 2:
391
+ _a = (_b = _bot.ActionSystem).emit.apply(_b, __spreadArray(__spreadArray([descriptor, chat], args, false), _args, false));
392
+ _c.label = 3;
393
+ case 3: return [2 /*return*/, _a];
394
+ }
395
+ });
396
+ });
376
397
  };
377
398
  }
378
399
  function WaitForData(descriptor) {
@@ -1,5 +1,5 @@
1
1
  import { BotBuilder } from "./bot-service";
2
- export type Action = (chat: number, _bot: BotBuilder, ...args: any[]) => Promise<void> | void;
2
+ export type Action = (chat: number, _bot: BotBuilder, ...args: any[]) => (Promise<any> | any);
3
3
  export interface Dialog {
4
4
  id: string;
5
5
  text: string | ((chat: number) => Promise<string>) | ((chat: number) => string);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telegram-botbuilder",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "lib/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/readme.md CHANGED
@@ -12,7 +12,7 @@ const schema: Schema = {
12
12
  [
13
13
  {
14
14
  text: 'Button 1',
15
- action: [CallbackAction('button1_clicked')],
15
+ action: [CallbackAction('button1_clicked', 'optional arg')],
16
16
  },
17
17
  {
18
18
  text: 'Dialog 2',
@@ -23,7 +23,7 @@ const schema: Schema = {
23
23
  },
24
24
  {
25
25
  id: 'dialog2',
26
- text: 'Test dialog 2',
26
+ text: async (chatid: number) => { return "test dialog 2"; },
27
27
  buttons: [
28
28
  [
29
29
  {
@@ -185,11 +185,13 @@ export class BotBuilder {
185
185
  }
186
186
  }
187
187
 
188
+ type CallbackActionFunc = ((chatid: number, ...args: any[]) => void) | ((chatid: number, ...args: any[]) => Promise<void>)
189
+
188
190
  export function ChangeDialog(id: string): Action {
189
191
  return (chat: number, _bot: BotBuilder) => { return _bot.ChangeDialog(chat, id); };
190
192
  }
191
- export function CallbackAction(descriptor: string): Action {
192
- return (chat: number, _bot: BotBuilder, ...args: any[]) => { _bot.ActionSystem.emit(descriptor, chat, ...args); };
193
+ export function CallbackAction(descriptor: string | CallbackActionFunc, ...args: any[]): Action {
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); };
193
195
  }
194
196
  export function WaitForData(descriptor: string): Action {
195
197
  return (chat: number, _bot: BotBuilder) => {
package/src/bot-struct.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BotBuilder } from "./bot-service";
2
2
 
3
3
 
4
- export type Action = (chat: number, _bot: BotBuilder, ...args: any[]) => Promise<void> | void;
4
+ export type Action = (chat: number, _bot: BotBuilder, ...args: any[]) => (Promise<any> | any);
5
5
 
6
6
  export interface Dialog {
7
7
  id: string;