Search code examples
aws-lambdaamazon-lexamazon-connect

How to restrict Amazon Connect to a specific set of Lex intents out of multiple intents?


I am new to AWS, and facing a problem with Amazon Connect and Lex. I have 11 intents in my Lex bot. In Amazon Connect Contact Flow inside the "Get Customer Input" I have included only 5 out of 11 intents. Get Customer Input screenshot. My problem is that I want to restrict Lex to those certain intents, i.e. when a user speaks, "Get Customer Input" should trigger only one of those 5 intents instead of triggering one of all 11 intents that are in the bot.

Intents that I have inside Get Customer Input:

  1. newRes: when a customer says New Reservation
  2. removePreviousRes: when a customer says Delete my Reservation or Cancel my Reservation
  3. updatePreviousRes: when a customer says Change my Reservation or Update my Reservation
  4. checkRideStatus: when a user says What is the status of my ride
  5. getAnOperator: when a user says Talk to operator

I also have a newUser intent in the Lex bot which can be triggered by saying New User or New Account or something similar. Now if a user says New User or New Account at Get Customer Input block, newUser intent will be triggered even though I have not added it inside Get Customer Input block as a parameter. Is there a way to restrict Lex to only those 5 intents? Because I need the newUser intent later in the Contact Flow, and I don't want the user to trigger it at the start of Contact Flow. Any ideas? Can I restrict it using Lambda function?


Solution

  • You can definitely control this yourself using sessionAttributes and your Lambda Function.

    You cannot stop Lex from attempting to match user input to some of your intents, however, you can check if those intents are triggered when you don't want them to be, based on a variable that you can create to keep track of where the user is in the conversation across multiple intents.

    To do that, make use of Lex's sessionAttributes. These can also be created or updated inside of Connect. You can also receive Lex's sessionAttributes in Connect as an "External" Contact Attribute: $.Lex.SessionAttributes.attributeKey

    For example:
    Set up an attribute called convo_point and set the value at start of the Connect conversation as "initiate" or "beginning". Then consider your conversation flow and the different check points you need where you can allow or disallow certain intents.

    Then inside of your Lex's Lambda, before handling each intent, check this convo_point sessionAttribute and compare with the triggered intent. If the convo point is too early for New User intent, then build a proper response with an ElicitIntent response type and ask the user to try a different intent. As the user fulfills other intents, then you can update the convo_point to reflect that and allow the New User intent to be fulfilled only after that has happened.