telegram-botbuilder
v1.5.2
Published
``` typescript import { Schema } from 'telegram-botbuilder'; import { BotBuilder, CallbackAction, ChangeDialog } from 'telegram-botbuilder';
Downloads
164
Readme
import { Schema } from 'telegram-botbuilder';
import { BotBuilder, CallbackAction, ChangeDialog } from 'telegram-botbuilder';
const schema: Schema = {
start: 'start_dialog',
content: [
{
id: 'start_dialog',
text: 'Welcome to my bot!',
buttons: [
[
{
text: 'Button 1',
action: [CallbackAction('button1_clicked', 'optional arg')],
},
{
text: 'Dialog 2',
action: [ChangeDialog('dialog2')],
},
],
],
},
{
id: 'dialog2',
text: async (chatid: number) => { return "test dialog 2"; },
buttons: [
[
{
text: 'Button 1',
action: [ChangeDialog('start_dialog')],
},
],
],
},
],
commands: [
{
text: 'test',
action: [CallbackAction('testcmd')],
},
],
};
const bot = new BotBuilder(schema, 'YOUR_BOT_TOKEN', { polling: true });
bot.ActionSystem.on('button1_clicked', (chatid: number) => {
bot.Message(chatid, 'Button1 Click!');
});
bot.ActionSystem.on('testcmd', (chatid: number, args: string) => {
bot.Message(chatid, `Test command: ${args}`);
});