Unit introduction
Welcome to the final unit of course four “An introduction to aggregators”.
In this unit you will explore the Text Aggregator and build your final use case of Make Basics.
You will also be introduced to the Tools → Set variable module.
Great job so far - let’s get started!
Aggregating text example
You have already seen what the numeric aggregator can be used for - aggregating and manipulating numerical data. Now you’re going to look at the text aggregator.
The text aggregator is useful for composing strings of messages from one or multiple sources, and/or multiple bundles. Let’s look at an example!
This is sample data stored in a Google Sheets, containing several fields for a repair service.
It contains the customer name, the service they had, car registration, date of service, cost, and their phone number.
For the sake of this use case, we want to send the list of services performed in one single message.
However when we read the Google Sheets it returns multiple bundles.
So, how could we aggregate the service column into one single text? The solution is the text aggregator.
Here’s an example of the data:
| Name | Service | Car registration | Date of job | Cost | Phone number |
|---|---|---|---|---|---|
| Paul | Battery change | MA1 1AB | 12-04-22 | 60 | 123456 |
| Sophie | Car wash | MA2 2CD | 13-04-22 | 5 | 789101 |
The text aggregator is used to map the services fields into a single bundle, along with the name and cost.
The reduction stage will aggregate this into a single bundle of information.
This bundle can then be used to send a message to any messaging service, such as Slack, Telegram, SMS etc.
From the Tools module’s operation, we can see the input and output:
INPUT
- Bundle 1:
- Text:
Paul / Battery change / $60
- Text:
- Bundle 2:
- Text:
Sophie / Car wash / $5
- Text:
OUTPUT
- Bundle 1:
- Text:
Paul / Battery change / $60 Sophie / Car wash / $5
- Text:
Upcoming use case
Let’s build on that basic use case and review the upcoming scenario that you will build over the next few pages. The aim of this scenario is to create a message with the help of text aggregator and functions.
Weather
This scenario will follow the same concept as the previous unit - your module will generate a bundle of data that contains the weather for 7 days. This will use the Weather app, and the Get daily forecast module.
The module is configured to select specific days for the forecast and a location. For example, days like “Today”, “Tomorrow”, “The day after tomorrow”, “3. days from today”, and “4. days from today” are selected, and the city is set to Madrid, ES.
Tools (Text Aggregator)
The text aggregator will process each bundle and aggregate it in the format that you specify. It then processes the next bundle based on what is defined in the Row separator field. As the aim of this module is to present a list of the weather by date on separate rows, New row has been selected.
The Source Module for the aggregator is Weather - Get daily weather forecast. The Row separator is set to New row. The Text field uses a formula to format the date and status: formatDate( 15.date ; DD MMM ) - Status.
This will produce an output similar to:
text: 17 Apr - Clouds 18 Apr - Rain 19 Apr - Rain 20 Apr - Rain 21 Apr - Rain 22 Apr - Rain 23 Apr - Rain
Tools (Set Variable)
The Set variable module will store the bundle that was produced in the text aggregator, and allow you to name the variable so that it can be used repeatedly. Additionally you are able to add additional fields to the variable, such as text, e.g. --Weekly Temperatures--.
The module is configured with a Variable name of message and a Variable lifetime of One cycle. The Variable value combines the text --Weekly Temperatures-- with the aggregated text output from the previous module.
This will output the end result as:
—Weekly Temperatures— [Aggregated text bundles for 7 days]
Let’s get started by building this!
Activity - Building the scenario
Work through the following stages to build the text aggregator scenario.
First, add the Weather → Get daily weather forecast module. Under Days, select from Today, Tomorrow, all the way up to 6 days from today. Under City, type your location, for example, Madrid, ES. Click OK and then click Run once. As this returns 7 days worth of information, it will generate 7 separate bundles.
Next, add a new module. Type Tools, select this option, and then select the Text Aggregator. When the text aggregator loads, it will show the source module as Weather → Get daily weather forecast. Select Show advanced settings to reveal more options for the aggregator.
Under Row separator, select New row.
The row separator determines how your bundles will be separated in the aggregated text. For example, if you have 3 bundles which map the names Benjamin / Liza / Tomas and use row separator, they will appear as: Benjamin Liza Tomas
Selecting Other allows you to determine what character to use to separate each bundle. For example: Benjamin,Liza,Tomas Benjamin-Liza-Tomas Benjamin/Liza/Tomas
Click OK. The next part of this exercise focuses on populating the text field. When you click OK, you will notice the text aggregator Wrap the connection to the weather module. This visually indicates that fields are being aggregated from this module, which is useful when building larger scenarios that may use multiple aggregators.
Activity - Adding your functions
The next step is to populate the text field of the text aggregator. You will need to follow each stage of this exercise.
Displaying the Date
The intended result of this function is to display the date at the start of the output message.
Insert the formatDate function, and map the Date from the Weather app. After the ;, type DD MMM – this is a new formatDate() function. It will display the date in the following format: 13 Apr.
If you choose to, you can use the DD-MM format, but this would display as 13-04.
The function should look like this: formatDate( Date ; DD MMM )
Displaying Minimum Temperature
The intended result of this function is to display the minimum temperature to 2 decimal points.
After the previous formatDate(Date;DD MMM), type - Min:, and then insert the formatNumber() function, map Temperature:Minimum.
After the first ;, type 2.
After the second ;, type ..
It should look like this: - Min: formatNumber( 1.temperature.min ; 2 ; . )
Displaying Maximum Temperature
This function will do the same as the previous, but this time display the maximum temperature to 2 decimal points.
After your previous function, type Max:.
Insert the second formatNumber() function and map Temperature:Maximum.
After the first ;, type 2.
After the second ;, type ..
It should look like this: Max: formatNumber( 1.temperature.max ; 2 ; . )
Displaying Average Temperature
Note: Within functions, you can insert other functions.
First, type Avg:. Then insert formatNumber(), and within this function, map average().
Within average(), map Temperature:min. Add a ; and then map Temperature:max.
After Temperature:max), type 2, and after ;, type ..
The function should look like this: Avg: formatNumber( average( 1.temperature.min ; 1.temperature.max ) ; 2 ; . )
These functions combined will first calculate the average temperature of Temperature:min/Temperature:max. Secondly, it will format the average number to 2 decimal points.
Activity – Wrapping
Click OK – you will notice the text aggregator wrap the connection to the weather module. This is to visually indicate that fields are being aggregated from this module. This is useful for when you are building larger scenarios and may use multiple aggregators.
Setting up the Weather Module
Add the Weather - Get daily weather forecast module.
Under Days, select from Today, Tomorrow, all the way up to 6 days from today.
Under City, type your location. E.g. London, UK.
Click OK and then click Run once.
As it is returning 7 days worth of information, this will create 7 separate bundles of forecast.
Setting up the Text Aggregator
Add a new module – you can type tools or aggregator in your Search. Select the Text aggregator.
When the text aggregator loads it will show the source module as Weather - Get daily weather forecast.
Select ‘Show advanced settings’ – this will give you more options to work with for the aggregator.
Under Row separator, select New row. The row separator determines how your bundles will be separated in the aggregated text. For example, if you have 3 bundles which map the names Benjamin / Liza / Tomas and use row separator, they will appear as:
Benjamin
Liza
Tomas
Selecting Other allows you to determine what character to use to separate each bundle. For example:
Benjamin,Liza,Tomas
Benjamin/Liza/Tomas
Benjamin|Liza|Tomas
When you click OK after configuring the aggregator, you will notice the text aggregator wrap the connection to the weather module, visually indicating that fields are being aggregated.
Activity - Viewing the output bundle
Click Run once – you will receive a prompt which states A transformer should not be the last module in the route. This is because Tools cannot be the last module in a scenario.
This prompt appears because nothing is happening with the transformed data. As part of this exercise is about viewing data, click Run anyway. This will execute your scenario.
If you receive any error prompts, please revisit the previous page to ensure your functions are correctly mapped.
Activity - Viewing the output bundle
Click the 1 on your output bundle.
If the functions in the aggregator module match the example below, the output bundle structure will match the image:
formatDate( Date ; DD MMM ) - Min: formatNumber( Temperature: Minimum ; 2 ; . ) Max: formatNumber( Temperature: Maximum ; 2 ; . ) Avg: formatNumber( average( Temperature: Minimum ; Temperature: Maximum ) ; 2 ; . )
The output bundle structure will show: 7 days worth of dates and temperatures, all on different rows.
Click any of the Bundles under Input - this shows the mapped information which was mapped through the text aggregator.
There’s one final step to add here.
Activity – Setting a variable
Work through the final stages of this use case.
You have your created bundle, and it’s in a readable format. The final step is to set a variable. A variable is a reusable element that will store a value, which can be customized and mapped within your scenario.
Let’s look at an example of how a variable works. If you type your name (or a name) in the text box, you will see it reflected on the next step. This is because a variable called name is used to store what you typed. This hopefully gives some context around variables. If you’re interested in learning more about variables, you can access the help center.
When you’re ready, move to the next step and we’ll add the final module to this use case.
Add a new module and type Tools, then select the Set variable module. For Variable name, type Message. Under Variable value, type ~Weekly temperatures~ and then map your aggregated text on a new line. The aim here is to create a single bundle that can be mapped.
Click Run once. Your scenario will generate the weather for the next 7 days. The aggregator will perform aggregation based on the conditions set in the text aggregator module. The aggregated text is set as a variable named Message, containing the additional ~Weekly temperatures~ text. Your output bundle should share a similar structure to the example, but with different dates: a nicely formatted and aggregated variable.
Well done! You have created a custom piece of text utilizing a text aggregator and a variable. Depending on the messaging service you use, you can now easily map your set variable as a message, and Make will take care of the rest. For example, utilizing Slack would look like the image on the left. For more information on how to create a connection to Slack, see the online Help.
This concludes this scenario and this unit on using the text aggregator. Great work!