简体   繁体   中英

AWS LEX: Slot update, intent update and then new publishing bot through a Lambda function

I am writing a lambda function that has an array of words that I want to put into a slotType, basically updating it every time. Here is how it goes. Initially, the slotType has values ['car', 'bus']. Next time I run the lambda function the values get updated to ['car', 'bus', 'train', 'flight'] which is basically after appending a new array into the old one.

I want to know how I publish the bot every time the Lambda function gets invoked so the next time I hit the lex bot from the front-end, it uses the latest slotType in the intent and newly published bot alias. Yep, also the alias!

I know for a fact that the put_slot_type() is working because the slot is getting updated in the bot.

Here is the function which basically takes in new labels as parameters.

def lex_extend_slots(new_labels):
    print('entering lex model...')
    lex = boto3.client('lex-models')
    slot_name = 'keysDb'
    intent_name = 'searchKeys'
    bot_name = 'photosBot'
    res = lex.get_slot_type(
        name = slot_name,
        version = '$LATEST'
    )
    current_labels = res['enumerationValues']
    latest_checksum = res['checksum']
    arr = [x['value'] for x in current_labels]
    labels = arr + new_labels
    print('arry: ', arr)
    print('new_labels', new_labels)
    print('labels in lex: ', labels)
    labels = list(set(labels))
    enumerationList = [{'value': label, 'synonyms': []} for label in labels]
    print('getting ready to push enum..: ', enumerationList)
    res_slot = lex.put_slot_type(
        name = slot_name,
        description = 'updated slots...',
        enumerationValues = enumerationList,
        valueSelectionStrategy = 'TOP_RESOLUTION',
    )
    res_build_intent = lex.create_intent_version(
        name = intent_name
    )
    res_build_bot = lex.create_bot_version(
        name = bot_name,
        checksum = latest_checksum
    )
    return current_labels

It looks like you're using Version 1 of the Lex Models API on Boto3.

You can use the put_bot method in the lex-models client to effectively create or update your Lex bot.

The put_bot method expects the full list of intents to be used for building the bot. It is worth mentioning that you will first need to use put_intent to update your intents to ensure they use the latest version of your updated slotType.

Here's the documentation for put_intent .

The appropriate methods for creating and updating aliases are contained in the same link that I've shared above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM