AI Model Tutorial 2 - Using an Intent Detection Model in a Flow

This tutorial is a guide to walk you through using an AI model for intent detection in a Flow.


The Problem to Solve

You have an email account for customers requesting a change of address. You want to automate the process of deciding if the customer's email has the required information for changing an address and reply accordingly.

Required Materials

To follow along with this tutorial, you will need:

Video - Change of Address Intent Detection Flow

The previously created Intent Detection AI model associated with this tutorial has been trained on a small set of data and therefore may not respond accurately to emails outside the basic pattern represented in the training materials – though you are welcome to test the limits. With more extensive training, the AI model could recognize and respond to more complex requests. This model is. meant for training and demo purposes.

Guide Outline

The steps to complete for this guide are as follows:

  1. Create an IMAP Connection.
  2. Create an SMTP Connection.
  3. Create Input for Email from Customers.
  4. Create Output for Email Response with Change of Address Request.
  5. Create Output for Email Response with No Change of Address Request.
  6. Build Flow.
  7. Prepare Demo Emails.
  8. Run Flow.
  9. Confirm Success.

Create an IMAP Connection

The IMAP Connection in Hero_Flow is responsible for connecting to the email account which receives emails. For this demonstration, a Gmail account is used.

  1. From the Hero_Flow dashboard, click Connections.
  2. Click Create New Connection.
  3. Enter a name for the Connection. (Example: Gmail_IMAP)
  4. Select IMAP for the Connection type.
  5. Enter the email IMAP hostname. (Example: imap.gmail.com)
  6. Enter the port number. (Example: 993)
  7. Select the protocol. (Example: For Gmail, IMAPS is required.)
  8. Enter the username for the email address.
  9. Enter the password for the email address.
  10. Click OK to finish saving the Connection. 

Create an SMTP Connection

The SMTP Connection in Hero_Flow is responsible for connecting to the email account which sends email. For this demonstration, a Gmail account is used.

  1. From the Hero_Flow dashboard, click Connections.
  2. Click Create New Connection.
  3. Enter a name for the Connection. (Example: Gmail_SMTP)
  4. Select SMTP for the connection type.
  5. Enter the email IMAP hostname. (Example: smtp.gmail.com)
  6. Enter the port number. (Example: 587)
  7. Enter the username for the email address.
  8. Enter the password for the email address.
  9. Click OK to finish saving the Connection.

Create an Input for the Email Data

The IMAP Input in Hero_Flow is responsible for extracting data from an email Connection.

  1. From the Hero_Flow dashboard, click Inputs.
  2. Click Create New Input.
  3. Enter a name for the Input. (Example: Gmail_Source)
  4. Select the GMAIL_IMAP connection. 
  5. Select INBOX for the folder where the emails to read are located.
  6. Click OK to finish saving the Input.

Create an Email Output for Change of Address Request 

The first SMTP Output created is to send a response email to the customer confirming a successful change of address.

  1. From the Hero_Flow dashboard, click Outputs.
  2. Click Create New Output.
  3. Enter a name for the Output. (Example: Intent_Change_Of_Address_Success)
  4. Select the GMAIL_SMTP connection. 
  5. Enter a subject for the email. (Example: Change of Address - Successfully Processed Your Request)
  6. Enter the template text in HTML format for the email body.

     Example template

    <html>

    <body>

    Dear Customer,

    <br/>

    <br/>

    Thank you for submitting your request.

    Your address has been successfully updated.  

    <br/>

    <br/>

    Kind regards, 

    <br/><br/><br/><br/>

    --

    <br/><br/><br/><br/>

    Original email:

    <br/>

    <br/>

    {{EMAIL_CONTENT}}

    --

    <br/><br/><br/><br/>

    Change of Address Intent Probability: {{pIntent}}

    </body>

    </html>

  7. Under the SMTP fields mapping table:
    1. Remove all fields other than From and Receiver_To.
    2. Click Add field.
      1. Enter EMAIL_CONTENT as the field name and select STRING as the data type.
    3. Click Add field.
      1. Enter pIntent as the field name and select DOUBLE as the data type.
  8. Click OK to finish saving the Output.

Create an Email Output for No Change of Address Request

The second SMTP Output created is to send a response emails to customers who did not send a change of request address. 

  1. From the Hero_Flow dashboard, click Outputs.
  2. Click Create New Output.
  3. Enter a name for the Output. (Example: Intent_Change_Of_Address_Failure)
  4. Select the GMAIL_SMTP connection. 
  5. Enter a subject for the email. (Example: Change of Address - Not a Change of Address Request)
  6. Enter the template text in HTML format for the email body.

     Example template

    <html>

    <body>

    Dear Customer,

    <br/>

    <br/>

    Thank you for your email.

    You did not request a change of address.

    Your email will be resent to an agent.

    Please use this email address only for address change requests.

    <br/>

    <br/>

    Kind regards, 

    <br/><br/><br/><br/>

    --

    <br/><br/><br/><br/>

    Original email:

    <br/>

    <br/>

    {{EMAIL_CONTENT}}

    --

    <br/><br/><br/><br/>

    Change of Address Intent Probability: {{pIntent}}

    </body>

    </html>

  7. Under the SMTP fields mapping table:
    1. Remove all fields other than From and Receiver_To.
    2. Click Add field.
      1. Enter EMAIL_CONTENT as the field name and select STRING as the data type.
    3. Click Add field.
      1. Enter pIntent as the field name and select DOUBLE as the data type.
  8. Click OK to finish saving the Output.

