OTP Verification in Einstein Bots

Einstein for Service is a powerful set of features to support your agents and satisfy your customers. Using Einstein Bots can greatly reduce the time efforts made to resolve the customers queries. Since Bots are the virtual agents acting towards the customer complaints or grievances, they are trained in a manner to listen to customer's queries and act on some pre-defined rules. If you want to know more on how to use/create Einstein Bots and Chat deployment, visit the Einstein for Service module of Salesforce help documentation or Einstein Bots Developer Cookbook from Salesforce developer documentation.

Now, as we have understood the centric idea of our blog i.e. how to use the OTP verification in our Einstein Bots, let's consider a use case and we will try to accomplish it in a real world scenario.

Use Case:
Assume you are running a portal/public forum and there you have enabled the Einstein Bots to cater for the customer's queries/complaints/grievances. Now the customer can raise a case for the speedy resolution if Einstein Bots is not able to handle on the fly. But before creating a case, we do require the authentication of the customer's identity. Unless the customer is authenticated, he/she should not be allowed to create a case to help prevent the system to be flooded with uncategorized and unsolicited cases and thus helping our real agents to focus on valid cases.
Let's focus on the how to authenticate the customer using OTP as the verification method. We assume that the OTP will be sent to the registered mail address and once the correct OTP is entered, he/she will be allowed to go ahead otherwise an unauthenticated message will appear for wrong OTP.

Implementation: 
This implementation requires that you first go with my previous blog Send OTP using Flows to set up Generate OTP flow in your sandbox/production/dev environment. The steps for generating OTP and sending to customer's mail address and comparing the entered OTP are as follows.

Pre-requisites: You should have understanding of working of Einstein Bots. If not, I would recommend to visit the Einstein Bots Developer Cookbook from Salesforce developer documentation.
  1. Create a flow named Generate OTP: Follow the steps of Send OTP using Flows blog
  2. Create a flow named Compare Sent and Entered OTPs: Follow the below process to create the new flow for comparing Sent and Entered OTPs.
    • Create following new resources as variables from flow Manager palette. 
      • Sent OTP: Input enabled for OTP sent to Customer mail address
      • Entered OTP: Input enabled for OTP entered by Customer during Einstein Bot chat
      • Result: Output enabled to store the comparison result of Sent OTP and Entered OTP to be used in authentication in Einstein Bot
    • Drag-drop the Decision element on the flow builder canvas to compare the Sent and Entered OTP.
    • Drag-drop the Assignment element on the flow builder canvas to store the result of matched OTPs.
  3. Enable the Einstein Bots and create a chat deployment channel and establish an active bot. Follow the steps as outlined in Einstein Bots Developer Cookbook from Salesforce developer documentation.
  4. Once the Einstein Bot is all set up, follow the steps as mentioned below to get the authentication OTP and get authenticated.
    • Create three variables of type custom:
      • Sent OTP: To store the OTP sent to registered mail address to be able to send to flow.
      • Entered OTP: To store the entered OTP in the chat window to be able to send to flow.
      • result: To store the comparison result of Sent and Entered OTP from flow.
    • Create Authentication Successful dialogue: To show authentication success message if authentication is successful.
    • Create Authentication Failure dialogue: To show authentication failure message if authentication is not successful.
    • Create New Request dialogue: Once the customer hit this option, an OTP will be sent to registered mail address.
      • Call a flow action to sent OTP to registered mail address.
      • Ask a question to enter the OTP received.
      • Set up rules to be executed to call specific dialogue
        • Call Authentication Successful dialogue if comparison result is true.
        • Call Authentication Failure dialogue if comparison result is false.
Demo:
In order to view the behavior of all our implementation as described above, let's put our Einstein Bot(Embedded Service Chat) into one of our community. This is a pre-chat enabled bot which prepopulates the contact details from the system who has logged into the community and can continue to chat with our virtual bot. 
  1. Fill all necessary information and click on Start Chatting. 
  2. Select New Request and you will receive an OTP on your given mail address.
  3. Enter the correct OTP and you will be greeted with Successful Authentication message.
  4. If you enter wrong OTP, your authentication will be unsuccessful.



If you like this blog content and find inciteful, please comment and let me know. 

Comments

  1. Hi,
    When I am running the flow from flows, email with otp is being sent to recipent, but when I am using the flow as an action in the einstein bot, I am getting bouced mail like this:

    FlowApplication
    20:00 (29 minutes ago)
    to me

    Debug the failed interview in Flow Builder for the interview GUID: 4473113a3ff7c631ae766f7fd9d517e201e30f-28d5
    Error element send_otp (FlowActionCall).
    Probably Limit Exceeded or 0 recipients
    Flow Details
    Flow API Name: Send_OTP_to_change_phone_number
    Type: Autolaunched Flow
    Version: 1
    Status: Active
    Org: Kusum org (00D5j000004mJ7a)
    Flow Interview Details
    Interview Label: send otp 1/3/2022, 6:30 AM
    Interview GUID: 4473113a3ff7c631ae766f7fd9d517e201e30f-28d5
    Current User: Platform Integration User (0055j000003UT8B)
    Start time: 1/3/2022, 6:30 AM
    Duration: 0 seconds
    How the Interview Started
    Platform Integration User (0055j000003UT8B) started the flow interview.
    API Version for Running the Flow: 53
    Some of this flow's variables were set when the interview started.
    registrationNumber = 10000000
    GET RECORDS: getEmail
    Find all Student__c records where:
    Registration_Number__c Equals {!registrationNumber} (10000000)
    Store the values of these fields in getEmail: Id, Student_s_Email__c
    Result
    Successfully found records.
    APEX ACTION (LEGACY): Generate OTP for verification
    Apex Class: OTPGenerator
    Inputs:
    None.
    Outputs:
    {!OTP} = OTP (135417)
    SEND EMAIL: send otp
    Inputs:
    emailBody = Your OTP is {!OTP} (Your OTP is 135417)
    emailAddresses = {!getEmail.Student_s_Email__c} (*********@kiit.ac.in)
    emailSubject = Verify OTP

    Error Occurred: Probably Limit Exceeded or 0 recipients


    Please help me to solve this.

    ReplyDelete

Post a Comment