yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.3k stars 1.5k forks source link

[Question] How to Emit message event from a group ? #1022

Closed dajneem23 closed 1 year ago

dajneem23 commented 1 year ago

How emit event text message from a group (bot: admin) ? this is my code

export const TelegramLoader = async () => { const logger = Container.get(DILogger); // Create a bot that uses 'polling' to fetch new updates const bot = new TelegramBot(token, { polling: true });

// // Matches "[whatever]" bot.onText(/.*/, (msg, match) => { logger.debug('info', JSON.stringify(msg));

const chatId = msg.chat.id;
const resp = match[1]; // the captured "whatever"

});

bot.on('message', (msg) => { const chatId = msg.chat.id; // send a message to the chat acknowledging receipt of their message logger.debug('info', JSON.stringify(msg)); bot.sendMessage(chatId, 'Received your message'); }); };

i tried both event message and text but it not work.

rblinde commented 1 year ago

See the documentation on Privacy mode:

Bots are frequently added to groups to perform basic tasks or assist moderators – like automatically posting company announcements or even celebrating birthdays. By default, all bots added to groups run in Privacy Mode and only see relevant messages and commands:

  • Commands explicitly meant for them (e.g., /command@this_bot).
  • General commands (e.g. /start) if the bot was the last bot to send a message to the group.
  • Inline messages sent via the bot.
  • Replies to any messages implicitly or explicitly meant for this bot.