telegram-botbuilder 1.0.20 → 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/package.json +1 -1
- package/readme.md +54 -0
- package/src/bot-service.ts +1 -1
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,7 +167,7 @@ export class BotBuilder {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
if (dialog == undefined) markup = [[{text: "Меню", callback_data: this._schema.start}]];
|
|
170
|
+
if (dialog == undefined) markup = [[{text: "Меню", callback_data: this._schema.start}]]; // FIX RAND BTN
|
|
171
171
|
let text = typeof dialog?.text === 'function' ? await dialog?.text(chat) : dialog?.text;
|
|
172
172
|
try {
|
|
173
173
|
await this._bot.editMessageText(text || "404", { chat_id: chat, message_id: this._userdialogs[chat].lastid, reply_markup: { inline_keyboard: markup || [] }})
|