Skip to main content

Reaction Messages

Reaction messages allow you to send emoji reactions to specific messages in a WhatsApp conversation. This is similar to how users can react to messages in the WhatsApp application.

Basic Usage

import WhatsApp from 'meta-cloud-api';

// Initialize client
const whatsapp = new WhatsApp({
phoneNumberId: YOUR_PHONE_NUMBER_ID,
accessToken: 'YOUR_ACCESS_TOKEN'
});

// Send a reaction to a message
const response = await whatsapp.messages.reaction(
"😊", // emoji
"wamid.abcd1234...", // message ID to react to
15551234567 // recipient
);

console.log(`Reaction message sent with ID: ${response.data.messages[0].id}`);

Parameters

The reaction() method accepts the following parameters:

ParameterTypeDescription
emojistringThe emoji to use as a reaction
messageIdstringThe ID of the message to react to
recipientstring or numberThe recipient's phone number with country code

Examples

Reacting to a Message with an Emoji

const response = await whatsapp.messages.reaction(
"👍",
"wamid.HBgLMTY1MDUwNzY1MjAVAgARGBI5QTNDQTVCM0Q0Q0Q2RTY3RTcA",
15551234567
);

Removing a Reaction

To remove a reaction, send an empty string as the emoji:

const response = await whatsapp.messages.reaction(
"",
"wamid.HBgLMTY1MDUwNzY1MjAVAgARGBI5QTNDQTVCM0Q0Q0Q2RTY3RTcA",
15551234567
);

Common Emoji Reactions

Here are some commonly used emoji reactions:

EmojiUnicodeDescription
👍U+1F44DThumbs up
❤️U+2764 FE0FRed heart
😂U+1F602Face with tears of joy
😮U+1F62EFace with open mouth
😢U+1F622Crying face
🙏U+1F64FFolded hands
🔥U+1F525Fire
👏U+1F44FClapping hands

Error Handling

try {
const response = await whatsapp.messages.reaction(
"👍",
"wamid.HBgLMTY1MDUwNzY1MjAVAgARGBI5QTNDQTVCM0Q0Q0Q2RTY3RTcA",
15551234567
);
console.log("Reaction message sent successfully:", response.data);
} catch (error) {
console.error("Error sending reaction message:", error);

// Handle specific error cases
if (error.response && error.response.data) {
if (error.response.data.error.code === 131051) {
console.log("Message to react to not found");
} else {
console.log("Error details:", error.response.data);
}
}
}

Limitations

  • You can only react to messages that are still available in the chat history
  • You can only use one emoji per reaction
  • The message ID must be valid and accessible
  • Not all emoji are supported as reactions

Best Practices

  1. Use common emojis: Stick to commonly used reaction emojis for better compatibility.

  2. React promptly: Reactions are most meaningful when sent promptly after receiving a message.

  3. Use reactions appropriately: Choose reactions that make sense in the context of the conversation.

  4. Don't overuse reactions: Use reactions sparingly and when they add value to the conversation.

  5. Consider cultural context: Be aware that emoji meanings can vary across different cultures.