In our next blog posts we will show you how you can use Dextcloud components to build business flows. We will walk you through the process of creating a simple but usable application through our Low Code designer.
The designer is an intuitive interface where you select components on the left hand side palette or tree view and the canvas allows you to build applications by creating interactions between components. Each component has contextual menus in the right hand side, here you can provide settings to connect to the component, operations to perform on them using messages from the previous component or input commands.
Lets see how this works in practice with a simple flow application.
The below sample is a rain alert application which demonstrates some of the key concepts.
Each morning, the application will check the current weather for a city of your choice and will send an email with description of the expected weather. When the rain was predicted, you will receive a text message instead that will remind you to take an umbrella with you when you go out.
Here is how it will look once we are done:
Now let’s create a new flow from scratch. Once you click the “New flow” button the following pop-up will appear:
Enter the flow name (and a description if you want) and click the “Create flow” button.
Each application has a structure of a flow that comprises components linked with each other. To build an application, we will have to drag and drop relevant components that, joined together, will implement a business process.
In the Designer, you can select components you want to use in your application from the left-hand side menu. As you probably have noticed, components are organized into groups, e.g. Notifications, Amazon Web Services to let you find components you need easier.
We will be getting the current weather forecast from the openweathermap.org. This site allows to receive the weather forecast by the REST API and, for non-commercial usage, it is free. However, It is required to sign-in to obtain the API key.
To make an HTTP GET request we will use the HTTP component. Drag and drop it on the canvas and connect with API component.
Once you click on the HTTP component, you can edit its properties. Please notice that mandatory parameters are marked in red. First choose a Connection - select “None” because OpenWeather REST API authorization bases on the API key included in URL and it does not require sending any authorization header. As you will notice later, many components will have connections. Connections can be re-used between flows.
Then select the operation “Send GET request” and enter the following URL:
Selecting an operation is required for every component, even if a given component supports only one operation.
Here is how our flow looks at this moment:
Despite it is not yet completed, let’s run the flow - click the button “Save” in the upper right corner to save the flow. Then click the button “Test” to run it.
If the flow runs successfully, you will see the logs. In the “Output” tab you will see outputs of each components. The logs are meant to help you debug a flow in case something did not work as expected.
Let’s now examine the response from the OpenWeather REST API. If you look at the output logs, you will notice that the returned json is quite complex and it contains fields that probably you will not need. Dextcloud has a very powerful component that lets you manipulate json objects. For instance, it allows to merge two json objects into one object or to simply build a json with fields of your choice. Let’s try it out and see how useful it is.
First, connect the HTTP component with the Mapper and click the gray circle situated in the upper right corner of the Mapper component icon. It will open the pop-up that consists of two parts. The left-hand side part shows objects that you can use to build your custom json object. The right-hand side is a canvas where you build your custom object.
To add a new attribute click the “+” icon and enter the name of an attribute. Next step is to link your newly added custom attribute with the attribute of the source json. First click on the custom attribute name (it will become selected). Then click on the relevant attribute of the source object. You will notice that, a sample value will be displayed next to the attribute name. In this way you can map all attributes you are interested in. Please do not forget to click the “Save” button before closing the pop-up.
To proceed with our app, create the same json as on the screenshot below.
Now, we can carry on with the next component. Please drag and drop Amazon SES (Simple Email Service) component to the canvas but do not connect it yet with the Mapper. First, choose the Connection - select “AWS”. The connection is needed in this case since AWS, requires authentication with AWS key and secret key before calling any of its services.
Let’s now define remaining properties - enter a “Subject” (e.g. “Today weather in London”), an “Email address” and a message body. Inside the body, you can refer to the json’s fields by surrounding them by #. A sample message could be - “Today we expect #description#. The lowest temperature will be #minTemp# and the highest #maxTemp#. Please also change the component’s title to something more meaningful, e.g. “Weather Email”.
This could complete our first application created with Dextcloud but let’s make it a bit more interesting by adding sending a text message in case the rain is expected. The OpenWeather json seems to not have a dedicated attribute for rain prediction but, let’s assume that, when it is going to rain, it will be mentioned in the weather description. So we will know that the rain is coming if the description contains words like “rain” or “drizzle”. Then, instead of an email, we will send a text message.
First, add the Twilio component from the “Notification” component group. Choose a connection “Twilo” or define a new Connection (Twilio requires providing user and password), choose the operation “Send text message” and enter required properties - phone numbers “From” and “To” and a text message body (Please notice that you may need to configure these phone numbers in Twilio settings before sending text messages becomes possible). Change the component name to “Rain alert” to make the flow easier to read.
Now let’s handle sending text messages. We will use the component called Router - it allows to define cases that base on a JsonPath - if a JsonPath condition is met then a flow is redirected to a selected component.
Let’s add the first case - click Add and enter a JSON path that will match the word “rain” in the weather description:
\$[?(@.weather =~ /.*rain.*/)] and select Rain alert from the list of Components. As “Default Component” select Weather Email.
We have made it! The application is completed. Click the button “Test” to check if the flow works as expected. You should receive an email with the weather forecast and also a text message if a description contains the word “rain”.
Now it is time to deploy the flow. Please click the button “Deploy” located in the upper right corner, choose a Cluster and accept default settings in the Deploy pop-up.
Once the application is deployed, go to the Flow screen, and click on the flow to open right-hand side window.
Now you can test the deployed flow by clicking the “Run” button. Or you can schedule its periodical executions.