in functions/source/kendra_search_intent_handler_lambda/lambda_function.py [0:0]
def kendra_search_intent_handler(intent_request, session_attributes):
"""
Fallback intent handler. Generates response by querying Kendra index.
:param intent_request: Request
:param session_attributes: Session attributes
:return: Response string
"""
session_attributes['fallbackCount'] = '0'
# fallbackCount = helpers.increment_counter(session_attributes, 'fallbackCount')
try:
slot_values = helpers.get_latest_slot_values(intent_request, session_attributes)
except config.SlotError as err:
return helpers.close(session_attributes, 'Fulfilled',
{'contentType': 'CustomPayload', 'content': str(err)})
logger.debug('<<help_desk_bot>> kendra_search_intent_handler(): slot_values = %s',
json.dumps(slot_values))
query_string = ""
if intent_request.get('inputTranscript', None) is not None:
query_string += intent_request['inputTranscript']
logger.debug(
'<<help_desk_bot>> kendra_search_intent_handler(): calling get_kendra_answer(query="%s")',
query_string)
kendra_response = helpers.get_kendra_answer(intent_request['kendraResponse'])
if kendra_response is None:
response = "Sorry, I was not able to understand your question. Could you please repeat?"
return helpers.close(session_attributes,
'Fulfilled', {'contentType': 'CustomPayload', 'content': response})
logger.debug(
'<<help_desk_bot>> "kendra_search_intent_handler(): kendra_response = %s',
str(kendra_response))
return helpers.close(session_attributes, 'Fulfilled',
{'contentType': 'CustomPayload', 'content': kendra_response})