Try Catch

Using the Try Catch block in Quickwork Journey Builder. Quickwork is a no-code, API-based SaaS platform with pre-integrated apps to automate business workflows.

Quickwork Journey Builder does well with handling exceptions using the Try Catch functionality. In programming terms, Try and Catch are the two exception handling keywords that take care of the errors occurring when a piece of code is in the execution state.

Talking in terms of automation journeys, the Try block contains a list of actions ready for execution, and the Catch block contains the actions that need to be executed if any action in the try block fails. Most importantly, the Try Catch block helps ensure the execution of a journey doesn't stop even if an action fails. Thus, the malfunctioning of the system is handled and the user gets the benefit of getting a proper response i.e. the user is not left hanging waiting for a reply and receives an evident success or error response:

Figure 1: Try Catch flow chart

Let's consider a simple use case to understand the working and behavior of the Try Catch block.

Use case

Bob, a 25-year old techie, believes more in online marketing on social media platforms than being a professional email rattler. He hates switching between apps now and then as he's entirely dedicated to the company's Facebook Page brand endorsement. He needs a solution that can enable him to send emails to customers from the Facebook Page's messenger. Not only Bob but also any other employee visiting the company's Facebook page should be able to send emails directly rather than switching to Gmail and do the needful.

To build an automation solution for this use case, you need the following elements:

  • Trigger: Facebook Messenger—New text message

  • Actions: Facebook Messenger—Ask question, Gmail—Send email, and Facebook Messenger—Send message

  • Try Catch conditional block

Let's start creating a journey.

Configuring Facebook Messenger—New text message trigger

This will listen to a new text message from a user. Follow these steps to configure:

  1. Choose the Facebook Messenger app from the App field drop-down menu present right below the New Trigger block.

  2. Select the trigger event, i.e., New text message, in the Triggers list.

  3. To authorize a new Facebook account, click on the Link an account button. In the Connection window, enter the connection name of your choice and specify the Facebook Page ID in the Page ID field. Then click the Link Account button. If you have already linked an account, you'll get a drop-down menu to select the existing connection.

  4. Once done, your configured trigger will look like this:

Figure 2: Facebook Messenger trigger

Configuring Facebook Messenger—Ask question action

This action will serve as the first response message to a user visiting the Facebook page connected in the trigger and will be asking the user to provide their email ID. Let's start configuring it:

  1. Under the Steps section, click on the Simple Action button. Choose the Facebook Messenger app from the drop-down menu. Select the Ask Question action from the drop-down menu of the Actions list.

  2. Since we already have an active connection of the same app in the current journey, you don't need to create it again, and the following fields will open up automatically in which you need to enter the required details:

    1. In the User question field, specify Enter the email address to whom you want to send an email.

    2. In the Answer type field, select Text from the drop-down menu.

    3. In the Retry help field, specify a suggestion to enter a valid email ID. E.g., Please enter a valid email ID in this case.

    4. In the Recipient field, parse the key from the trigger App Data tree: Note: The Sender Id key is the Facebook Page ID that we have configured while establishing a connection. We will parse and get all the replies on this key.

Figure 3: Facebook Messenger—Ask question action configuration

Configuring Facebook Messenger— Ask question action

This action will help us send another response, specifying the email content to be sent, to the user when he/she completes entering the email ID.

To do so, we will need the same action, Ask question, to continue configuring the journey. Simply, clone the previous Facebook Messenger action by clicking on the copy icon. Now, let's do some alterations in the input fields as discussed here:

  1. In the User question field, specify Enter the email content you want to send.

  2. In the Retry help field, specify a suggestion to enter the content within the character limit. E.g., The email content should not exceed 2000-character limit, in this case.

Figure 4: Configuring Facebook Messenger-Ask question action

Using the Try Catch block

Whenever a journey faced an error, there was no endpoint-flow to show the failure status until we headed towards the History tab and searched for the root cause of the error. However, in this case, we will be using the Try Catch block, which would not only successfully execute our journey, but would also highlight the error, if any, in the response without stopping its execution.

To add the Try Catch block, click on the + icon and then click on the Business Logic block. This block shows all the various types of business/conditional logic that can be used. Select the Try Catch option from the drop-down menu.

Configuring Gmail action in the Try block

This action will send an email to the email ID that the user will specify as an input to Facebook Messenger:

  1. Under the Try block, click on Please choose an action.

  2. Choose the Gmail app from the drop-down menu in the App field.

  3. Select the action, Send email, from the drop-down menu in the Action field.

  4. Authorize and connect your Gmail account from which you want to sent the email to the customer. Once a connection is created, the following fields will open up in which you need to enter the details as follows:

    1. In the To field, parse the key from the first action, Facebook Messenger—Ask question data output tree.

    2. Enter the subject as Email Via Facebook Messenger in the Subject field.

    3. In the Message field, parse the key from the second action, Facebook Messenger—Ask question Data Tree Output:

Figure 5: Gmail action under Try

Configuring Facebook Messenger action under the Try block

It's necessary to notify the user when the email gets sent successfully otherwise, the user might lose interest in not getting a proper response. The Facebook Messenger — Send message serves the needful. Follow these steps to configure:

  1. Clone the Gmail — Send email action by clicking on the copy icon.

  2. Open the cloned action and select Facebook Messenger from the App field drop-down menu.

  3. Choose the Send message action for the Action field.

  4. The connection will automatically get established as we already connected the Facebook account previously.

  5. In the Message type field, select Response.

  6. Parse the key to the Recipient field and enter This email has been sent successfully as a response in the Message text field:

Figure 6: Facebook Messenger-Send message action

Bringing the Catch block into play

The journey we configured until this point was for a proper valid response. What about handling the exception in case of invalid user input, i.e., email address? The Catch block will help to do so. As Facebook Messenger is the go-to app in our use case, we will configure for one more time to handle the exception:

  1. Click on the Please choose an action bar under the Catch block.

  2. Search and choose the Facebook Messenger app from the App field drop-down menu.

  3. Select the Send Message action from the Action field.

  4. The connection will automatically get established as we connected the Facebook account previously.

  5. In the Message type field, select Response.

  6. Parse the key to the Recipient field and from the Catch block data output tree as a response in the Message text field:

Figure 7: Gmail under the Catch block

Here, we have completed configuring an event and all the actions that our journey requires. The complete journey outlook would look like this:

Figure 8: A complete Try Catch journey

Executing the journey

Click the Start Journey button and go to your Facebook Messenger account. Search the Facebook Page that you have connected with the journey. Now, send a message, say Hi, to the Facebook Page:

Figure 9: Successful execution

The page will automatically ask you to enter the email ID. Once done specifying the email address, the Facebook Page will ask you to enter the email content. As soon as you specify the content and hit the enter button, the email will be sent to the specified email ID, for which you will get a confirmation message on the messenger. For the sake of cross verification, check the SENT folder of your Gmail account that we have configured with the journey:

Figure 10: Email sent successfully

In the case of the invalid email ID, the messenger will pop-up an error notifying you that the email was not sent:

Figure 11: Exception handled