Alwi Muhammad
Alwi Muhammad

Reputation: 21

Waiting for a message response using Telegraf/Node.js

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();

Upvotes: 1

Views: 8849

Answers (2)

Nehemiah Aklil
Nehemiah Aklil

Reputation: 11

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

Upvotes: 1

TAB_mk
TAB_mk

Reputation: 51

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

Upvotes: 0

Related Questions