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

# 正在发送消息

> 发送文本、 媒体、 联系人、 位置、 链接、 民意测验以及与 /发送端点的存在。

所有示例都假定基本认证`admin:changeme`, 一个叫做`my-device`, 的 GOWA 和 `localhost:3000`的 GOWA。

```bash theme={null}
export GOWA=http://localhost:3000
export AUTH=admin:changeme
export DEVICE=my-device
```

## 收件人

接受`phone`：

* 一个带有国家代码的数字，不含`+`、空格或破折号：`628123456789` (前面的`+` 是删除的)。
* 用户 JID：`628123456789@s.whatsapp.net`。
* 群组 JID：`120363025246125486@g.us`。
* `status@broadcast`来发布状态更新。

使用 `WHATSAPP_ACCOUNT_VALIDATION=true` (默认)，GOWA 检查一个数字在发送前是否在WhatsApp 上。请使用 `GET /user/check?phone=628123456789` 自行检查一下。

## 文本

```bash theme={null}
curl -u $AUTH -X POST $GOWA/send/message \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone": "628123456789", "message": "Hello!"}'
```

可选字段:

| 字段 | 描述 |
| - | - |
| `reply_message_id` | 引用以前的消息。 |
| `mentions` | 要提及的电话号码，例如 `["628111111111"]`；`"@everyone"` 会提及所有群组成员。提及时无需在消息文本中添加 `@`。 |
| `is_forwarded` | 显示"转发"标签。 |
| `duration` | 消灭消息计时器以秒计：`0`, `86400` (24 h), `604800` (7d) 或 `7776000` (90 d)。 |
| `allow_reshare` | 仅适用于状态发布（`phone` = `status@broadcast`）。 |

成功发送返回 WhatsApp 消息ID：

```json theme={null}
{"code": "SUCCESS", "message": "Success", "results": {"message_id": "3EB0B430B6F8F1D0E053AC120E0A9E5C", "status": "Message sent to 628123456789 (server timestamp: ...)"}}
```

## 媒体

媒体端点使用 `multipart/form-data` 。上传文件或通过 GOWA 下载的 URL (`*_url`)。

```bash Image theme={null}
curl -u $AUTH -X POST $GOWA/send/image -H "X-Device-Id: $DEVICE" \
  -F phone=628123456789 \
  -F caption="Product photo" \
  -F image=@photo.jpg \
  -F compress=true
```

```bash Image from URL theme={null}
curl -u $AUTH -X POST $GOWA/send/image -H "X-Device-Id: $DEVICE" \
  -F phone=628123456789 \
  -F image_url=https://example.com/photo.jpg
```

```bash Document theme={null}
curl -u $AUTH -X POST $GOWA/send/file -H "X-Device-Id: $DEVICE" \
  -F phone=628123456789 \
  -F caption="Invoice" \
  -F file=@invoice.pdf
```

```bash Video theme={null}
curl -u $AUTH -X POST $GOWA/send/video -H "X-Device-Id: $DEVICE" \
  -F phone=628123456789 \
  -F caption="Demo" \
  -F video=@demo.mp4
```

```bash Voice note theme={null}
curl -u $AUTH -X POST $GOWA/send/audio -H "X-Device-Id: $DEVICE" \
  -F phone=628123456789 \
  -F audio=@note.ogg \
  -F ptt=true
```

```bash Sticker theme={null}
curl -u $AUTH -X POST $GOWA/send/sticker -H "X-Device-Id: $DEVICE" \
  -F phone=628123456789 \
  -F sticker=@cat.png
```

| Endpoint | 文件字段 / URL 字段 | 额外字段 |
| - | - | - |
| `/send/image` | `image` / `image_url` | `caption`, `view_once`, `compress`, `hd`, `mentions` |
| `/send/video` | `video` / `video_url` | `caption`, `view_once`, `compress`, `hd`, `gif_playback`, `mentions` |
| `/send/file` | `file` / `file_url` | `caption`, `mentions` |
| `/send/audio` | `audio` / `audio_url` | `ptt` (作为语音笔记发送) |
| `/send/sticker` | `sticker` / `sticker_url` | JPG, PNG, WebP 或 GIF; 转换为 WebP |

