How to call another intent without prompting to user in Lex?
Asked Answered
D

2

5

Is it possible to trigger intent-B from the lambda function of intent-A without prompting to user?
Suppose user typed something and an intent-A is fired, after some processing I want to trigger some other intent i.e intent-B.
User can also directly trigger intent-B through specific utterances. Any help is appreciated.

Discotheque answered 1/12, 2017 at 6:31 Comment(0)
D
4

I ended up doing below to call intent-B from intent-A without prompting anything to user:

  • give access to invoke lambda functions to your calling lambda function i.e lambda function of intent-A
  • get the name of backend lambda function of intent-B
  • call that lambda function with all the inputs using boto3
  • response will be in 'Payload' key of response object
  • get the response using read() method
  • get actual output in ['dialogAction']['message']['content']
  • return using default close() method

import boto3

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']
Discotheque answered 8/12, 2017 at 10:6 Comment(0)
S
3

Yes it is possible .From the lambda of Intent-A , you can write the below code :

        intentRequest.currentIntent.name='Intent-B';
        var param1={
                slot-B:null
            };
            intentRequest.currentIntent.slots=param1;
          callback(elicitSlot(outputSessionAttributes, 'Intent-B', intentRequest.currentIntent.slots, 'slot-B'));

Below is the function for elicitSlot

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

}

Sat answered 6/12, 2017 at 19:2 Comment(2)
thanks for answer, it's good method but still it is prompting the user with the slot details. I do not want to send anything to user as a prompt.Discotheque
This seems to be most appropriate approach as of now as it doesn't depends on external hooks. Thanks for sharing.Resnick

© 2022 - 2024 — McMap. All rights reserved.