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

# Mengirim Pesan

> Kirim teks, media, lokasi, polling, kontak, reaksi, dan lainnya melalui Wappfy API.

# Mengirim Pesan

Semua pesan dikirim melalui satu endpoint. Field `type` menentukan jenis pesan yang dikirim, dan field lainnya berubah sesuai dengan jenis pesan tersebut.

**Endpoint:**

```
POST https://api.wappfy.io/api/instances/{instanceId}/messages/send
```

**Header:**

| Header         | Nilai              |
| -------------- | ------------------ |
| `X-Api-Key`    | API key Anda       |
| `Content-Type` | `application/json` |

***

## Pesan Teks

Kirim pesan teks biasa.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "text",
      "text": "Hello from Wappfy!"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "text",
        text: "Hello from Wappfy!",
      }),
    }
  );

  const result = await response.json();
  console.log(result.data.message_id);
  ```
</CodeGroup>

**Respons:**

```json theme={null}
{
  "data": {
    "message_id": "BAE5F2C4D3B2A1",
    "status": "sent"
  }
}
```

***

## Pesan Gambar

Kirim gambar dengan keterangan opsional.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "image",
      "media_url": "https://example.com/photo.jpg",
      "caption": "Check out this photo!"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "image",
        media_url: "https://example.com/photo.jpg",
        caption: "Check out this photo!",
      }),
    }
  );
  ```
</CodeGroup>

***

## Pesan Video

Kirim file video dengan keterangan opsional.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "video",
      "media_url": "https://example.com/clip.mp4",
      "caption": "Watch this!"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "video",
        media_url: "https://example.com/clip.mp4",
        caption: "Watch this!",
      }),
    }
  );
  ```
</CodeGroup>

***

## Pesan Audio

Kirim file audio. Pesan audio muncul sebagai pesan suara di WhatsApp.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "audio",
      "media_url": "https://example.com/voice-note.ogg"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "audio",
        media_url: "https://example.com/voice-note.ogg",
      }),
    }
  );
  ```
</CodeGroup>

<Note>
  Untuk kompatibilitas terbaik, gunakan file `.ogg` yang di-encode dengan codec Opus untuk pesan suara.
</Note>

***

## Pesan Dokumen

Kirim file sebagai lampiran dokumen.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "document",
      "media_url": "https://example.com/report.pdf",
      "filename": "Q1-Report.pdf",
      "caption": "Here is the quarterly report"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "document",
        media_url: "https://example.com/report.pdf",
        filename: "Q1-Report.pdf",
        caption: "Here is the quarterly report",
      }),
    }
  );
  ```
</CodeGroup>

***

## Pesan Lokasi

Kirim pin lokasi geografis.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "location",
      "latitude": -23.5505,
      "longitude": -46.6333,
      "name": "Sao Paulo",
      "address": "Sao Paulo, SP, Brazil"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "location",
        latitude: -23.5505,
        longitude: -46.6333,
        name: "Sao Paulo",
        address: "Sao Paulo, SP, Brazil",
      }),
    }
  );
  ```
</CodeGroup>

***

## Pesan Polling

Buat polling interaktif. Penerima dapat memberikan suara langsung di WhatsApp.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "poll",
      "poll_name": "What day works best for the meeting?",
      "poll_options": ["Monday", "Wednesday", "Friday"],
      "poll_allow_multiple": false
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "poll",
        poll_name: "What day works best for the meeting?",
        poll_options: ["Monday", "Wednesday", "Friday"],
        poll_allow_multiple: false,
      }),
    }
  );
  ```
</CodeGroup>

***

## Pesan Kontak / vCard

Bagikan kartu kontak.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "contact",
      "contact_name": "Maria Silva",
      "contact_phone": "+5511988887777"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "contact",
        contact_name: "Maria Silva",
        contact_phone: "+5511988887777",
      }),
    }
  );
  ```
</CodeGroup>

***

## Teruskan Pesan

Teruskan pesan yang sudah ada ke chat lain.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511888887777@s.whatsapp.net",
      "type": "forward",
      "forward_message_id": "BAE5F2C4D3B2A1",
      "forward_chat_id": "5511999998888@s.whatsapp.net"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511888887777@s.whatsapp.net",
        type: "forward",
        forward_message_id: "BAE5F2C4D3B2A1",
        forward_chat_id: "5511999998888@s.whatsapp.net",
      }),
    }
  );
  ```
</CodeGroup>

***

## Reaksi

Bereaksi terhadap pesan dengan emoji.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "reaction",
      "reaction_message_id": "BAE5F2C4D3B2A1",
      "reaction": "\ud83d\udc4d"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "reaction",
        reaction_message_id: "BAE5F2C4D3B2A1",
        reaction: "\ud83d\udc4d",
      }),
    }
  );
  ```
