Flow Tutorial 3 - Stock Price Email Response

This tutorial includes a video and written guide to walk you through building an automation Flow from start to finish.


The Problem to Solve

You want to automatically respond to emailed customer requests for stock price information and/or automatically email yourself stock price information every day.

Required Materials

To follow along with this tutorial you will need to have:

Gmail Account (free)

World Trading Data Account at https://www.worldtradingdata.com/ (free)

Download: Stock Request Email Text to copy and paste. 

Download: Response Email Format to copy and paste.

Download: Please email learning@automationhero.ai for access to the Swagger Definition. We are happy to share.

For best results, use the Chrome browser


Video - Set Up Gmail


Video - Stock Price Email Response


Guide Outline

The steps to complete for this guide are as follows:

  1. Basics for Creating Automations.

  2. Set Up Gmail and Prepare Demo Data.

  3. Set Up World Trading Data Account.

  4. Create Inbound Gmail Connection.

  5. Create World Trading Data Swagger Connection.

  6. Create SMTP Connection.

  7. Create Inbound Gmail Input.

  8. Create Outbound Gmail Output.

  9. Build Flow.

  10. Run Flow.

  11. Confirm Success.

  12. Stop or Delete the Environment.

Basics for Creating Automations

The basics for building an automation are completing the following steps:

  1. Define the input data and how to access it. In this example emails in your Gmail inbox.

  2. Define the expected output data. In this example, email in your Gmail inbox with Stock price information pulled from a finance API.

  3. Create your automation Flow in our point-and-click interface (Flow_Studio) by connecting your input and output.

Set Up Gmail

Learn more about OAuth Authentication at https://developers.google.com/identity/protocols/OAuth2

Sign In

  1. Go to https://console.developers.google.com with the Google account which you want to use as a Connection in Hero_Flow.

  2. If this is your first time using the Google Cloud Platform. Agree to the terms of service, enter your country of residence, and click AGREE AND CONTINUE.

Create a Project for the Hero_Flow app

  1. Click Select a Project and then click New Project.

  2. Name the project Hero Flow and click Create.

  3. After the project has been created, click on the project name to open it.

  4. Click on APIs and Services from the menu on the left and select Credentials.

  5. Click on the OAuth consent screen from the menu on the left.

  6. Click External and then Create.

  7. Fill in the Application name with Hero_Flow.

  8. Fill in the Authorized domains with automationhero.ai and press Enter to commit the entry and then click Save.

  9. Click the Credentials tab and Create credentials drop-down menu and select OAuth client ID.

  10. Select Web application.

  11. Enter a name for the app.

  12. Enter your Hero_Flow redirect URI for the OAuth 2 setting.

    1. Copy and paste the Flow Server URL from your Hero_Flow environment. Do not copy over the tab name that follows automationhero.ai/ and instead type oauth2 after automationhero.ai/

      1. Example Hero_Flow instance URL: https://abcxyz123.cloud.automationhero.ai

      2. Example redirect URI to enter for the redirect URI: https://abcxyz123.cloud.automationhero.ai/oauth2

  13. Click Create. Your client ID and client secret are displayed. 

Build the Connection in Hero_Flow

After you have the client ID, client secret, and have the redirect URI set in your Google console, you can configure the rest of the Hero_Flow Connection details.

  1. Open Hero_Flow.

  2. Click Connections from the menu on the left.

  3. Click CREATE NEW CONNECTION.

  4. Give the Connection a name and select Gmail from the drop-down list for Connection type.

  5. The Gmail Connection details screen pops up with client ID and client secret fields. Copy and paste the client ID and client secret from Google Console into these fields.

  6. Click Sign in with Google. Select the email account you are using.

  7. On the pop up warning that the app is not verified, click Advanced and then click Go to automationhero.ai.

  8. Click Allow to grant permission to automationhero.ai to connect to your Gmail.

  9. A confirmation message is displayed if the connection has been established with your email account.

  10. If you receive the error message below, your Google mail API has not yet been enabled. Copy the URL in the 3rd line of the error message and paste it into your browser.

    1. Example:

    2. On the resulting page, enable your Google mail API by clicking ENABLE.

    3. In Hero_Flow exit out of error message and click Sign in with Google.

    4. Follow the steps above and this time you should not receive an error message.

  11. Click TEST CONNECTION. A confirmation message is displayed if the connection has been established with your Google account.

  12. Click OK to finish saving the Connection in Hero_Flow.

Prepare Demo Data

  1. Send yourself two emails with the following information:

    1. Email 1: Subject:Stocks to check Body: Hey, can you check out these stock tickers for me? TWLO TSLA MSFT

    2. Email 2: Subject: Stocks to check Body: Hi can you look up these stock tickers for me. AAPL GE GOOG

Set Up World Trading Data Account

  1. Go to https://www.worldtradingdata.com/ and click Sign Up.

  2. You will receive a verification email in your inbox. Click Verify Email Address.

  3. You will be automatically directed to a dashboard with your API token prominently displayed. You will need this token later.

Create Inbound Gmail Connection

  1. Open Hero_Flow.

  2. Click Connections from the menu on the left.

  3. Click CREATE NEW CONNECTION.

  4. Name the Connection Gmail and select Gmail  from Connection type drop-down list.

  5. The Connection details screen pops up with fields that need to be configured.

  6. Copy and paste your Client Id and Client secret from Google Console into the appropriate fields.

  7. Click SIGN IN WITH GOOGLE.

  8. Select your Gmail account and click Advanced to then Allow Hero_Flow access.

  9. Click TEST CONNECTION and then OK to finish saving the Connection in Hero_Flow.

