Amazon Lex accepting ConfirmIntent on any response
Asked Answered
A

1

4

I have an intent-A which is triggered by some user input. When the response is given to user I have used ConfirmIntent instead of Close so that I can switch/chain another intent (lets say intent-B).

Ideally if user type "yes" then intent should be triggered and if user type "no" then it should not. Problem is that intent-B is being triggered no matter what I type.

I have read about ConfirmIntent from here, here and here.

Calling Code:

session_attributes = {"confirmationContext": "AutoPopulate"}
return confirm_intent(session_attributes , 'intent-B', slots, 'Do you want to invoke intent-B')

ConfirmIntent Code:

def confirm_intent(session_attributes, intent_name, slots, message):
    return {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'ConfirmIntent',
            'intentName': intent_name,
            'slots': slots,
            'message': {
                'contentType': 'PlainText',
                'content': message
            }
        }
    }

In the logs I can see that confirmationStatus': 'Denied' when I type "no" but even then intent-B is being called.

Am I missing something or is it designed this way?

NOTE: For workaround I am adding below code in the DialogCodeHook of intent-B

if 'confirmationStatus' in intent_request['currentIntent'] and intent_request['currentIntent']['confirmationStatus'] == 'Denied':
    return close("Ok, let me know if you need anything else.", session_attributes)
Acetabulum answered 14/12, 2017 at 10:36 Comment(0)
M
5

You are handling this correctly.

When you are passing intent-B into your confirm_intent request. You are telling Lex to pass the users response to intent-B. When the user responds with "no", the Denied value is correctly passed on.

Alternatively, you could have intent-A in your confirm_intent request. Then when the response hits intent-A you can use Close on denial and Delegate on confirmation to pass the flow to intent-B. This is "more correct" but will result in additional computation, so it's a trade off.

If you have multiple follow up requests, you could consider using ElicitIntent to instead ask the user "What can I help you with?". Having an an intent with utterances such as "nothing", "goodbye" will catch negative responses. This is a slightly different use case and may not be appropriate for you.

Mews answered 14/12, 2017 at 19:11 Comment(3)
so the intent-B will always be called but we can stop it's execution in DialogCodeHook by validating "confirmationStatus". is that correct?Acetabulum
@Acetabulum I've added another approach you can use using Delegate to only call intent-B when required. This is more computationally expensive so it's your call if you think it's a better wayMews
Hi @Milk, confirmationStatus is being set to Confirmed even if I type some single words like outlook, printer etc which are nowhere closer to yes. how to resolve this... any idea?Acetabulum

© 2022 - 2024 — McMap. All rights reserved.