TechBuzzPro

WhatsApp Automation with n8n: Send & Get Replies

· 5 min read · Phones & Tablets

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, you can send messages and wait for responses in WhatsApp using n8n. This is achieved by leveraging the WhatsApp Business API through an n8n integration, allowing you to create automated workflows that interact with WhatsApp contacts.

What You'll Need

  • An n8n account (free or paid depending on usage)
  • A WhatsApp Business API account. This requires applying to Meta and getting approved. This is the most complex part and can take time.
  • A phone number registered with your WhatsApp Business API account.
  • An understanding of basic n8n workflow concepts.

Step-by-Step

  1. Install the WhatsApp Business API Node: In your n8n workflow editor, click the '+' button to add a new node. Search for 'WhatsApp Business API' and install the node.
  2. Configure the WhatsApp Business API Node (Send Message): Click on the WhatsApp Business API node you just added. You'll need to configure it with your API credentials. These are typically found in your WhatsApp Business API dashboard provided by Meta. You'll need to input your:
    • API Key: Your unique API key for authentication.
    • Token: Your authentication token.
    • Phone Number ID: The ID of the phone number you want to use for sending messages.
    Under 'Message Options', enter the recipient's phone number (including the country code, e.g., +15551234567) in the 'To' field. Enter the message you want to send in the 'Message' field.
  3. Add a Wait Node: After the WhatsApp Business API (Send Message) node, add a 'Wait' node. This node pauses the workflow execution for a specified duration. The duration should be long enough to allow a response from the recipient, but not excessively long. A good starting point is 30 seconds. You can adjust this based on your testing.
  4. Configure the WhatsApp Business API Node (Receive Message): Add another WhatsApp Business API node. This time, configure it for receiving messages.
    • API Key: (Same as the send node).
    • Token: (Same as the send node).
    • Phone Number ID: (Same as the send node).
    Crucially, in the 'Webhook URL' field, you must set up a webhook. n8n provides a unique webhook URL for each workflow. This URL is where WhatsApp will send incoming messages. Copy the webhook URL from n8n.
  5. Expose the Webhook URL: You need to tell WhatsApp Business API where to send incoming messages. This is done through your WhatsApp Business API provider's dashboard (Meta Business Manager). You will need to add the n8n webhook URL as a 'Message Received' webhook. The exact steps for doing this vary depending on your provider, but generally involve navigating to the 'Webhooks' or 'Messaging Settings' section and adding the URL.
  6. Set up Message Filtering (Optional but Recommended): The 'Receive Message' node will receive *all* incoming messages to your phone number. To only process messages from the person you sent the initial message to, add a 'Function' node *before* the 'Receive Message' node. Inside the function, use Javascript to check if the 'From' field of the incoming message matches the phone number you sent the initial message to. Only pass messages from that number to the 'Receive Message' node. This prevents your workflow from being triggered by unwanted messages.
  7. Process the Received Message: After the 'Receive Message' node (or the Function node if you added it), add nodes to process the incoming message. You can use nodes like 'Set', 'String Manipulation', or 'HTTP Request' to extract information from the message body or perform other actions based on the response.
  8. Test Your Workflow: Send a message to your WhatsApp Business API phone number from another WhatsApp account. Verify that you receive the message in n8n and that your workflow executes as expected. Adjust the 'Wait' duration and message filtering as needed.

Common Mistakes

  • Incorrect API Credentials: Double-check your API Key, Token, and Phone Number ID. Even a small typo will prevent the workflow from working.
  • Webhook URL Configuration: Ensure the webhook URL in n8n is correctly configured in your WhatsApp Business API provider's dashboard. This is the most common source of errors.
  • Insufficient Wait Time: If the wait time is too short, the workflow may try to receive a message before the recipient has had a chance to respond.
  • Missing Message Filtering: Without message filtering, your workflow will be triggered by *all* incoming messages to your phone number, which can lead to unexpected behavior and increased costs.
  • Incorrect Phone Number Format: Always include the country code when specifying the recipient's phone number.

Tips

  • Use Variables: Store the recipient's phone number and the sent message ID in n8n variables. This makes it easier to reference them in subsequent nodes.
  • Error Handling: Implement error handling in your workflow to gracefully handle situations where messages fail to send or receive. Use the 'Try/Catch' node for this.
  • Logging: Add 'Console Log' nodes to your workflow to log important information, such as the sent message ID, the received message body, and any errors that occur.
  • Rate Limiting: Be mindful of WhatsApp Business API rate limits. Avoid sending too many messages in a short period of time.
  • Test Thoroughly: Test your workflow thoroughly with different scenarios and message types before deploying it to production.

Troubleshooting

  • Workflow Not Triggering: Check your webhook URL configuration in your WhatsApp Business API provider's dashboard. Verify that the webhook URL in n8n matches the URL configured in your provider's dashboard exactly.
  • Messages Not Sending: Double-check your API credentials. Ensure that your phone number is properly registered with your WhatsApp Business API account.
  • No Response Received: Increase the 'Wait' duration. Make sure the recipient is online and has WhatsApp enabled.
  • Unexpected Messages Received: Implement message filtering to only process messages from the intended recipient.
  • API Errors: Consult the WhatsApp Business API documentation for specific error codes and their meanings. Examine the n8n workflow execution logs for more detailed error information. Restart n8n. Check your WhatsApp Business API account status with Meta.

Frequently Asked Questions

What is the WhatsApp Business API?

It's a platform that allows businesses to integrate WhatsApp into their workflows, enabling automated messaging and communication with customers.

How do I get approved for the WhatsApp Business API?

You need to apply through Meta Business Manager and meet their criteria, which includes having a legitimate business and a clear use case for WhatsApp messaging.

Can I use WhatsApp Business App with n8n?

No, n8n uses the WhatsApp Business API, not the regular WhatsApp Business app. They are different platforms.

Is there a cost associated with using the WhatsApp Business API?

Yes, Meta charges for message delivery based on conversation types. Pricing varies by country.

How do I handle multiple conversations?

You'll need to manage conversation IDs and use them to identify and track individual conversations within your workflow.