简体   繁体   中英

Telegram bot doesn't respond to message in group rather replies for the same in personal chat

Telegram bot using node js doesn't reply in the group. When I text it in the group, it replies to me immediately in my personal chat. -The group is a supergroup -The bot is an admin -Privacy setting is disabled Yet there is this problem. How do I do it??

const TelegramBot = require('node-telegram-bot-api');
const token = 'my bot_token here';
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
var Hi = "hi";
if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
    bot.sendMessage(msg.from.id, "Hello  " + msg.from.first_name);
} });

you should use chat.id instead of user.id:

const TelegramBot = require('node-telegram-bot-api');
const token = 'my bot_token here';
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
var Hi = "hi";
if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
    bot.sendMessage(msg.chat.id, "Hello  " + msg.from.first_name);
} });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM