Example 1: AI auto-reply

This example demonstrates how to implement a basic automated reply workflow using n8n, a large language model and a YCloud node: When the YCloud platform receives an inbound message, it triggers an n8n workflow via a webhook. The workflow calls upon the large language model to generate a reply, and then sends the message back to the user via the YCloud node.

YCloud Chatbot has built a comprehensive AI workflow for you, offering an end-to-end, easy-to-understand AI knowledge base, corpora and automated processes. Click here for more details.

Overall Process

Webhook Event

  1. Create a Webhook endpoint

    1. Use the n8n Webhook Node to create a new listener

    2. Select POST as the HTTP method

    3. In the Options, set the Response Code to 200 and ensure that โ€˜Immediatelyโ€™ is selected

Add your endpoint details to the YCloud platform and select the Webhook events you wish to monitor

Parse the return value and verify the signature

Parse the return value

Parsing the headers in the webhook response using N8Nโ€™s built-in โ€˜codeโ€™ node

Select JavaScript for parsing

The return values of this node are:

  • The original value,

  • The timestamp,

  • The received signature, the payload, the signed payload, and the signature information in the request header

Encrypted data

In the previous step, the data was fully partitioned. In this node, we will use SignedPayload and Secret. We will use the Crypto node to encrypt the data.

Ge Secret from YCloud platform.

Compare signatures

Use an if statement to verify the signature information; if it matches, the verification is considered successful.

Reply to messages using AI

Once you have subscribed to the whatsapp_inbound_message and whatsapp_messages_updated events, you will receive a push notification when a message is received, or a follow-up status update after a message has been sent.

  1. Use the switch node to configure multiple webhook notification types.

  1. When an inbound_message_received event is received, a reply can be generated by calling the AI API

  1. Use the merge node to retain the collection of webhook push data from the preceding section

  1. Sending messages using YCloud nodes

Fill in the relevant details, place the AI-generated text in the Body field, and send.

circle-exclamation

With that, the complete n8n workflowโ€”Webhook โ†’ Large Language Model โ†’ Automated Replyโ€”is now configured.

Save to a data table (optional)

Monitor subsequent updates to the message sent (optional)

Once step 5 is complete, the data will be pushed via the whatsapp.message.update event.

Upon receiving this push, you can use the datatable - update rows node to update the data table, thereby tracking the entire message delivery process.

Last updated

Was this helpful?