wati-cli를 사용해 10분 안에 WhatsApp AI 에이전트 구축하기
Source: Dev.to
대시보드 없음. 끌어다 놓기 없음. 터미널, LLM, 그리고 몇 개의 명령만 있으면 됩니다.
우리는 방금 @wati-io/wati-cli를 출시했습니다 — 터미널만으로 WhatsApp AI 에이전트를 완전히 구축할 수 있게 해주는 커맨드라인 도구입니다. 모든 명령은 구조화된 JSON을 반환합니다. 모든 종료 코드는 의미가 있습니다. 이 도구는 스크립트, 자동화 파이프라인, AI 에이전트를 위해 설계되었으며, 버튼을 클릭하는 인간을 위한 것이 아닙니다.
10분 안에 제로에서 작동하는 AI 지원 에이전트를 만드는 방법을 소개합니다.
우리가 만들고 있는 것
- 웹훅을 통해 들어오는 고객 메시지를 수신합니다
- 고객의 프로필과 최근 대화 기록을 가져옵니다
- LLM을 사용해 상황에 맞는 답변을 생성합니다
- 답변을 WhatsApp으로 다시 전송합니다
- 복잡한 이슈는 사람에게 할당합니다
대시보드가 없습니다. 플로우 빌더도 없습니다. 오직 코드만 있습니다.
사전 요구 사항
npm install -g @wati-io/wati-cli
wati configure init
프롬프트에 따라 Wati API 기본 URL 및 인증 토큰을 입력하세요. 약 30 초면 완료됩니다.
단계 1: 수신 메시지 구독하기
wati webhooks subscribe \
--url https://your-server.com/webhook \
--events message,newContactMessageReceived
{
"id": "wh_abc123",
"url": "https://your-server.com/webhook",
"events": ["message", "newContactMessageReceived"],
"status": "Enabled"
}
이제 고객이 WhatsApp 메시지를 보낼 때마다 Wati가 해당 메시지를 귀하의 엔드포인트로 푸시합니다. 다른 이벤트도 구독할 수 있습니다 — sentMessageDELIVERED, sentMessageREAD, templateMessageSent 등.
언제든지 활성 웹훅을 확인하세요:
wati webhooks list --pretty
단계 2: 고객 컨텍스트 가져오기
메시지가 웹훅에 도착하면, 에이전트는 컨텍스트가 필요합니다 — 이 사람은 누구이며, 대화 기록은 무엇인가요?
# Who is this?
wati contacts get +852XXXXXXXX
{
"name": "John Doe",
"phone": "+852XXXXXXXX",
"tags": ["premium", "ecommerce"],
"customParams": [
{ "name": "plan", "value": "enterprise" },
{ "name": "ltv", "value": "2400" }
]
}
# What have we been talking about?
wati conversations messages +852XXXXXXXX --page-size 5
[
{ "text": "Where's my order?", "type": "received", "timestamp": "2026-03-06T14:20:00Z" },
{ "text": "Checking now — one moment!", "type": "sent", "timestamp": "2026-03-06T14:21:00Z" }
]
두 개의 명령. 전체 컨텍스트. 이제 LLM은 프리미엄 고객이 주문에 대해 문의하고 있다는 것을 알게 됩니다.
Step 3: 원하는 LLM으로 답변 생성하기
CLI는 LLM에 구애받지 않으며, 필요에 맞는 모델을 사용하면 됩니다. 아래 예시에서는 Anthropic의 Claude Sonnet 4.6(현재 에이전시 작업에서 최고 점수를 받은 모델)을 사용하지만, OpenAI, Gemini 또는 다른 제공자를 자유롭게 교체할 수 있습니다.
import anthropic, subprocess, json
def wati(args):
result = subprocess.run(["wati"] + args, capture_output=True, text=True)
return json.loads(result.stdout)
# Get contact + history via CLI
contact = wati(["contacts", "get", phone])
messages = wati(["conversations", "messages", phone, "--page-size", "5"])
# Build prompt
system_prompt = f"""You are a support agent for an ecommerce store.
Customer: {contact['name']} (plan: {contact['customParams'][0]['value']}, LTV: ${contact['customParams'][1]['value']})
Recent conversation:
{json.dumps(messages, indent=2)}
New message: "{incoming_message}"
Reply helpfully and concisely. If the issue is complex or the customer is upset, respond with ESCALATE."""
# Generate reply with Claude Sonnet 4.6
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": system_prompt}]
)
reply = response.content[0].text
대신 OpenAI를 사용하려면?
import openai
response = openai.chat.completions.create(
model="gpt-5.2",
messages=[{"role": "system", "content": system_prompt}]
)
reply = response.choices[0].message.content
4단계: 회신 전송 (또는 에스컬레이션)
import subprocess
if "ESCALATE" in reply:
# Route to human
subprocess.run([
"wati", "contacts", "assign-teams",
"--target", phone, "--teams", "Escalations"
])
subprocess.run([
"wati", "conversations", "assign-operator",
"--target", phone, "--email", "senior@company.com"
])
subprocess.run([
"wati", "conversations", "send-text",
"--target", phone,
"--text", "I'm connecting you with a specialist who can help further."
])
else:
# Auto‑reply
subprocess.run([
"wati", "conversations", "send-text",
"--target", phone, "--text", reply
])
subprocess.run([
"wati", "conversations", "update-status",
"--target", phone, "--status", "solved"
])
고객은 WhatsApp에서 상황에 맞고 개인화된 회신을 받게 됩니다. 복잡한 문제는 인간 담당자에게 전달됩니다. 대시보드는 열리지 않았습니다.
Step 5: 전달 및 참여 추적
메시지가 언제 전달되고 읽혔는지 알고 싶으신가요? 전달 이벤트를 구독하세요:
wati webhooks subscribe \
--url https://your-server.com/tracking \
--events sentMessageDELIVERED,sentMessageREAD,sentMessageREPLIED
이제 웹훅 엔드포인트에서 직접 전달, 읽음 확인 및 회신을 모니터링할 수 있습니다.
전체 그림
flowchart TD
A[Customer sends WhatsApp message] --> B[Wati webhook (message event) → your server]
B --> C[wati contacts get (who is this?)
wati conversations messages (what's the history?)]
C --> D[LLM generates reply with full context]
D --> E{Is it a simple query?}
E -->|Yes| F[wati send-text (auto‑reply)
wati update-status (mark solved)]
E -->|No| G[wati assign-teams (escalate)
wati assign-operator (route to human)]
F --> H[wati webhooks (track delivery + read receipts)]
G --> H
여섯 개의 CLI 명령어. 하나의 LLM 호출. 인간 에스컬레이션 및 전달 추적이 포함된 완전한 기능의 AI 지원 에이전트.
더 만들 수 있는 것들
AI 리드 자격 확인기
# Subscribe to new contact messages
wati webhooks subscribe --url https://... --events newContactMessageReceived
# Add a new unknown contact
wati contacts add --number +55... --name "..."
# Let the LLM qualify based on message content
wati contacts assign-teams --target +55... --teams "Hot Leads"
# Send a confirmation message
wati conversations send-text --target +55... --text "Thanks! Our sales team will be in touch."
스마트 캠페인 매니저
# "Send a promo to recent customers"
wati contacts list --page-size 100
wati templates list
wati templates send \
--template-name winter_promo \
--broadcast-name "auto-$(date +%s)" \
--recipients '[...]'
# Track results
wati campaigns overview \
--date-from 2026-02-01T00:00:00Z \
--date-to 2026-03-01T00:00:00Z
인터랙티브 대화
# Send buttons for quick replies
wati conversations send-interactive \
--target +55... \
--type buttons \
--data '{
"body":"How can I help?",
"buttons":[
{"text":"Track Order"},
{"text":"Returns"},
{"text":"Talk to Human"}
]
}'
사용 가능한 웹훅 이벤트
| Event | When it fires |
|---|---|
message | 들어오는 모든 메시지 |
newContactMessageReceived | 새로운 연락처의 메시지 |
sessionMessageSent | 세션 메시지 전송 |
templateMessageSent | 템플릿 메시지 전송 |
sentMessageDELIVERED | 메시지가 전화기로 전달됨 |
sentMessageREAD | 수신자가 메시지를 읽음 |
sentMessageREPLIED | 수신자가 회신함 |
whatsAppPaymentCaptured | 결제 수신 |
ctaUrlClicked | CTA 링크 클릭 |
이러한 이벤트들을 조합하여 정교한 에이전트 동작을 구축하세요 — 읽지 않은 메시지를 추적하고, 캠페인 참여도를 모니터링하며, 결제 시 흐름을 트리거합니다.
왜 CLI인가?
왜냐하면 SaaS의 미래는 대시보드가 아니라 AI 에이전트가 소비하는 인프라이기 때문입니다.
전통적인 챗봇 플랫폼은 드래그‑앤‑드롭 흐름 빌더를 제공합니다. 이는 인간이 봇을 만들 때는 의미가 있었습니다. 하지만 이제 AI 에이전트가 워크플로를 만들고 실행합니다. 그들은 GUI가 필요하지 않습니다. 그들이 필요로 하는 것은:
- 구조화된 데이터
- 결정론적인 명령
- 의미 있는 종료 코드
이것이 wati-cli가 제공하는 내용입니다:
wati contacts get +852... # → { "name": "John", "tags": ["premium"] }
wati conversations messages # → [{ "text": "Where's my order?", ... }]
wati conversations send-text # → { "result": true }
wati webhooks list # → [{ "url": "...", "events": [...] }]
깨끗한 입력. 깨끗한 출력. 파이썬, Node.js, n8n, LangChain, CrewAI 혹은 여러분이 에이전트를 구축하는 어떤 환경과도 조합 가능합니다.
시작하기
npm install -g @wati-io/wati-cli
wati configure init
wati webhooks subscribe --url https://your-server.com/hook --events message
아무것도 없는 상태에서 프로그래밍 방식으로 WhatsApp 메시지를 받을 수 있게 해 주는 세 가지 명령입니다.
전체 문서 및 소스:
멋진 무언가를 만들었나요? 여러분의 작품을 보고 싶어요.
@wati-io/wati-cli v0.2.0 — 이제 전체 웹훅 지원 포함