Design a N8N Work Flow Here is a general outline of an N8n workflow that handles…
- User
Design a N8N Work Flow Here is a general outline of an N8n workflow that handles WhatsApp messages with a specific focus on forwarding images with captions to a Telegram bot, while responding with an error for other message types.
-
Trigger Node: WhatsApp Business Cloud The workflow begins with a WhatsApp Business Cloud Trigger node. This node is set to "On Message Received," which will activate the workflow whenever a new message arrives at your WhatsApp Business account. This node captures all the information sent, including the sender's phone number, the message content, and any attached media.
-
Conditional Logic: IF Node After receiving a message, a crucial step is to determine its type. The IF node is perfect for this. In this node, you'll set up two conditions:
Condition 1: Check for Image and Caption
This condition checks if the message is an image with a caption. You can access the message content via an expression. The expression would look something like {{$json.image.id}} or a similar path, depending on the data structure returned by the WhatsApp node. You'll want to check for the presence of the image.id and also the caption field. If both fields exist, this path is "true," and the workflow proceeds down the "true" branch.
Condition 2: Check for Other Message Types
The "false" branch of the IF node is for all other message types, such as text-only, audio, or images without captions. The condition here would be the inverse of the first one. For example, if the message is not an image with a caption, the workflow goes down this path.
- Handling the "True" Path: Image with Caption If the message is an image with a caption, the workflow proceeds to the following steps:
HTTP Request Node (or similar node for downloading media)
Since WhatsApp only provides a media ID, you'll need to use an HTTP Request node to download the actual image file. The URL for this request will use the media ID provided in the trigger node's output. You must also include your WhatsApp Business API access token in the headers for authentication.
Telegram Node: Send Photo
This node will send the image and its caption to your Telegram bot.
Chat ID: You'll specify the chat ID of the recipient (your bot's chat or a specific channel).
Photo: The photo data will come from the output of the previous HTTP Request node.
Caption: The caption will be the caption from the original WhatsApp message, accessed through an expression like {{$json.caption}}.
- Handling the "False" Path: Other Message Types If the message is not an image with a caption, the workflow will take the "false" path and send an error message via WhatsApp:
WhatsApp Business Cloud Node: Send Message
This node will send a reply back to the user.
-
Assistant