skip to Main Content

I would like to wait for the user to send a message, then assign the new message to a variable.

How can I wait for a message reply using Telegraf on Node.js?

const Telegraph = require("telegraf");
const APIKEY = 'LADLADJLDAKJLAK;LAKS;LSAKLDA,MDALJDALJLDAJLDAJLDAJDALDAJLADJ'
const bot = new Telegraph(APIKEY);
const loginMessage = `
PLEASE ENTER YOUR EMAIL:
`;
bot.command("login", (ctx) => {
    ctx.reply("You Entered Login");
    ctx.reply(loginMessage);//login message:Please Enter EMAIL
    //wait for user to send message
    //ASSIGN MESSAGE TO VARIABLE
  });

bot.launch();

2

Answers


  1. There are few ways:

    1. Store chatID with state in any way (session middleware, object, db), like "123" : "login_step" and check state of user first.
    2. Use ForceReply: Add it to reply_markup of sendMessage. And check reply_to_message for your command
    Login or Signup to reply.
  2. You should consider using Scenes. but not just a normal scene but use WizardScene for better usage especially since you want your bot to kind of have an interview-like thing with users to get their info. To store user data use Session. Out of the boxes its stores its data on memory I think to be able to persist your data even after restart use this telegraf-session.

    Check out this tutorial it helped me out a lot How to build OCR Bot

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search