help please, I am writing a telegram bot for feedback, at the moment it works in a private chat (i.e. the user writes to the bot – I answer reply the bot via reply and the user receives SMS from the bot), but does not work in the group chat( in a group I can see the user’s messages, but I can’t reply to the user through reply). it is necessary that any user from the group can reply to the user’s message
JavaScript
x
32
32
1
const bot = new Telegraf(token, {});
2
3
let replyText = {
4
'helloAdmin': '...',
5
'helloUser': '...',
6
'replyWrong': '....'
7
};
8
let isAdmin = userId => {
9
return userId === admin;
10
};
11
let forwardToAdmin = ctx => {
12
if (isAdmin(ctx.message.from.id)) {
13
ctx.reply(replyText.replyWrong);
14
} else {
15
ctx.forwardMessage(admin, ctx.from.id, ctx.message.id);
16
}
17
};
18
bot.start(ctx => {
19
ctx.reply(isAdmin(ctx.message.from.id)
20
? replyText.helloAdmin
21
: replyText.helloUser);
22
});
23
24
bot.on('message', ctx => {
25
if (ctx.message.reply_to_message && ctx.message.reply_to_message.forward_from && isAdmin(ctx.message.from.id)) {
26
ctx.telegram.sendCopy(ctx.message.reply_to_message.forward_from.id, ctx.message);
27
} else {
28
forwardToAdmin(ctx);
29
}
30
});
31
bot.launch();
32
Advertisement
Answer
there is a getChatAdministrators
method (https://core.telegram.org/bots/api#getchatadministrators), I guess you can use it to get Admins of the group and check if one of them is replied. In that case forward it back to user