in functions/source/lex_custom_resource/lex_custom_resource.py [0:0]
def create_lex_intents(fulfillment_lambda, intents, kendra_search_role_arn, kendra_index_id, account_id, slot_type_version):
"""
Creates Lex intents.
:param fulfillment_lambda: ARN of fulfillment Lambda
:param intents: List of Lex intents
:param kendra_search_role_arn: ARN of role created for creating custom Lex bot
:param kendra_index_id: Kendra Index ID
:param account_id: AWS Account ID
:param slot_type_version: Map of Slot type versions.
:return: List of intents (Name and Version)
"""
intent_list = []
for intent in intents:
if 'slots' in intent:
for slot in intent['slots']:
if 'slotType' in slot and slot['slotType'] in slot_type_version:
slot['slotTypeVersion'] = slot_type_version[slot['slotType']]
if intent['name'].startswith('AMAZON.'):
continue
if 'parentIntentSignature' in intent and intent['parentIntentSignature'] == 'AMAZON.KendraSearchIntent':
intent['kendraConfiguration']['kendraIndex'] = 'arn:aws:kendra:' + os.environ['AWS_REGION'] + ':' + account_id + ':index/' + kendra_index_id
intent['kendraConfiguration']['role'] = kendra_search_role_arn
intent.pop('version', None)
if intent['fulfillmentActivity']['type'] == 'CodeHook':
intent['fulfillmentActivity']['codeHook']['uri'] = fulfillment_lambda
try:
intent_get_response = lex_client.get_intent(name=intent['name'], version='$LATEST')
intent['checksum'] = intent_get_response['checksum']
except lex_client.exceptions.NotFoundException:
pass
intent['createVersion'] = True
intent_response = lex_client.put_intent(**intent)
intent_list.append({
'intentName': intent['name'],
'intentVersion': intent_response['version']
})
logger.info("Created/updated intent %s", str(intent['name']))
return intent_list