How to get & read user replies message sent to the bot? #2007
Unanswered
wexford-larry
asked this question in
Q&A
Replies: 1 comment
-
You need to send a message with the const { Telegraf } = require('telegraf');
const bot = new Telegraf('<YOUR_BOT_TOKEN>');
bot.command('start', (ctx) => {
ctx.reply('Please reply to this message:', {
reply_markup: {
force_reply: true,
},
});
}); After the user replies to the message, you can listen for messages in the bot and capture the reply. You can then store it in a variable or perform any action you want with the user's input. bot.on('text', (ctx) => {
if (ctx.message.reply_to_message && ctx.message.reply_to_message.text === 'Please reply to this message:') {
const userReply = ctx.message.text;
console.log(`User replied: ${userReply}`);
// You can perform any action with the reply here
ctx.reply(`You replied: ${userReply}`);
}
}); Finally, start the bot to handle the incoming updates. bot.launch(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm making a simple telegram bot with this library. I want to ask how I can make user forceReply to a message and then read that message or get it into a variable and do something with it.
This library have little to no clear documentations
Beta Was this translation helpful? Give feedback.
All reactions