node.jstelegramtelegram-bottelegraftelegraf.js

Why bot.reaction() by Telegraf.js for Telegram Bot doesn't work?


Trying to develop a telegram bot with Telegraf.js when I try to listen message reactions the code doesn't work. The code appears the same as Telegraf 4.16.0 Release Notes - Working with Reactions

My demo code:

const {Telegraf} = require('telegraf');

const dotenv = require('dotenv');

// Load DOTENV
dotenv.config();
// Config
const BOT_TOKEN = process.env.BOT_TOKEN || '';
// Init bot
const bot = new Telegraf(BOT_TOKEN);

bot.reaction("👍", (ctx) => {
    // user added a 👍 reaction
    console.log("added")
});

bot.launch();
console.log(`Launch local with token: ${BOT_TOKEN}`)

package.json - dependencies

"dependencies": {
    "dayjs": "^1.11.7",
    "dotenv": "^16.0.3",
    "mongodb": "^4.13.0",
    "rss-parser": "^3.12.0",
    "telegraf": "^4.16.3"
  }

I have tried with specific version 4.16.0 and other ways like bot.on('message_reaction') but anything happened Thanks for the help.


Solution

  • Was having same problem here, turns out that reactions are not send by Telegram by default, you have to enable it.

    // enable updates from reactions
    bot.launch({ allowedUpdates: [ "message", "message_reaction" ] });