J
J
jenya77712018-06-18 00:02:56
Node.js
jenya7771, 2018-06-18 00:02:56

How to make multiple Telegraf.js message chain scripts?

Hello, how can I change the next question or bot action depending on the answer. For example, if the user selects sorting by distance, how can he slip a question asking him to send a geolocation?

const categoriesWizard = new WizardScene('categories', (ctx) => {

  const keyboard = 
  Markup.keyboard(['Категория 1', 'Категория 2'], {
    columns: parseInt(2)
  })
  .oneTime()
  .resize()
  .extra()

  ctx.reply('Выбери категорию', keyboard)
  return ctx.wizard.next()
}, (ctx) => {

  const message = ctx.update.message.text

  ctx.session.categorise = {
    cat: message
  }

  const keyboard = 
  Markup.keyboard(['подкатегория 1', 'подкатегория 2'], {
    columns: parseInt(2)
  })
  .oneTime()
  .resize()
  .extra()

  ctx.reply('Выбери подкатегорию', keyboard)
  return ctx.wizard.next()
}, (ctx) => {

  const message = ctx.update.message.text

  ctx.session.categorise.sub_cat = message

  const keyboard = 
  Markup.keyboard(['По расстоянию', 'По цене'], {
    columns: parseInt(2)
  })
  .oneTime()
  .resize()
  .extra()

  ctx.reply('Как сортировать скидки?', keyboard)
  return ctx.wizard.next()
}, (ctx) => {

  const message = ctx.update.message.text

  ctx.session.categorise.sort = message

  ctx.reply(`Категория: ${ctx.session.categorise.cat}\nПодкатегория: ${ctx.session.categorise.sub_cat}\nСортировка: ${ctx.session.categorise.sort}`)
  return ctx.scene.leave()
})

How can I validate the user's answer after the answer, thanks!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-06-18
@atcrew

Look towards bot.hears(/some regexp/) and/or bot.command('command') well, from memory, you can also look at the docks, there are some other handlers.
Yes, there is a difference where to put handlers. telegraf is run in a loop (if it's very simple) and executes everything written sequentially, command by command.
If it gets really hot, contact me, let's see your code, maybe I can help something)

V
Vladislav Prikhodko, 2018-12-27
@Vuishnak

You can use Composer.
Here is an example, so implement what you need!
https://github.com/telegraf/telegraf/blob/master/d...
Please let me know if the issue persists)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question