A
A
aassww2021-02-28 15:16:10
Node.js
aassww, 2021-02-28 15:16:10

How to send a question to the user and, having received an answer, write it to a variable?

node-telegram-bot-api library

spoiler
Нерабочий код:


bot.on('callback_query', async (query) => {
  const chatId = query.message.chat.id
  if(query.data === 'createBTCcheque') {
    await bot.sendMessage(chatId, `На какую сумму вы хотите создать чек?`)
    const sumCheque = query.message.text
      const numberCheque = generationBTCcheque(20)
    cheque.push({
      number: numberCheque,
      sum: sumCheque,
      owner: query.message.chat.id
    })
    bot.sendMessage(chatId, `Чек на сумму ` + sumCheque + ` успешно создан:\n\nt.me/TeleBotOnJs_bot?start=` + numberCheque)
  }
  return
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex K, 2021-03-01
@thewayofmagic

In the above code, upon receiving a notification about the pressed button with `createBTCcheque`, the message `How much do you want to create a check for?` is sent, and then an attempt is made to get the data of the message, which does not exist.
First, you need to remember the user's state (save somewhere that the user is at such and such a step). In this case, with sending a message about entering the amount, remember that the user is at the step of entering the amount.
Secondly, everything that goes with you after sending a message with a question needs to be taken away from the block that listens to the button being pressed, into listening to the messages being sent. There, check that the user is at the step of entering the amount, and then extract the amount, put it in `cheque` and send the next message. And fix that the user has gone to another step.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question