</CodeGroup>

<Tip>
  Untuk menghapus reaksi, kirim string kosong sebagai nilai `reaction`.
</Tip>

***

## Fitur Lanjutan

### Membalas Pesan

Kutip pesan sebelumnya dengan menyertakan `quoted_message_id`. Ini berfungsi dengan semua jenis pesan.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "text",
      "text": "Yes, I agree with this!",
      "quoted_message_id": "BAE5F2C4D3B2A1"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "text",
        text: "Yes, I agree with this!",
        quoted_message_id: "BAE5F2C4D3B2A1",
      }),
    }
  );
  ```
</CodeGroup>

### Mengedit Pesan Terkirim

Edit pesan yang sebelumnya Anda kirim dengan menyertakan `edit_message_id`.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "5511999998888@s.whatsapp.net",
      "type": "text",
      "text": "Updated message content",
      "edit_message_id": "BAE5F2C4D3B2A1"
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "5511999998888@s.whatsapp.net",
        type: "text",
        text: "Updated message content",
        edit_message_id: "BAE5F2C4D3B2A1",
      }),
    }
  );
  ```
</CodeGroup>

<Warning>
  Anda hanya dapat mengedit pesan yang Anda kirim sendiri. Pengeditan memiliki batasan waktu yang ditetapkan oleh WhatsApp (kurang lebih 15 menit setelah pengiriman).
</Warning>

### Mention

Mention kontak tertentu dalam pesan grup. Kontak yang di-mention akan menerima notifikasi.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/messages/send \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chat_id": "120363012345678901@g.us",
      "type": "text",
      "text": "Hey @Maria and @Carlos, please review this.",
      "mentions": [
        "5511999998888@s.whatsapp.net",
        "5511888887777@s.whatsapp.net"
      ]
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/messages/send",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        chat_id: "120363012345678901@g.us",
        type: "text",
        text: "Hey @Maria and @Carlos, please review this.",
        mentions: [
          "5511999998888@s.whatsapp.net",
          "5511888887777@s.whatsapp.net",
        ],
      }),
    }
  );
  ```
</CodeGroup>

***

## Format Chat ID

| Format                   | Deskripsi       | Contoh                         |
| ------------------------ | --------------- | ------------------------------ |
| `{phone}@s.whatsapp.net` | Chat individual | `5511999998888@s.whatsapp.net` |
| `{id}@g.us`              | Chat grup       | `120363012345678901@g.us`      |

***

## Nomor Telepon Brasil

<Note>
  Wappfy secara otomatis menangani masalah digit ke-9 nomor Brasil. Jika pesan gagal dengan error "no LID found", sistem akan secara otomatis mencoba ulang dengan format alternatif (menambahkan atau menghapus digit ke-9).

  Sebagai contoh, jika `5511999998888` gagal, sistem akan mencoba ulang dengan `551199998888`, dan sebaliknya. Ini terjadi secara transparan -- Anda tidak perlu menanganinya sendiri.
</Note>

***

## Referensi Jenis Pesan

| Jenis      | Field Wajib                             | Field Opsional                                     |
| ---------- | --------------------------------------- | -------------------------------------------------- |
| `text`     | `text`                                  | `quoted_message_id`, `edit_message_id`, `mentions` |
| `image`    | `media_url`                             | `caption`, `quoted_message_id`                     |
| `video`    | `media_url`                             | `caption`, `quoted_message_id`                     |
| `audio`    | `media_url`                             | `quoted_message_id`                                |
| `document` | `media_url`                             | `filename`, `caption`, `quoted_message_id`         |
| `location` | `latitude`, `longitude`                 | `name`, `address`, `quoted_message_id`             |
| `poll`     | `poll_name`, `poll_options`             | `poll_allow_multiple`                              |
| `contact`  | `contact_name`, `contact_phone`         | `quoted_message_id`                                |
| `forward`  | `forward_message_id`, `forward_chat_id` | --                                                 |
| `reaction` | `reaction_message_id`, `reaction`       | --                                                 |

***

## Penanganan Error

| Kode Status | Deskripsi                                                                               |
| ----------- | --------------------------------------------------------------------------------------- |
| `400`       | Payload pesan tidak valid (misalnya, field wajib tidak ada untuk jenis yang diberikan). |
| `404`       | Instance tidak ditemukan atau tidak terhubung.                                          |
| `422`       | Validasi pesan gagal (misalnya, format nomor telepon tidak valid).                      |
| `429`       | Batas laju terlampaui. Lihat [Batas Laju](/id/rate-limits).                             |
| `502`       | Provider WhatsApp mengembalikan error. Periksa pesan error untuk detailnya.             |
