At the moment, the chat bot will return the slots elicited from the user, back to the caller in the form of a JSON payload. Instead, we want our bot to perform the actual search of the trips database, and present the options back to the user, otherwise, our client (the browser) would need to make an additional call to the back-end to search for trips. While that may be what you want to do in some situations, in this case, we will implement a Lambda function to do all the work of fulfilling the request, and returning the results in one hit.
In this exercise, we will create a Lambda function written in NodeJS to perform the ‘fulfillment’ for our bot.
{
"sessionId": "885078239936701",
"inputTranscript": "Yes",
"interpretations": [
{
"intent": {
"slots": {
"date": {
"shape": "Scalar",
"value": {
"originalValue": "Tomorrow",
"resolvedValues": [
"2023-02-10"
],
"interpretedValue": "2023-02-10"
}
},
"destinationCity": {
"shape": "Scalar",
"value": {
"originalValue": "Sydney",
"resolvedValues": [
"melbourne"
],
"interpretedValue": "Sydney"
}
},
"originCity": {
"shape": "Scalar",
"value": {
"originalValue": "Melbourne",
"resolvedValues": [
"sydney"
],
"interpretedValue": "Melbourne"
}
}
},
"confirmationState": "Confirmed",
"name": "TravelBuddyCheckFlightsIntent",
"state": "ReadyForFulfillment"
},
"nluConfidence": 1
},
{
"intent": {
"slots": {},
"confirmationState": "None",
"name": "FallbackIntent",
"state": "ReadyForFulfillment"
}
}
],
"sessionState": {
"sessionAttributes": {},
"intent": {
"slots": {
"date": {
"shape": "Scalar",
"value": {
"originalValue": "Tomorrow",
"resolvedValues": [
"2023-02-10"
],
"interpretedValue": "2023-02-10"
}
},
"destinationCity": {
"shape": "Scalar",
"value": {
"originalValue": "Sydney",
"resolvedValues": [
"melbourne"
],
"interpretedValue": "Sydney"
}
},
"originCity": {
"shape": "Scalar",
"value": {
"originalValue": "Melbourne",
"resolvedValues": [
"sydney"
],
"interpretedValue": "Melbourne"
}
}
},
"confirmationState": "Confirmed",
"name": "TravelBuddyCheckFlightsIntent",
"state": "ReadyForFulfillment"
},
"originatingRequestId": "033310c3-eb7e-44e7-8e44-db2b62acc310"
},
"responseContentType": "text/plain; charset=utf-8",
"invocationSource": "FulfillmentCodeHook",
"messageVersion": "1.0",
"transcriptions": [
{
"resolvedContext": {
"intent": "TravelBuddyCheckFlightsIntent"
},
"transcription": "Yes",
"resolvedSlots": {},
"transcriptionConfidence": 1
}
],
"inputMode": "Text",
"bot": {
"aliasId": "TSTALIASID",
"aliasName": "TestBotAlias",
"name": "TravelBuddyChatBot",
"version": "DRAFT",
"localeId": "en_US",
"id": "0BTWXR7UVD"
}
}
This indicates that the Lambda function can correctly read the input data, and queried the DynamoDB table for flights from Melbourne to Sydney, and returned the matches.