I need help implementing message reactions for my Telegram bot using JavaScript. When users send messages or media files, I want the bot to respond with emoji reactions. I tried one approach but it’s not working properly. Can someone share a working solution or alternative method?
async function addEmojiReaction(channelId, msgId, reactionEmoji) {
const apiEndpoint = `${BOT_API_BASE}/sendMessage`;
const requestData = {
chat_id: channelId,
text: reactionEmoji,
reply_to_message_id: msgId,
};
try {
const result = await fetch(apiEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestData)
});
console.log('Reaction added:', await result.json());
} catch (err) {
console.error('Failed to add reaction:', err);
}
}
async function processIncomingMedia(msgData) {
const chatIdentifier = msgData.chat.id;
const messageIdentifier = msgData.message_id;
const mediaId = msgData.photo
? msgData.photo[msgData.photo.length - 1].file_id
: msgData.document
? msgData.document.file_id
: null;
if (mediaId) {
await addEmojiReaction(chatIdentifier, messageIdentifier, '❤️');
console.log('Media processed successfully');
}
}
Any suggestions would be helpful. Thanks!