Create World Trading Data Swagger Connection

  1. Open Hero_Flow.

  2. Click Connections from the menu on the left.

  3. Click CREATE NEW CONNECTION.

  4. Name the Connection World Trading Data and select Swagger from Connection type drop-down list.

  5. Click Choose File and upload the Swagger definition as a .json file included within the ZIP in the materials section of this course..

  6. Select GET /stock from the Endpoints drop-down list.

  7. Click the Reload icon for the Base URL and click Yes to reload field content.

  8. Click Test Connection and OK to save.

Create SMTP Connection for Gmail Outbound

  1. Open Hero_Flow.

  2. Click Connections from the menu on the left.

  3. Click CREATE NEW CONNECTION.

  4. Name the Connection Gmail Outbound (SMTP) and select SMTP from Connection type drop-down list.

  5. The SMTP Connection details screen pops up with fields that need to be configured.

    In order to configure the fields, you might need to contact your email administrator.
    Enter your email:

    • Host name: smtp.gmail.com

    • Port number: 587

    • Username: Your username

    • Password: Your password

    • Protocol: SMTP

  6. Click TEST CONNECTION and click OK to save.

Create Inbound Gmail Input

  1. Open Hero_Flow.

  2. Click Inputs from the menu on the left.

  3. Click CREATE NEW INPUT.

  4. Name the Input Gmail Inbox to specify the inbox in Gmail and select the previously created Gmail Connection.

  5. Select Inbox from the Labels drop-down list.

  6. Click OK to save.

Create Outbound Gmail Output

  1. Open Hero_Flow.

  2. Click Outputs from the menu on the left.

  3. Click CREATE NEW Output.

  4. Name the Output Gmail Outbound and select the previously created Gmail Outbound (SMTP) Connection.

  5. In the Template section, copy and paste the Email Body Template available for download in the materials section of this course.

  6. In the Subject field, fill in Stock Recap: {{name}}

  7. Add the following fields and data types to the SMTP fields mapping table:

    1. Name: name Data type: String

    2. Name: symbol Data type: String

    3. Name: currency Data type: String

    4. Name: price Data type: String

    5. Name: day_high Data type: String

    6. Name: day_low Data type: String

    7. Name: volume Data type: String

  8. Click the Delete icon to delete the following fields in the SMTP fields mapping table.

    1. Name: Receiver_CC

    2. Name: Receiver_BCC

    3. Name: Attachments

    4. Name: Attachment names

  9. Click OK to save.

Build Flow

  1. Open Hero_Flow.

  2. Click Output from the menu on the left.

  3. Click CREATE NEW FLOW.

  4. Name the Flow and click OK.

  5. Click Add Input and select the previously created Gmail Inbox.

  6. Click Plus Sign (+) and select the Function ConstantString.

  7. Name the Output field name api_token and copy and paste your API token from World Trading Data - see instructions for accessing this above.

  8. Click Plus Sign (+) and select the Function Contains.

  9. Select Email_Content (STRING) for the Argument and fill in stock for the Token and click OK.

  10. Click Plus Sign (+) and select the Function RegExtract.

  11. In the Argument drop-down list, select EMAIL_CONTENT (STRING).

  12. Fill out the RegEx field with: \b[A-Z]{2,4}\b

  13. Click Plus Sign (+) and select the Function Concat List items.

  14. In the Argument drop-down list, select RegExtract(LIST{STRING]).

  15. Name the Output field name Concat Stock Tickers.

  16. Type in a comma (,) for the JoinerMessageConstants field and click OK.

Configure Swagger API Lookup

  1. Click Plus Sign (+) and select the Function Swagger Lookup.

  2. Select the previously created World Trading Data Connection from the Connection drop-down list.

  3. Select GET /stock from the Endpoints drop-down list.

  4. The Swagger Lookup configuration screen pops up. In the Argument drop-down list, select the previously created Concat Stock Tickers(STRING) for the Parameter name symbol(STRING).

  5. In the Argument drop-down list, select the previously created api_token(STRING) for the Parameter name api_token(STRING).

  6. Click OK.

Format Swagger Output

  1. Click Plus Sign (+) and select the Function Flatten List.

  2. Select data (LIST) from the Argument drop-down list.

  3. The Flatten List configuration screen pops up, click OK.

Prepare Email

  1. Click Plus Sign (+) and select the Function ConstantString.

  2. Name the Output field name email address.

  3. In the String constant field, fill in the email recipient and sender and click Okay.

  4. Click Plus Sign (+) and select the Function TokenizeList.

  5. In the Argument drop-down list, select the previously created email address(STRING).

  6. Name the Output field name Email_List.

  7. In the Separator field type a comma (,) and click OK.

Add Output

  1. Click Add Output.

  2. Select the previously created Gmail Outbound Output and click OK.

  3. Map the following input fields to the corresponding Output field:

    1. FROM(STRING) to From(STRING)

    2. Email_List(LIST{STRING}) to Receiver_To(LIST{STRING})

    3. name(STRING) to name(STRING)

    4. symbol(STRING)to symbol(STRING)

    5. currency(STRING) to currency(STRING)

    6. price(STRING)to price(STRING)

    7. day_high(STRING) to day_high(STRING)

    8. day_low(STRING) to day_low(STRING)

    9. volume(STRING) to volume(STRING)

  4. Click OK to Save.

  5. Click Save in Flow_Studio to save your work.

Run Flow

  1. Click Run Now in Flow_Studio.

Confirm Success

  1. Go to your email and refresh.

  2. Check that you received automatic emails with the updated stock price.

Stop or Delete the Environment 

Running an environment costs money by the hour. Reduce costs by stopping or deleting an environment you are not actively using.

  1. Navigate back to your cloud home screen.
  2. Click the settings icon next to the name of your environment.
  3. Choose Stop or Delete to stop or delete the environment.