Untitled
unknown
javascript
2 years ago
1.9 kB
2
Indexable
const { session, Markup, Scenes, Telegraf } = require('telegraf');
require('dotenv').config();
const clientsQueue = [];
const bot = new Telegraf(process.env.BOT_TOKEN);
const welcomeScene = new Scenes.BaseScene("welcome-scene");
welcomeScene.enter(async ctx => {
await ctx.replyWithMarkdownV2("Welcome",
Markup.inlineKeyboard(
[
Markup.button.url("🌐 Website", "<some_url>"),
Markup.button.url("📞 Support", "<some_url>")
])
);
});
welcomeScene.on("message", async ctx => await ctx.reply("Click on buttons to continue"));
const secondScene = new Scenes.BaseScene("second-scene");
secondScene.enter(async ctx => {
await ctx.deleteMessage();
//Need to add to clients queue
clientsQueue.push(ctx)
await ctx.replyWithMarkdownV2("People in second scene: " + clientsQueue.length,
Markup.inlineKeyboard([
Markup.button.callback("❌ Close", "close"),
])
);
});
secondScene.action("close", async ctx => {
await ctx.deleteMessage();
//need to remove from clients queue
clientsQueue.splice(clientsQueue.map(x => x.chatId).indexOf(ctx.chat.id), 1);
ctx.scene.enter('welcome-scene');
});
secondScene.on("message", async ctx => await ctx.reply("Click on buttons to continue"));
const stage = new Scenes.Stage([welcomeScene, secondScene]);
bot.use(session());
bot.use(stage.middleware());
bot.command('start', (ctx) => ctx.scene.enter('welcome-scene'));
bot.action('start', (ctx) => ctx.scene.enter('welcome-scene'));
bot.command('second', (ctx) => ctx.scene.enter('second-scene'));
bot.action('second', (ctx) => ctx.scene.enter('second-scene'));
bot.on("message", (ctx) => ctx.scene.enter('welcome-scene'));
bot.launch();
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
Editor is loading...
Leave a Comment