3

I am working on aws lex I have an intent-A. I named it welcomeMsg. I want to call another intent(B) from intent-A. In welcome msg(intent-A), it will say:

> `"Hi, I am a xxx-BOT. i can help you with following:`
       A
       B
       C

If I Say B, it should go to intent-B . This is what I want to do but I am unable to achieve this. Any help in python code will be appreciated .

sid8491
  • 6,622
  • 6
  • 38
  • 64
ajaysheoran2323
  • 109
  • 1
  • 10
  • no. I that question, he asked for "without" response and the code is also not in python. – ajaysheoran2323 Jan 08 '18 at 13:48
  • its without `prompt` **not** `response`, and you can easily convert that code from node to python. anyway i am adding detailed answer, do check. :) – sid8491 Jan 08 '18 at 14:01

1 Answers1

11

I have found these 3 methods for calling intent-B from intent-A.

1st method (using ConfirmIntent):

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
            }
        }
    }
msg = "Hi, I am a xxx-BOT. i can help you with following: A B C"

return confirm_intent(output_session_attributes, 'intent-B', new_slot, msg)

2nd method (pretending to be Lex and invoke Lambda method):

client = boto3.client('lambda')
data = {'messageVersion': '1.0', 'invocationSource': 'FulfillmentCodeHook', 'userId': '###', 
        'sessionAttributes': {}, 'requestAttributes': None, 
        'bot': {'name': '###', 'alias': '$LATEST', 'version': '$LATEST'}, 
        'outputDialogMode': 'Text', 
        'currentIntent': {'name': '###', 'slots': {'###': '###'}, 
        'slotDetails': {'###': {'resolutions': [], 'originalValue': '###'}}, 
        'confirmationStatus': 'None'}, 
        'inputTranscript': '###'}
response = client.invoke(
    FunctionName='{intent-B_lambda_function}',
    InvocationType='RequestResponse',
    Payload=json.dumps(data)
)
output = json.loads(response['Payload'].read())['dialogAction']['message']['content']

3rd method (using ElicitSlot):

def elicitSlot(sessionAttributes, intentName, slots, slotToElicit, message):   
    return {
        sessionAttributes,
        dialogAction: {
            type: 'ElicitSlot',
            intentName,
            slots,
            slotToElicit,
            message,
        }
    }

intentRequest['currentIntent']['name'] = 'intent-B'
param1 = {
    slot-B:null
    }
intentRequest['currentIntent']['slots'] = param1
return elicitSlot(outputSessionAttributes, 'intent-B', intentRequest['currentIntent']['slots'], 'slot-B', 'some_message')

Do check these methods, play with them and tweak according to your need. I think method 1 will best suit your need and it's easiest.

Comment in case you run into some problems.

Hope it helps.

sid8491
  • 6,622
  • 6
  • 38
  • 64