telegram-botbuilder 1.0.19 → 1.1.0
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 +2 -0
- package/package.json +1 -1
- package/readme.md +54 -0
- package/src/bot-service.ts +1 -0
package/lib/bot-service.js
CHANGED
|
@@ -321,6 +321,8 @@ var BotBuilder = /** @class */ (function () {
|
|
|
321
321
|
b++;
|
|
322
322
|
return [3 /*break*/, 1];
|
|
323
323
|
case 8:
|
|
324
|
+
if (dialog == undefined)
|
|
325
|
+
markup = [[{ text: "Меню", callback_data: this._schema.start }]];
|
|
324
326
|
if (!(typeof (dialog === null || dialog === void 0 ? void 0 : dialog.text) === 'function')) return [3 /*break*/, 10];
|
|
325
327
|
return [4 /*yield*/, (dialog === null || dialog === void 0 ? void 0 : dialog.text(chat))];
|
|
326
328
|
case 9:
|
package/package.json
CHANGED
package/readme.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
``` typescript
|
|
2
|
+
import { Schema } from 'telegram-botbuilder';
|
|
3
|
+
import { BotBuilder, CallbackAction, ChangeDialog } from 'telegram-botbuilder';
|
|
4
|
+
|
|
5
|
+
const schema: Schema = {
|
|
6
|
+
start: 'start_dialog',
|
|
7
|
+
content: [
|
|
8
|
+
{
|
|
9
|
+
id: 'start_dialog',
|
|
10
|
+
text: 'Welcome to my bot!',
|
|
11
|
+
buttons: [
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
text: 'Button 1',
|
|
15
|
+
action: [CallbackAction('button1_clicked')],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
text: 'Dialog 2',
|
|
19
|
+
action: [ChangeDialog('dialog2')],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'dialog2',
|
|
26
|
+
text: 'Test dialog 2',
|
|
27
|
+
buttons: [
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
text: 'Button 1',
|
|
31
|
+
action: [ChangeDialog('start_dialog')],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
commands: [
|
|
38
|
+
{
|
|
39
|
+
text: 'test',
|
|
40
|
+
action: [CallbackAction('testcmd')],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const bot = new BotBuilder(schema, 'YOUR_BOT_TOKEN');
|
|
46
|
+
|
|
47
|
+
bot.ActionSystem.on('button1_clicked', (chatid: number) => {
|
|
48
|
+
bot.Message(chatid, 'Button1 Click!');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
bot.ActionSystem.on('testcmd', (chatid: number, args: string) => {
|
|
52
|
+
bot.Message(chatid, `Test command: ${args}`);
|
|
53
|
+
});
|
|
54
|
+
```
|
package/src/bot-service.ts
CHANGED
|
@@ -167,6 +167,7 @@ export class BotBuilder {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
if (dialog == undefined) markup = [[{text: "Меню", callback_data: this._schema.start}]]; // FIX RAND BTN
|
|
170
171
|
let text = typeof dialog?.text === 'function' ? await dialog?.text(chat) : dialog?.text;
|
|
171
172
|
try {
|
|
172
173
|
await this._bot.editMessageText(text || "404", { chat_id: chat, message_id: this._userdialogs[chat].lastid, reply_markup: { inline_keyboard: markup || [] }})
|