If you are looking for how to send quick replies on WhatsApp dynamically using WhatsApp by Gupshup.
What you'll need:
Skill level: Intermediate
Time required: 5 minutes
- Sandbox or live account in WhatsApp by Gupshup
- A WhatsApp by Gupshup app running in your WhatsApp account
- Google Sheets to store quick reply buttons
Usecase
Send a list of the top three richest men of India on WhatsApp to a user as a quick reply. Associated information with an image must be received when a user clicks on any of the quick reply buttons.
Limitation
If you connect a WhatsApp by Gupshup sandbox app with Quickwork and wish to use Send media action, a sample image supported by Gupshup is sent on WhatsApp. To send personalized images as a message, ensure to connect WhatsApp by Gupshup production/live app.
Sample image URL that the sandbox account supports: https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg
To explain better, we will connect a production/live app of WhatApp by Gupshup named kayoapp1 with a journey in Quickwork:
Prerequisites
Create a Google Sheet named Quick Reply Buttons to store the name of the buttons and configure them dynamically in a journey:
Note: If you are using sandbox account of WhatsApp by Gupshup, you can configure and send upto 3 quick reply buttons.
Configuring the first journey
The first journey sends the quick reply buttons as a message on WhatsApp tapping which the user gets the desired result.
Configuring the trigger
- In the Event section, choose the WhatsApp by Gupshup app from the drop-down menu in the Apps field present right below the New Trigger button.
- Select the trigger event as New text message from the drop-down menu in the Triggers field.
- Click the Link account button. Specify the API key and Source number of the kayoapp1 app. Click here to know how to connect a Gupshup app with Quickwork.
- A webhook URL gets generated. Copy it, go back to kayoapp1 in your Gupshup account, and scroll down to Callback URL/Link your Bot. Paste the URL, toggle ON the button, and click Set:
- Type a text in the Message field and select No in the Send welcome message field:
Configuring the Google Sheet action
Let us configure this action to select all the three quick reply buttons stored in the Google Sheet and loop over them to make them appear on WhatsApp as a response to a user:
- In the Steps section, click on the Simple Action button and choose the Google Sheets app from the drop-down menu in the Apps list.
- In the Actions list, select Search cell using query action.
- Click the Link account button to connect the Google account in which you have created the Quick Reply Buttons sheet.
- In the Spreadsheet field, select the Quick Reply Buttons sheet.
- Specify Select * in the Query String field. This query helps displaying all the quick reply buttons on WhatsApp.
- Specify
{"Name":"abc"}
in the Sample Response field. - Select Sheet 1 from the Sheet drop-down menu:
Configuring the WhatsApp by Gupshup action
- In the Steps section, click on the Simple Action button and choose the WhatsApp by Gupshup app from the drop-down menu in the Apps list.
- In the Actions list, select Send interactive quick reply action.
- The connection is established automatically with kayoapp1.
- In the Phone number field, drag and drop the
Sender Id
data pill from WhatsApp by Gupshup | New text message Trigger under Data Tree Output. - In the Body type field, select Text.
- In the Message ID field, drag and drop the
Message Id
data pill from WhatsApp by Gupshup | New text message Trigger under Data Tree Output: - In the Text field, specify the message you want to send as a heading for quick replies. E.g., Here is the list of top 3 richest man of India:
- Now move to the Options object. Here, we will dynamically call the quick reply buttons instead of configuring them manually. To do so, swich to the Dynamic mode.
- In the Source field, drag and drop the
[]Rows
data pill from Google Sheets | Search cell using query action under Data Tree Output.
Note: Input in the the Source field must be an array, which is[]Rows
in this case. The array must contain inputs in it to call and loop over. - In the Type field under the Item 1 block, select Text.
- In the Title input field, drag and drop the
Name
data pill from Google Sheets | Search cell using query action under Data Tree Output: - In this way, we have successfully configured our first journey with 3 quick reply buttons. Save the changes and click the Save & Start button:
Configuring the second journey
The second journey contains logic for each quick reply button. Whenever any quick reply button is tapped, the journey checks for the button name and then sends the appropriate result on WhatsApp.
Configuring the trigger
- In the Event section, choose the WhatsApp by Gupshup app from the drop-down menu in the Apps field present right below the New Trigger button.
- Select the trigger event as Interactive quickreply click from the drop-down menu in the Triggers field.
- Connect the same kayoapp1 in this journey.
Using If Condition for validation of quick replies clicked
Since there are three quick reply buttons, let's use If Condition and configure the logic to be executed for each button, respectively. The If Condition validates the quick reply button clicked by the user and sends appropriate information to the user accordingly.
Configuring the If Condition and an action for the first quick reply button
- In the Steps section, click on the Business Logic button and choose the If Condition block.
- The If block will appear with their respective indented simple action. Click the If block. In the Left Value field, drag and drop the Title data pill present in the Payload object under the WhatsApp by Gupshup | Interactive quickreply click Trigger data tree.
- Select Equals in the Condition field.
- Enter the button name, i.e., Mukesh Ambani in the Right Value field:
Note: Ensure to keep the exact name of the quick reply button in the Right Value field, else the If block won't be able to compare and process the configured actions down the line. - Now, click the Please choose an action bar below the If block. Choose WhatsApp by Gupshup in the App drop-down menu.
- Select Send media as an action. The connection gets established automatically with kayoapp1.
- In the Phone number field, pass the Sender Id data pill from the WhatsApp by Gupshup | Template Quickreply click Trigger data tree.
- In the URL field, enter the image URL you want to send. E.g.,
https://bsmedia.business-standard.com/_media/bs/img/article/2021-07/24/full/1627066748-4739.jpg
. - In the Message field, enter the description to be sent with the image upon clicking the quick reply button:
Configuring the If Condition and an action for the second quick reply button
- Now let's move towards configuring If Condition and simple action for the second quick reply button.
- Click the Clone Step icon of the first If Condition block. The replica of the first If Condition with WhatsApp by Gupshup app gets created.
- Click the If Condition and change the value of the Right Value field to Gautam Adani:
- Click the Send media action bar.
- In the URL field, change the image URL to
https://cdn.ceoworld.biz/wp-content/uploads/2021/03/Gautam-Adani.jpg
. - In the Message field, enter the description to be sent with the image upon clicking the quick reply button:
Configuring the If Condition and an action for the second quick reply button
- Now let's move towards configuring If Condition and simple action for the third quick reply button.
- Click the Clone Step icon of the second If Condition block. The replica of the second If Condition with WhatsApp by Gupshup app gets created.
- Click the If Condition and change the value of the Right Value field to Shiv Nadar:
- Click the Send media action bar.
- In the URL field, change the image URL to
https://images.livemint.com/img/2021/07/19/1600x900/shiv-nadar-kqJG--621x414@LiveMint_1626703494503.jpg
. - In the Message field, enter the description to be sent with the image upon clicking the quick reply button:
- Now save the changes and click the Save & Start button. The fully configured second journey looks like this:
Activating the app on WhatsApp
Go to your WhatsApp by Gupshup account, click the kayoapp1, and scroll down to the Smart mechanisms to get active and opted in users section. Go to the Click URL option and copy the URL. Paste it in the new tab to open it:
Paste it in the new tab to open it. The web version of WhatsApp will open with the predefined command PROXY kayoapp1 in the text field. Click the CONTINUE TO CHAT button:
If you are haven't linked the web version of WhatsApp, you'll be asked to do so.
Executing the journey
Send the command PROXY kayoapp1 to the WhatsApp by Gupshup chat account. You'll receive the welcome message confirming that the app is now connected successfully. Your app is activated and both the journeys are in the execution state. Send Hi:
Now click any one of the quick replies. You'll receive the associate information with an image as shown in the following figure:
Comments
0 comments
Please sign in to leave a comment.