I want to connect the AI Agent to Whatsapp and then reply to the customer with the AI Agent, but there is an ERROR. What should I do?
Hi Michael!
You’re very close! The issue is coming from this part of your HTTP Request node for WhatsApp:
"to": "whatsapp:{{ $json.chat_id }}"
The error says:
“Bad request – please check your parameters. A ‘To’ phone number is required.”
That means chat_id
is missing or not correctly passed from the AI Agent output. Here’s how you can fix it:
Steps to Resolve:
- Double-check the data path:
Open the AI Agent node’s output and make surechat_id
exists and is accessible at$json.chat_id
.
You can click the “AI Agent” node, go to the “output” tab, and check if the phone number is there and correctly formatted like1234567890
. - Add a debug node (optional):
Before theSend WhatsApp Reply
, add aSet
node temporarily to print{{ $json.chat_id }}
and see what it returns. - Ensure the correct format:
Twilio requires this format:
"to": "whatsapp:+1234567890"
So in your body, it should be:
"to": "whatsapp:+{{ $json.chat_id }}"
Make sure the +
and country code are included.
Let me know if you want me to help you inspect the exact JSON output or adjust the field dynamically. Happy to help you get this working
Thank you, Erick_Torres🙏 I will continue to work hard. I hope I can realize the workflow I want.。
Test the answer if it is correct, mark it as an answer, this helps us as a community
Send me a screenshot of the webhook output.
You can send workflow too so we can see,
btw, you may need to specify to the ai agent what the output you want also, to keep it consist for the send whatapp node, this will help the last node, and you can maybe even add output parser to json
Code:
const raw = $json.body;
try {
const message = raw?.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
if (!message || !message.from || !message.text?.body) {
throw new Error(“無法正確提取訊息結構內容”);
}
return [
{
json: {
chat_id: “+” + message.from, // 正確寫法,將 “+” 接到電話號碼前面
userMessage: message.text.body
}
}
];
} catch (err) {
throw new Error(“解析 WhatsApp webhook 內容失敗:” + err.message);
}
Send WhatsApp Reply Body:
const raw = $json.body;
try {
const message = raw?.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
if (!message || !message.from || !message.text?.body) {
throw new Error(“無法正確提取訊息結構內容”);
}
return [
{
json: {
chat_id: “+85261387889” + message.from, // 正確寫法,將 “+” 接到電話號碼前面
userMessage: message.text.body
}
}
];
} catch (err) {
throw new Error(“解析 WhatsApp webhook 內容失敗:” + err.message);
}
u still need ure ai agent to parse the output so the last node knows what to expect, ie the ‘’‘to’ phone number ‘’