curl -X POST "https://live-mt-server.wati.io/api/ext/v3/messageTemplates/send" \
-H "Authorization: Bearer $WATI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"template_name": "order_update",
"broadcast_name": "order_update_api",
"recipients": [
{
"phone_number": "14155552671",
"custom_params": [
{ "name": "name", "value": "Maya" },
{ "name": "order_id", "value": "10482" }
]
}
]
}'
const res = await fetch("https://live-mt-server.wati.io/api/ext/v3/messageTemplates/send", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WATI_API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
template_name: "order_update",
broadcast_name: "order_update_api",
recipients: [
{
phone_number: "14155552671",
custom_params: [
{ name: "name", value: "Maya" },
{ name: "order_id", value: "10482" },
],
},
],
}),
});
console.log(await res.json());
import os
import requestsresp = requests.post(
"https://live-mt-server.wati.io/api/ext/v3/messageTemplates/send",
headers={"Authorization": f"Bearer {os.environ['WATI_API_TOKEN']}"},
json={
"template_name": "order_update",
"broadcast_name": "order_update_api",
"recipients": [
{
"phone_number": "14155552671",
"custom_params": [
{"name": "name", "value": "Maya"},
{"name": "order_id", "value": "10482"},
],
}
],
},
timeout=30,
)
print(resp.json())
200 响应示例来自文档示例的结构
{
"success": true,
"broadcast_id": "broadcast_123456",
"recipients": [
{
"local_message_id": "local-msg-123",
"phone_number": "14155552671",
"errors": []
}
]
}
curl -X POST "https://live-mt-server.wati.io/api/ext/v3/conversations/messages/text" \
-H "Authorization: Bearer $WATI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"target": "14155552671",
"text": "Your order 10482 is out for delivery. Reply here to change the address."
}'
const res = await fetch("https://live-mt-server.wati.io/api/ext/v3/conversations/messages/text", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WATI_API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
target: "14155552671",
text: "Your order 10482 is out for delivery. Reply here to change the address.",
}),
});
console.log(await res.json());
import os
import requests
resp = requests.post(
"https://live-mt-server.wati.io/api/ext/v3/conversations/messages/text",
headers={"Authorization": f"Bearer {os.environ['WATI_API_TOKEN']}"},
json={
"target": "14155552671",
"text": "Your order 10482 is out for delivery. Reply here to change the address.",
},
timeout=30,
)
print(resp.json())
200 响应示例文档示例,已精简
{
"message": {
"id": "507f1f77bcf86cd799439011",
"type": "text",
"text": "Your order 10482 is out for delivery. Reply here to change the address.",
"owner": true,
"local_message_id": "88aed3c93a050b3c53978463",
"conversation_id": "685bd235e6119686e693a093",
"created": "2026-07-14T16:15:38.3992421Z",
"event_type": "message"
}
}
# 1. Wati 将每个新消息 POST 到您的 webhook URL(事件:message)。
# 2. 您的代码获取答案并将其发送回:
curl -X POST "https://live-mt-server.wati.io/api/ext/v3/conversations/messages/text" \
-H "Authorization: Bearer $WATI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"target": "14155552671",
"text": "Yes, we are open from 9am to 9pm."
}'
import express from "express";
const app = express();
app.use(express.json());
app.post("/wati", async (req, res) => {
res.sendStatus(200); // 先响应 Wati;若未收到 200 它会重试
const event = req.body;
if (event.eventType !== "message" || event.owner) return; // 仅限客户消息
const answer = /open|hours/i.test(event.text || "")
? "Yes, we are open from 9am to 9pm."
: "Thanks! A teammate will reply shortly.";
await fetch("https://live-mt-server.wati.io/api/ext/v3/conversations/messages/text", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WATI_API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ target: event.waId, text: answer }),
});
});
app.listen(3000);
import os
import re
import requests
from flask import Flask, request
app = Flask(__name__)Fragment 3 of 5. Translate only the text inside this item.
@app.post("/wati")
def wati_webhook():
event = request.get_json(silent=True) or {}
if event.get("eventType") == "message" and not event.get("owner"):
text = event.get("text") or ""
answer = (
"Yes, we are open from 9am to 9pm."
if re.search("open|hours", text, re.I)
else "Thanks! A teammate will reply shortly."
)
requests.post(
"https://live-mt-server.wati.io/api/ext/v3/conversations/messages/text",
headers={"Authorization": f"Bearer {os.environ['WATI_API_TOKEN']}"},
json={"target": event["waId"], "text": answer},
timeout=30,
)
return "", 200
IN Wati 发送到你 URL 的内容来自文档示例的字段,已裁剪
{
"eventType": "message",
"id": "69282478274a880fe782b2d9",
"conversationId": "68c8d56157578adb12ada249",
"waId": "14155552671",
"senderName": "Maya",
"type": "text",
"text": "Are you open tomorrow?",
"owner": false,
"timestamp": "1764238453"
}
curl -X POST "https://live-mt-server.wati.io/api/ext/v3/chatbots/start" \
-H "Authorization: Bearer $WATI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"target": "14155552671",
"chatbot_id": "607f1f77bcf86cd799439011"
}'
const res = await fetch("https://live-mt-server.wati.io/api/ext/v3/chatbots/start", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WATI_API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
target: "14155552671",
chatbot_id: "607f1f77bcf86cd799439011", // 来自 GET /chatbots
}),
});
console.log(await res.json());
import os
import requests
resp = requests.post(
"https://live-mt-server.wati.io/api/ext/v3/chatbots/start",
headers={"Authorization": f"Bearer {os.environ['WATI_API_TOKEN']}"},
json={
"target": "14155552671",
"chatbot_id": "607f1f77bcf86cd799439011", # 来自 GET /chatbots
},
timeout=30,
)
print(resp.json())
200 响应示例文档示例。适用于 Pro 和 Business 套餐
{
"result": true
}
curl -X POST "https://live-mt-server.wati.io/api/ext/v3/contacts" \
-H "Authorization: Bearer $WATI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"whatsapp_number": "14155552671",
"name": "Maya",
"custom_params": [
{ "name": "city", "value": "Singapore" },
{ "name": "customer_tier", "value": "vip" }
]
}'
const res = await fetch("https://live-mt-server.wati.io/api/ext/v3/contacts", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WATI_API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
whatsapp_number: "14155552671",
name: "Maya",
custom_params: [
{ name: "city", value: "Singapore" },
{ name: "customer_tier", value: "vip" },
],
}),
});
console.log(await res.json());
import os
import requestsresp = requests.post(
"https://live-mt-server.wati.io/api/ext/v3/contacts",
headers={"Authorization": f"Bearer {os.environ['WATI_API_TOKEN']}"},
json={
"whatsapp_number": "14155552671",
"name": "Maya",
"custom_params": [
{"name": "city", "value": "Singapore"},
{"name": "customer_tier", "value": "vip"},
],
},
timeout=30,
)
print(resp.json())
200 示例响应文档示例,已裁剪
{
"id": "507f1f77bcf86cd799439011",
"wa_id": "14155552671",
"name": "Maya",
"phone": "+14155552671",
"opted_in": true,
"custom_params": [
{ "name": "city", "value": "Singapore" },
{ "name": "customer_tier", "value": "vip" }
],
"channel_type": "whatsapp"
}
curl -X POST "https://live-mt-server.wati.io/api/ext/v3/comments/$COMMENT_ID/privateReply" \
-H "Authorization: Bearer $WATI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"channel": "yourbrand",
"userId": "17841400000000000",
"userName": "maya",
"type": "text",
"text": "Hi Maya, yes we do. Chat with us on WhatsApp for shipping options."
}'
const commentId = "17900000000000000"; // 来自 GET /posts/{post_id}/comments
const res = await fetch(`https://live-mt-server.wati.io/api/ext/v3/comments/${commentId}/privateReply`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WATI_API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
channel: "yourbrand",
userId: "17841400000000000",
userName: "maya",
type: "text",
text: "Hi Maya, yes we do. Chat with us on WhatsApp for shipping options.",
}),
});
console.log(await res.json());
import os
import requests
comment_id = "17900000000000000" # 来自 GET /posts/{post_id}/commentsFragment 5 of 5. Translate only the text inside this item.
resp = requests.post(
f"https://live-mt-server.wati.io/api/ext/v3/comments/{comment_id}/privateReply",
headers={"Authorization": f"Bearer {os.environ['WATI_API_TOKEN']}"},
json={
"channel": "yourbrand",
"userId": "17841400000000000",
"userName": "maya",
"type": "text",
"text": "Hi Maya, yes we do. Chat with us on WhatsApp for shipping options.",
},
timeout=30,
)
print(resp.json())
200 示例响应来自文档架构的响应结构
{
"ok": true,
"result": "success"
}