所有媒体端点也接受 `reply_message_id`、`is_forwarded` 和 `duration`。有关大小限制和格式，请参阅[媒体处理](https://gowa-docs.mintlify.site/zh/examples/media-handling.md)。

## 联系人、位置、链接、调查

```bash Contact theme={null}
curl -u $AUTH -X POST $GOWA/send/contact \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone": "628123456789", "contact_name": "Jane Doe", "contact_phone": "628987654321"}'
```

```bash Location theme={null}
curl -u $AUTH -X POST $GOWA/send/location \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone": "628123456789", "latitude": "-6.200000", "longitude": "106.816666"}'
```

```bash Link theme={null}
curl -u $AUTH -X POST $GOWA/send/link \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone": "628123456789", "link": "https://github.com", "caption": "Check this out"}'
```

```bash Poll theme={null}
curl -u $AUTH -X POST $GOWA/send/poll \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone": "628123456789", "question": "Lunch?", "options": ["Pizza", "Sushi", "Salad"], "max_answer": 1}'
```

## 存在和键入

```bash theme={null}
# account-wide presence: available | unavailable
curl -u $AUTH -X POST $GOWA/send/presence \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"type": "available"}'

# typing indicator in one chat: start | stop
curl -u $AUTH -X POST $GOWA/send/chat-presence \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone": "628123456789", "action": "start"}'
```

本地流按钮、位置请求和图像漫画，请查看 [实验性交互消息](https://gowa-docs.mintlify.site/zh/examples/interactive-messages.md)。

## 发送后

| 任务 | Endpoint |
| - | - |
| 编辑 | `POST /message/{message_id}/update`，携带 `phone`、`message` |
| React | `POST /message/{message_id}/reaction`，携带 `phone`、`emoji` |
| 为所有人删除 | `POST /message/{message_id}/revoke`，携带 `phone` |
| 为我删除 | `POST /message/{message_id}/delete`，携带 `phone` |
| 转发方式 | `POST /message/{message_id}/forward`，携带 `phone`（目标聊天）。源消息必须存在于 GOWA 的本地聊天存储中。 |
| 星/取消星星 | `POST /message/{message_id}/star`、`/unstar`，携带 `phone` |

### 编辑图像或文档标题

在 v9.9.0 之后的 GOWA `main` 分支上，将 `media_type` 设置为 `image` 或 `document`，且必须与原始消息一致。将 `message` 设置为替换后的说明文字，并省略 `link`。请将示例 ID 替换为你已发送消息的 ID。

```bash theme={null}
curl -u "$AUTH" -X POST "$GOWA/message/3EB0B430B6F8F1D0E053AC120E0A9E5C/update" \
  -H "Content-Type: application/json" -H "X-Device-Id: $DEVICE" \
  -d '{"phone":"628123456789","message":"Updated caption","media_type":"image"}'
```

## 稍后发送

在支持的发送请求中添加 `scheduled_at` 和 `timezone`，即可改为定时发送。`/send/interactive` 仅支持立即发送。参阅[定时发送](https://gowa-docs.mintlify.site/zh/examples/scheduled-sends.md)。

## 发送到许多收件人

GOWA 没有广播端点。请在代码中遍历收件人，每次发送一个请求并在请求之间加入延迟，遇到 `WA_REACHOUT_TIMELOCK` 错误时停止发送。批量发送前，请阅读[发送限制](https://gowa-docs.mintlify.site/zh/advanced/rate-limiting.md)。


## Related topics

- [发送消息](https://gowa-docs.mintlify.site/zh/api-reference/send/发送消息.md)
- [快速开始](https://gowa-docs.mintlify.site/zh/quickstart.md)
- [正在接收消息](https://gowa-docs.mintlify.site/zh/examples/receiving-messages.md)
- [预定发送](https://gowa-docs.mintlify.site/zh/examples/scheduled-sends.md)
- [发送限制](https://gowa-docs.mintlify.site/zh/advanced/rate-limiting.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.