5 minute read
Add Readable Google Sheet
1 . Log in to your Glific account.
2 . Click on
Flows from the left panel
3 . From the bottom of the
Flow page. Click on
Google Sheet link.
4 . Click on
Add Sheet button
5 . Add the
Sheet URL and
Name of the sheet which you want to integrate. Check the
Read checkbox and Click on the
Save button. See 6 below for how to get the URL
- Open the Google sheet and click on share button on the right hand side to update the sheet permission to at least
Anyone with the linkcan
6 . Copy the URL
- Paste the copied URL in the Google Sheet Integration screen in Glific and click on
- You can click on the link button to open the added sheet
It is important to note that the first cell in the Sheet should be named as 'Key' for the Read function to work.
Configuring Readable Google Sheet in the Flow
9 . Create a new flow and open it for editing
link Google sheetnode
Link google Sheet
In the second drop-down select the sheet
In Select row add
@calendar.current_dateor any variable that uniquely defines the
Keycolumn of Google sheet
OK and use the column name like below and access the value of cell values.
Send template messages using Google Sheets
Template messages could be sent using Google Sheets using
Read Google Sheets. This is generally useful when different template messages need to be scheduled & sent regularly to the beneficiaries.
Let us dive in a bit deeper by looking at the steps involved :
Create the template messages that you'd like to send via Google Sheets using the normal method. Refer Creating Template Messages
Once the template is created, make note of the UUID of the template messages you need to share using Google Sheets. Refer the screenshot below :
Create a Google Sheet with two headers,
template_uuidas shown below. Usually the
keycolumn will be having dates on which the individual templates need to be sent.
Now let us setup the flow. The flow starts with a
Link Google Sheetsnode which has the Google Sheets we created linked. This is how the node looks like :
As you can see, the row input field is given an expression
@calendar.current_date which tries to match the current date value with a
Key value. If a match is found, then that row is chosen.
- In the next step,
Send contact a messageis used and an expression is given in place of the template selection drop-down. The expression reads
<%= Glific.Clients.ColoredCow.send_template("@results.sheet.template_uuid", ["@contact.name"]) %>
In this expression, the
template_uuid matching the row in the given date gets send to the user. The expression also passes the value of the contact's name. You can pass multiple variables in this expression, if the template message demands it, using comma separation.
In this way, you can use Google Sheets for sending template messages. With the use of Triggers you'll be able to schedule different template messages for specific dates using Google Sheets, enabling you to do it in a single flow, instead of creating separate flows for separate templates. This is particularly useful, when you plan to share a set of instructions/ advisory/ content in a scheduled manner in specific dates & let's you use dynamic content for the same.
Send Interactive Messages using Google Sheets
Glific enables you to send interactive messages using Google Sheets. This is particularly helpful when you need the options within the interactive messages to be dynamic. This lets you use the same interactive message for creating multiple dynamic list of options to choose from for the beneficiary.
Let's dive in a bit deeper to see how it works.
Create a Google Sheet with the list of options you wish to have in the interactive message in a row as shown below. In this example, we want the values given in row 2 i.e
keyvalue as 1 to be used as the options in the interactive message we're going to create. These values could be updated in real-time to change the options inside the interactive message or you can add more rows to have different interactive messages too.
Add the above created Google Sheet on the Glific. Please find the steps to do that here
Now create a sample
Interactive Messagewith a list message (can do similarly for button options too). Only the first option needs to be entered as shown below with some sample data, as it will be rewrited by the values on the sheet- hence the rest of the options could be left empty. The idea is to fetch values for the options list dynamically from the sheet.
Now since we have the Google Sheets linked & the interactive message created, let's create a sapmple flow to understand how it works :
As you can see, the flow starts with a Link Google Sheets node, where the readable google sheets from which the options to be fetched inside the interactive message is added. This is how the Google Sheets node is configured :
- In the node above, the sheet we created have been linked & the corresponding action is marked as
Readsince the options for
Interactive Messageare being read from the Google Sheets.
- Here 1 is added in
Select rowfield, as the values for the interactive message are present on the row with the key value as 1 and it is stored under the variable name
- Instead of 1, you can also use dynamic values like flow variables or contact variables, functions like @calendar.current_date etc.
- The next node consists of
Send contact an interactive messagenode and this is how it is configured
- The interactive message we've created is chosen from the dropdown.
- The dynamic fields checkbox is selected which enables us to use dynamic values inside the interactive message.
- In the input field box with
number of variables, the number of options in the interactive message needs to be entered. Here we've given 8, since we need 8 options in the list sent (as also shown on google sheets).
variablevalues need to be filled. The id could be any unique value for referencing & variable value is being fetched from the linked Google Sheet.
- The variable names are filled as
@results.sheet.course2and so on representing each row value from the row we've chosen to read from.
- Now since the flow is configured, let's test the flow
As you can see on the preview above, the list of options we had given in the Google Sheets are shown as a list of options inside the Interactive Message.
- Sending interactive messages using Google Sheets could avoid the redundancy of creating multiple interactive messages when the list of options needs to be updated (some option needs to be added or removed) or multiple interactive messages to be used.
- It can also be used for handling situations where the list of options is more than 10 by using 'More' as the tenth option and having a separate list of options in the next row.
Add Writable Google Sheet
Enable Google Sheet APIs and Add Credentials
Use this wizard to create or select a project in the Google Developers Console. This will automatically turn on the API. Click Continue, then Go to credentials.
Add credentials to your projectpage, create a Service account key.
Select your project name as the service account and choose JSON as the key format. Download the generated JSON file containing the credentials.
Go to your Glific account, navigate to Settings, and select Google Sheet.
Paste the service account credentials in the provided field, and click on the Save button.
Link Writable Google Sheet in Glific
- Go to the Google Sheet screen as mentioned in the above steps.
- Click on the Add Sheet button.
- Add the Sheet URL and Name of the sheet you want to integrate. Check the
Writecheckbox and click on the Save button. Refer to Step 8 below for instructions on how to get the URL.
- Open the Google Sheet you want to write data on and click on the share button on the right-hand side. Update the sheet permissions and add the Service Account Identifier (The client email on the service account) as a user invited in the spreadsheet's Collaboration Settings with
- Copy the URL.
Paste the copied URL in the Google Sheet Integration screen in Glific and click on the
You can click on the link button to open the added sheet.
Configuring Writable Google Sheet in the Flow
- Import the below sample flow from the Flow screen and click on
settingicon to configure it.
- Here's how the imported flow would look like
- The first node is the
Send Messagenode, which asks the contact for input to be added to the sheet.
- The second node is the
Wait for Responsenode with the result name sheet_input. The response from the contact will be saved in this result and can be referenced as @results.sheet_input.
- The third node is the
Link Google sheetnode, used to add the user-entered text into the Google sheet. Click on this node to configure it.
- Under Action, select Write from the dropdown menu.
- Select the sheet from the dropdown that was added in Step 7 above i.e. Sample Sheet
- Specify the Sheet range from which you would like to enter the data in the Google sheet. For example, Sheet1!A10:D will add data from row 10 of column A in subsheet Sheet1 up to column D. This means that four data values will be added in 20.
- Enter the data to be written in the Google sheet under Input data to update in sheet. You can use values like @results.sheet_input, @contact.name, @contact.fields.age, etc.
After configuring the flow, click on the Preview button located on the bottom right side of the screen to run the flow in the simulator.
In the simulator, you will see the first message from the
Send Messagenode, which prompts you to enter text.
Type the desired text that you want to see in the sheet, and then press Enter.
This will move the flow forward, and the data will be written to the Google Sheet.
Open the Google Sheet to check the newly inserted data.
- This functionality can be used to write upto 30 columns in google sheets
- To handle blank cells in between the Google Sheet use Split by Expression