Skip to content

Instantly share code, notes, and snippets.

@vladthelittleone
Last active April 28, 2022 00:35
Show Gist options
  • Select an option

  • Save vladthelittleone/fd9872e4a0e3c50087f0b7855d9301a2 to your computer and use it in GitHub Desktop.

Select an option

Save vladthelittleone/fd9872e4a0e3c50087f0b7855d9301a2 to your computer and use it in GitHub Desktop.
Telegram Bot, using framework Telegraf.
const session = require("telegraf/session");
const Stage = require("telegraf/stage");
const WizardScene = require("telegraf/scenes/wizard");
// ...
// Сцена создания нового матча.
const create = new WizardScene(
"create", // Имя сцены
(ctx) => {
ctx.reply('Этап 1: выбор типа матча.');
return ctx.wizard.next(); // Переходим к следующему обработчику.
},
(ctx) => {
ctx.reply('Этап 2: выбор времени проведения матча.');
return ctx.wizard.next(); // Переходим к следующему обработчику.
},
(ctx) => {
if (ctx.message.text === "Назад") {
ctx.wizard.back(); // Вернуться к предыдущиму обработчику
}
ctx.reply('Этап 3: выбор места проведения матча.');
return ctx.wizard.next(); // Переходим к следующему обработчику.
},
// ...
(ctx) => {
ctx.reply('Финальный этап: создание матча.');
return ctx.scene.leave();
}
);
// Создаем менеджера сцен
const stage = new Stage();
// Регистрируем сцену создания матча
stage.register(create);
bot.use(session());
bot.use(stage.middleware());
bot.action("create", (ctx) => ctx.scene.enter("create"));
// ...
Copy link

ghost commented Nov 14, 2020

Hi bro. Good day! I used your code. but I took this error:
'Failed to process updates. TypeError: Cannot read property 'enter' of undefined'

@Sharofboyev
Copy link

Me too. Is Telegraf Js documentation changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment