Answer the question
In order to leave comments, you need to log in
Almost the same example from the telegraf, scene examples does not work?
I paste an example from the documentation (it really works)
const Telegraf = require('telegraf')
const session = require('telegraf/session')
const Stage = require('telegraf/stage')
const Scene = require('telegraf/scenes/base')
const bot = new Telegraf("ТОКЕН", { handlerTimeout: 100 });
// Handler factoriess
const { enter, leave } = Stage
// Greeter scene
const greeterScene = new Scene('greeter')
greeterScene.enter((ctx) => ctx.reply('Hi'))
greeterScene.leave((ctx) => ctx.reply('Bye'))
greeterScene.hears('hi', enter('greeter'))
greeterScene.on('message', (ctx) => ctx.replyWithMarkdown('Send `hi`'))
// Echo scene
const echoScene = new Scene('echo')
echoScene.enter((ctx) => ctx.reply('echo scene'))
echoScene.leave((ctx) => ctx.reply('exiting echo scene'))
echoScene.command('back', leave())
echoScene.on('text', (ctx) => ctx.reply(ctx.message.text))
echoScene.on('message', (ctx) => ctx.reply('Only text messages please'))
const stage = new Stage([greeterScene, echoScene], { ttl: 10 })
bot.use(session())
bot.use(stage.middleware())
bot.command('greeter', (ctx) => ctx.scene.enter('greeter'))
bot.command('echo', (ctx) => ctx.scene.enter('echo'))
bot.on('message', (ctx) => ctx.reply('Try /echo or /greeter'))
bot.launch()
const Telegraf = require('telegraf')
const session = require('telegraf/session')
const Stage = require('telegraf/stage')
const Scene = require('telegraf/scenes/base')
const bot = new Telegraf("ТОКЕН", { handlerTimeout: 100 });
const { enter, leave } = Stage
const NameScene = new Scene("namespace");
NameScene.enter((ctx) => {
ctx.reply("Send your name, user");
namespace.on('text', async(ctx) =>{
let HeName = ctx.message.text
})
if (HeName.lenght() < 2) {
ctx.reply("Setup your real name")
}
})
bot.command('start', (ctx) => ctx.scene.enter('namespace'))
const stage = new Stage([NameScene], { ttl: 10 })
bot.use(session())
bot.use(stage.middleware())
bot.launch()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question