WhatsApp connect question

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?



1 Like

Hi Michael! :wave:

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:

  1. Double-check the data path:
    Open the AI Agent node’s output and make sure chat_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 like 1234567890.
  2. Add a debug node (optional):
    Before the Send WhatsApp Reply, add a Set node temporarily to print {{ $json.chat_id }} and see what it returns.
  3. 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 :muscle::sparkles:

1 Like

Thank you, Erick_Torres🙏 I will continue to work hard. I hope I can realize the workflow I want.。

1 Like

Test the answer if it is correct, mark it as an answer, this helps us as a community

1 Like

Chat_id: 85261387889 No characters added “+”,Failed to pass yet。

Send me a screenshot of the webhook output.

1 Like

You can send workflow too so we can see,

n8n attach workflow

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

1 Like




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, // :white_check_mark: 正確寫法,將 “+” 接到電話號碼前面
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, // :white_check_mark: 正確寫法,將 “+” 接到電話號碼前面
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 ‘’

1 Like