0

Imagine that theres one user message in the chat, and I, as another user, do the following

Answer to his text with: /tip 50

I basically want to somehow receive , the user to whom I have answered to, (his id) , and the second parameter. I cant seem how to do so since msg doesnt contain the id of the user who you answered to

I dont really have anything right now, this is my code

    `bot.onText(/\/tip/,(msg,res) => {
    var tg_chat_id = msg.chat.id
    var tg_ser_id = msg.from.id
    console.log(res)
    console.log(msg)
    // bot.onReplyToMessage(msg.chat.id, msg.from.id)

})`

I was thinking about logging the msg and finding there the userID to whom I answered. But I cant see it. Maybe I can use bot.onReplyToMessage to achieve it, but I dont understand it.

mouchin777
  • 1,428
  • 1
  • 31
  • 59

1 Answers1

1

To capture the passed parameter within the onText method, you need to compose your regexp properly and pass the match to the callback function. To reply to a specific message, pass the reply_to_message_id option to the sendMessage method, like this:

bot.onText(/\/tip (.+)/, (msg, match) => {
    let chatId = msg.chat.id;
    let messageId = msg.message_id;
    let tipValue = match[1];
    bot.sendMessage(chatId, `You tipped with value: ${tipValue}`, {
        reply_to_message_id: messageId
    });
});

This will result in the following bot's reply:

enter image description here

Bandantonio
  • 816
  • 1
  • 7
  • 19