JavaScript implementation for adding reactions to Telegram bot messages

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!

The problem is you’re using the Bot API, which has limited support for reactions. You need to utilize setMessageReaction for proper emoji reactions, but it only functions in specific chats and requires the necessary permissions. Personally, I have found more success with MTProto libraries like GramJS or telegram-js, as they provide greater control over reactions. If you’re constrained to the Bot API, your emoji reply workaround is decent; just ensure to set disable_notification to true to avoid spamming users. Additionally, check if reactions are permitted by using getChatMember to confirm your bot’s permissions.

Had this exact problem building a customer support bot last year. setMessageReaction works but it’s pretty limited - only works in supergroups and channels with reactions enabled, and even then it can fail silently based on chat settings. I ended up using a hybrid approach: try setMessageReaction first, then fall back to a small inline keyboard with reaction buttons if it fails. This way users can still interact even when direct reactions don’t work. Also, some clients don’t show bot reactions properly, so the fallback ensures it works consistently across different Telegram clients.

you’re mixing up reactions with regular messages. telegram has actual reaction endpoints now - use setMessageReaction instead of sendMessage. that code just sends a heart emoji as a separate message, not as a reaction.