Nojde Telegram API -- how do I use ForceReply?

Viewed 168

Hi im new with this type of programming so im triying to do a bot, that allows me to create something like a poll but before that, i wanna know some information from the user (which I'll use later), so i triying to use forceReplay for that, but i dont know how to start to interacting with the user after that

bot.start((ctx) => {
const opts = {
 reply_markup: JSON.stringify(
   {
     force_reply: true,
   }
 )};
bot.telegram.sendMessage(ctx.chat.id, 'Hi what is your name?', opts);
});

this is my initial code, so, what i need to do from this is wait for the user to write his name and then start a new question...

Note: im using telegraf to create my bot

1 Answers

This is the code I referenced from: Link

bot.onText(/\/start/, async(msg) => {
  let listenerReply;

  let contentMessage = await bot.sendMessage(msg.chat.id, "Type your name: ", {
      "reply_markup": {
          "force_reply": true
      }
  });
  listenerReply = (async (replyHandler) => {
      bot.removeReplyListener(listenerReply);
      await bot.sendMessage(replyHandler.chat.id, `Ohh your name is ${replyHandler.text}`, {"reply_markup": {"force_reply": false}})

  });
  bot.onReplyToMessage(contentMessage.chat.id, contentMessage.message_id, listenerReply);
});

Hope it helps you

Related