无效的Lambda响应:Lambda响应提供了无效的插槽名称[slotId]

时间:2018-04-08 08:05:38

标签: node.js aws-lambda bots aws-lex

当lambda使用Invalid Lambda Response: Lambda response provided invalid slot names [slotId]向lex发送响应以获取未定义槽的槽值时,我收到错误elicitSlot

我将lex蓝图代码引用如下。

const handleOrder = async (intentRequest, callback) => {
    const source = intentRequest.invocationSource
    const id = intentRequest.currentIntent.slots.slotId

    if (source === 'DialogCodeHook') {
        // Perform basic validation on the supplied input slots.  Use the elicitSlot dialog action to re-prompt for the first violation detected.
        const slots = intentRequest.currentIntent.slots

        const validationResult = validateOrderRequest(id)
        if (!validationResult.isValid) {
            //reset the slot value
            slots[`${validationResult.violatedSlot}`] = null
            callback(elicitSlot(intentRequest.sessionAttributes, intentRequest.currentIntent.name, slots, validationResult.violatedSlot, validationResult.message))
            return;
        }
        const outputSessionAttributes = intentRequest.sessionAttributes || {}
        callback(delegate(outputSessionAttributes, intentRequest.currentIntent.slots))
        return;
    }

    ...
}

function validateOrderRequest(id) {
    if(!id){
        return buildValidationResult(false, 'slotId', `Tell me the ID.`);
    }
}

有什么可以提供错误?

1 个答案:

答案 0 :(得分:-1)

您无需使用语句

插槽[${validationResult.violatedSlot}] = null;

将插槽值指定为null是不好的做法。

删除此声明。我希望你不会得到那个错误。