Build the Flow

This automation Flow extracts the customer email addresses and the body of those emails. The email addresses are separated into individual records and processed through the AI model you created in the previous tutorial to check the probability that the customer is requesting a change of address. Those emails with a probability over 50% are sent a response indicating success. Emails processed with a probability of 50% or lower are sent a response that their message is being sent to a company representative for review.

  1. From the Hero_Flow dashboard, click Flows.
  2. Click Create New Flow.
  3. Enter a name for the Flow. (Example: Intent_detection_Address_Change)
  4. Click Add Input and select the IMAP Input you created above. (Example: Gmail Source)
    1. Add a note for context. (Optional).
  5. Click the plus button (+) to the right of the Input to add a function.
  6. Select the function Flatten List and click OK. 
    This function returns each element of a list as an individual record. This makes it possible to respond to a single email address from your list of extracted customer email addresses.
    1. Select the argument SENDER_ADDRESSES (LIST)
    2. Enter the Output field name SENDER_ADDRESS.
    3. Click OK.
  7. Click the plus button (+) to the right of the Input to add a function.
  8. Select the function Address_Change_Intent under the AI model section which you created in the previous tutorial and click OK.
    1. Under Input function field, select EMAIL_CONTENT (STRING).
    2. Click OK.
  9. Click the branch icon to the right of the AI model to create two branches which the Flow can take depending on the probability that each customer email is requesting a change of address.
  10. Select the filter IsGreaterThan and click OK.
    1. Select the argument label (DOUBLE).
    2. Enter the number 0.5 (I.e., is greater than 50%) for the > right side argument.
    3. Click OK.
  11. Click the branch icon to the right of the AI model again.
  12. Select the filter IsLessThanOrEqual and click OK.
    1. Select the argument label (DOUBLE).
    2. Enter the number 0.5 (I.e., is less than or equal to 50%) for the <= right side argument.
    3. Click OK.
  13. Click Add Output to the right of the IsGreaterThan filter.
    1. Select Intent_Change_Of_Address_Success and click OK.
    2. Match the Input fields to the Output fields.
      1. Select SENDER_ADDRESS (STRING) for From(String).
      2. Select SENDER_ADDRESSES (LIST) for Receiver_To(LIST{STRING}).
      3. Select EMAIL_CONTENT (STRING) for EMAIL_CONTENT(STRING).
      4. Select label (DOUBLE) for pIntent(DOUBLE).
      5. Click OK.
  14. Click Add Output to the right of the IsLessThanOrEqual filter.
    1. Select Intent_Change_Of_Address_Failure and click OK.
    2. Match the Input fields to the Output fields.
      1. Select SENDER_ADDRESS (STRING) for From(String).
      2. Select SENDER_ADDRESSES (LIST) for Receiver_To(LIST{STRING}).
      3. Select EMAIL_CONTENT (STRING) for EMAIL_CONTENT(STRING).
      4. Select label (DOUBLE) for pIntent(DOUBLE).
      5. Click OK.
  15. Click Save in the top toolbar in Flow Studio to save the Flow.

Prepare Demo Emails

  1. Open any email service.
  2. Compose three emails. One email is a true change of address request and two emails are not address change requests.
    1. The email recipient for all three emails is the email address of your IMAP Input.
    2. Example email texts:
      1.  Email 1 - True Address Change Request

        Subject:

        Address Change Request

        Body:

        Good day,

        Our offices recently moved to a new space. Please modify our billing address to 5416 Business Court 34 Pawnee, IN. 12345.

        Thanks.

      2.  Email 2 - False Address Change Request

        Subject:

        Change of Reservation

        Body:

        Hello,

        I would like to move our 17:00 o'clock appointment to 20:00 o'clock on the 5th of May.

        Thank you.

      3.  Email 3 - False Address Change Request

        Subject:

        Request to book a flight

        Body:

        Hello,

        Please book me a ticket from London to California on the 7th of July 2020. 

        Have a nice day.

  3. Send all three emails.

Run Flow

  1. Open the Hero_Flow application. 
  2. From the Hero_Flow dashboard, click Flows.
  3. Open the Flow you created above in this tutorial. (Example: Intent_detection_Address_Change)
  4. Click Run Now in the top toolbar of Flow Studio to run the Flow immediately.

Confirm Success

  1. Open the email account from where the three emails were sent. 
    1. You should see three responses sent from the SMTP Output.
      1. One email notifying that the change of address request was successfully processed.
      2. Two emails notifying that the original email was forwarded to a representative.