> ## Documentation Index
> Fetch the complete documentation index at: https://messages.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Reactions

> Send and receive iMessage reactions

iMessage reactions are the emoji responses native to iMessage: love, like, dislike,
laugh, emphasize, and question. You can send them on any message and receive them
via webhooks.

## Send a reaction

To react to a message, you need the message's `id` or `guid` (both are returned
when listing messages) and the recipient's handle:

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  import { createClient } from "@messages-dev/sdk";

  const client = createClient();

  await client.sendReaction({
    from: "+15551234567",
    to: "+15559876543",
    messageId: "msg_abc123",
    type: "love",
  });
  ```

  ```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  curl -X POST "https://api.messages.dev/v1/reactions" \
    -H "Authorization: Bearer sk_live_..." \
    -H "Content-Type: application/json" \
    -d '{
      "from": "+15551234567",
      "to": "+15559876543",
      "message_id": "msg_abc123",
      "type": "love"
    }'
  ```
</CodeGroup>

You can pass either a `msg_` prefixed ID or a raw iMessage GUID as the `message_id`.

### Reaction types

| Type        | Emoji |
| ----------- | ----- |
| `love`      | ❤️    |
| `like`      | 👍    |
| `dislike`   | 👎    |
| `laugh`     | 😂    |
| `emphasize` | ‼️    |
| `question`  | ❓     |

## Receive reactions via webhooks

Subscribe to `reaction.added` and `reaction.removed` events to get notified when
someone reacts to a message:

```typescript theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
import { verifyWebhook } from "@messages-dev/sdk";

app.post("/webhooks", async (req, res) => {
  const event = await verifyWebhook(
    req.body,
    req.headers["x-webhook-signature"],
    "your_webhook_secret",
  );

  if (event.event === "reaction.added") {
    console.log(`${event.data.sender} reacted with ${event.data.type}`);
  }

  if (event.event === "reaction.removed") {
    console.log(`${event.data.sender} removed their ${event.data.type} reaction`);
  }

  res.sendStatus(200);
});
```

## List reactions on a message

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  const reactions = await client.listReactions({
    messageId: "msg_abc123",
  });

  for (const reaction of reactions.data) {
    console.log(`${reaction.sender}: ${reaction.type} (${reaction.added ? "added" : "removed"})`);
  }
  ```

  ```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
  curl "https://api.messages.dev/v1/reactions?message_id=msg_abc123" \
    -H "Authorization: Bearer sk_live_..."
  ```
</CodeGroup>

## Finding the message ID

Both the `id` and `guid` fields are returned on every message object. You can use
either one when sending reactions:

```typescript theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
const messages = await client.listMessages({
  from: "+15551234567",
  to: "+15559876543",
  limit: 1,
});

await client.sendReaction({
  from: "+15551234567",
  to: "+15559876543",
  messageId: messages.data[0].id,
  type: "love",
});
```
