Alexa:在DelegateDirective之后删除插槽

时间:2019-08-12 18:30:55

标签: alexa alexa-skills-kit voice

在委派新的意图后试图引出广告位时,我遇到了问题。

我有一个名为EnterPIN的意图,该意图处理围绕PIN输入进行帐户链接的对话流。它会检查他们是否已关联帐户,是否要求提供PIN,否则会告诉他们如何进行帐户关联。

理想的结果是在需要PIN的任何时间将其委托给该意图,并传递先前的意图,以便在身份验证完成后返回。

当我委托EnterPIN时,即使在当前意图上找到了PIN插槽,也无法填充PIN插槽。但是,当我通过“登录我”之类的话语直接调用EnterPIN意图时,便会正确引发该插槽,并在下一个请求时接受我的PIN。

CallContactCentre.js(摘要):

  return handlerInput.responseBuilder
    .addDelegateDirective({name: 'EnterPIN', slots: { 
      "OBFUSCATE_PIN": {
        "name": "OBFUSCATE_PIN",
          "confirmationStatus": "NONE"
       }
    }})
    .withShouldEndSession(false)
    .getResponse();

EnterPIN.js:

module.exports = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();

    console.log('request.intent', request.intent);

    return request.type === 'IntentRequest'
      && request.intent.name === 'EnterPIN'
      && request.intent.slots
      && request.intent.slots.OBFUSCATE_PIN
      && request.intent.slots.OBFUSCATE_PIN.value === undefined
      && handlerInput.attributesManager.getSessionAttributes().PIN === undefined
  },
  handle(handlerInput) {
    const requestAttributes = handlerInput.attributesManager.getRequestAttributes();
    const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();

    if(handlerInput.requestEnvelope.session.user.accessToken !== undefined) {
      return handlerInput.responseBuilder
        .speak('You have account linked. Please enter your PIN code')
        .reprompt(requestAttributes.t('PROMPT'))
        .addElicitSlotDirective('OBFUSCATE_PIN')
        .withShouldEndSession(false)
        .getResponse();
    } else {
      return handlerInput.responseBuilder
        .speak('You have not account linked. Please find this skill in the Alexa directory and enable account linking')
        .reprompt(requestAttributes.t('PROMPT'))
        .addElicitSlotDirective('OBFUSCATE_PIN')
        .withShouldEndSession(false)
        .getResponse();
    }    
  },
};

直接调用:

requestEnvelope.request.intent = { name: 'EnterPIN', confirmationStatus: 'NONE',
  slots: { 
    OBFUSCATE_PIN: { 
      name: 'OBFUSCATE_PIN',
      value: '1234',
      confirmationStatus: 'NONE',
      source: 'USER' 
    } 
  } 
}

委托指令:

requestEnvelope.request.intent = { name: 'EnterPIN', confirmationStatus: 'NONE',
  slots: { 
    OBFUSCATE_PIN: { 
      name: 'OBFUSCATE_PIN',
      confirmationStatus: 'NONE',
      source: 'USER' 
    } 
  } 
}

如您所见,在进行直接调用时,我们获得了OBFUSCATE_PIN的值,但是当从委托指令中获得意图时,则未设置该值。

非常感谢所有可能解决此问题的信息。

谢谢

1 个答案:

答案 0 :(得分:0)

我认为,当您在委托指令中创建新的意图时,您可能需要包括“值”。

return handlerInput.responseBuilder
    .addDelegateDirective({name: 'EnterPIN', slots: { 
      "OBFUSCATE_PIN": {
        "name": "OBFUSCATE_PIN",
        "confirmationStatus": "NONE",
        "value": ""      <-----------
       }
    }})
    .withShouldEndSession(false)
    .getResponse();