arshid dar
arshid dar

Reputation: 1485

how to get matched utterance inside lambda used with amazon lex?

i have created a bot in amazon lex and an utterance like

"show me top ten vendors"

so if i type

"show me top ten vendrs"

lex still matches it with utterance even though it has a spelling mistake which is ok for me. but i need to know what utterance was matched with my input transcript inside lambda. is it possible to do? i tried to find it inside event object which is passed to lambda but could not find anything.

Upvotes: 2

Views: 1360

Answers (2)

sid8491
sid8491

Reputation: 6800

As of now, it is not possible for Lex to tell which utterance it matched to determine the intent.

You can however do one thing, after intent is matched write a code to get the utterances of matched intent, then match every input to each of those utterances and select the closest one.

client_model = boto3.client('lex-models')
bot_details = client_model.get_intent(
    name='name_of_your_intent',
    versionOrAlias='$LATEST'
    )

bot_details['sampleUtterances'] will contain all the utterances. You can use some string matching library like FuzzyWuzzy for matching closest string.

Hope it helps.

Upvotes: 0

Parrett Apps
Parrett Apps

Reputation: 589

You should be able to see the matched intent in the event object sent from Lex to Lambda as event.currentIntent.name. The full event format is documented here - https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html
The utterance can be referenced as event.inputTranscript

The following example collects the currentIntent and utterance and writes both to the log file as expected. Hope this helps!

exports.handler = (event, context, callback) => {
    
console.log("incoming event details: " + JSON.stringify(event));
console.log("Matched intent: " + event.currentIntent.name);
console.log("Utterance: " + event.inputTranscript);


};

Upvotes: 1

Related Questions