yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.45k stars 1.53k forks source link

bot.on("message") not triggered #931

Closed christopheSeeka closed 2 years ago

christopheSeeka commented 2 years ago

Hello,

I installed latest version of the lib and i'm trying to follow the basic example but for some reason, the bot.on("message") is not triggered when i do a /start then "hi" to my bot, here is my code:

const TelegramBot = require('node-telegram-bot-api');
const token = '508***0Rg';

const bot = new TelegramBot(token, {polling: true});

bot.on('message', (msg) => {
  console.log(msg)
});

then i run node index.js i get the following warning: "node-telegram-bot-api deprecated Automatic enabling of cancellation of promises is deprecated."

and then nothing happens when i /start then message the bot

i tried also NTBA_FIX_319=1 node index.js, it remove the warning but doesnt change the problem.

What can i be doing wrong?

PabloFacciano commented 2 years ago

Hello, did you try bot.on('text', ...) ?

christopheSeeka commented 2 years ago

Hello, thank you for the answer, yes i tried both and they were not working but i finally figured it. I just created a new bot and it worked... not sure why... I guess it's because i first didn't set the privacy to the bot and added it to my test group, then i set privacy. Probably would have had to removed it and re add it to the group? Anyway, fixed, thank you very much :)

danielperez9430 commented 2 years ago

Yes, for read messages in a group that is not a bot command (/...@botalias) you need to change the bot privacy in @BotFather. In the other case you can only listen the message when the user is talk with the bot (user <-> bot chat 1 to 1)