Integration with n8n

Integration with n8n

Need to send WhatsApp messages to your customers receiving a webhook? This article will explain how to use the setup n8n workflow.  

Prior to getting started, you will need to have the following:

  • Login Access to n8n

Step 1: Download WAContact workflow

Login to WAContact, then navigate to the Integration page from the top menu. Click on the Download Workflows button in the n8n card.

 

Click on one of the buttons to download the workflow file.

 

 

Step 2: Account ID, Secret Key and Channel ID

 

In WAContact, click on your name at the top right corner of the page. Choose Profile.

 

 

Scroll down to see your Account ID and Secret Key. You will need this info later.

 

Then click on Channels from the top menu.

 

 

Step 3: Setup Workflow

 

3.1 Add a workflow

 

Login to n8n and go to Workflows. Click on the Add Workflow button

 

 

.

 

3.2 Import Workflow

Click on the three vertical dots button on the top right corner of the page. Select Import from file.


Then select the file that you have downloaded at step 1

 

 

 

3.3 Configure Code

 

Double-click on the Code node.

 

 

3.3.1 Configure Account ID, Secret and Channel ID

 

Let’s go to line 13.

 

 

Change the value to your Account ID, Secret and Channel ID. (Refer to step 2)

 

For example, if your Account ID is 3766a5b4-c4fe-4347-841e-27fae5477291, then after the value is changed, it  will look like this:

 

 

 

Important: Make sure the values of accountId and secret are enclosed in single quotes ( ' ) as shown in the picture. 

 

Important: Channel ID is only needed to send messages. There is no channelId variable in the Add Contact workflow.  

 

3.3.2 Set phone and name

 

Now we want to get the phone and name info from the webhook data. We will talk about how we can see the data in more detail in section 4.  

First, we will need the webhook data in application/json format. For example:

{"id": 1, "name": "Andy", "phone": "+6591234567"}  

If the server sends data that is in another format, please check if it can send the data in application/json format.  

Starting from line 17, you can set the value for phone, name and other info. You can get the value from the variable data, which has the value of the data sent from the server.  

For example, if we use the example data above, we can set the phone and name as follows:  

 

const phone = data.phone;

const name = data.name;  

 

Another webhook data example:

 

  {       "id": 1,         

             "customer": {                  

                          "name": "Andy",                

                          "phone": "+6591234567"        

             },      

              "product": {                  

                           "name": "A good product"          

             }

 }

 

We can set the phone and name as follows:  

const phone = data.customer.phone;

const name = data.customer.name;

const data1 = data.product.name;  

 

After you have done setting the data, click on the Back to canvas button on the top left of the page.  

 

3.3.3 Set Message Content (applicable to Send Text & Send Media workflow)

 

Click on the HTTP Request node

 

 

Scroll down to message in the Parameters tab

 

 

 

You can set the message in the Value textbox as above. If you need any data from the Code node, you can use {{ $json.data. }}.   

For example if you want to add the value of the variable name in the message, you can use {{ $json.data.name }}.   

Another example, if you want to add the value of the variable data1, you can use {{ $json.data.data1 }}.  

After you have done setting the message content, click on the Back to canvas button on the top left of the page.  

 

Step 4: Test Workflow

  Double-click on the Webhook node.

 

 

Click on the Test URL and set your server to send webhooks to this URL.

 

 

Click Listen for the Test Event button on the left.

 

 

Send a Webhook from the server. If successful, you will see the output on the right pan

 

 

Click on the JSON tab above.

 

 

You can see the data in the body field:

 

 

If you go back to canvas, you will see that the Webhook is checked.

 

 

Now let’s test the Code node.

 

 

 

Click on the Execute node button.  

 

You will be able to see the output on the right.  

 

If you go back to canvas, you can see that the Code node is also checked.

 

 

Next we test the HTTP Request node.

 

 

 

Click on the Execute node button. If successful, WAContact will perform the action requested.

If the Send Text workflow is being used, then a text message will be sent.  

 

Step 5: Activate Workflow

  Double-click on the Webhook node.

 

 

 

 

Click on the Production URL, and copy the URL. Set your server to send webhooks to this URL instead.  

 

After that, press the Back to canvas button on the top left corner of the page.

 

Now you can activate the workflow by pressing the toggle button on the top right corner of the page.

 

 

Congratulations! Your workflow is now active.  

 

If you have any questions about this, please contact our support team. Login to WAContact. We have a chat button at the bottom right of the page.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 4240