群聊回复(telegram bot - support) (NODE JS)



请帮忙,我正在写一个电报机器人反馈,目前它在私人聊天中工作(即用户写信给机器人-我通过回复回答回复机器人,用户从机器人收到短信),但在组聊天中不工作(在组中我可以看到用户的消息,但我不能通过回复回复用户)。需要组中的任何用户都可以回复用户的消息

const bot = new Telegraf(token, {});
let replyText = {
'helloAdmin': '...',
'helloUser': '...',
'replyWrong': '....'
};
let isAdmin = userId => {
return userId === admin;
};
let forwardToAdmin = ctx => {
if (isAdmin(ctx.message.from.id)) {
ctx.reply(replyText.replyWrong);
} else {
ctx.forwardMessage(admin, ctx.from.id, ctx.message.id);
}
};
bot.start(ctx => {
ctx.reply(isAdmin(ctx.message.from.id)
? replyText.helloAdmin
: replyText.helloUser);
});
bot.on('message', ctx => {
if (ctx.message.reply_to_message && ctx.message.reply_to_message.forward_from && isAdmin(ctx.message.from.id)) {
ctx.telegram.sendCopy(ctx.message.reply_to_message.forward_from.id, ctx.message);
} else {
forwardToAdmin(ctx);
}
});
bot.launch();

有一个getChatAdministrators方法(https://core.telegram.org/bots/api#getchatadministrators),我想你可以用它来获得组的管理员,并检查其中一个是否回复。在这种情况下,将其转发回用户

最新更新