【问题标题】:Alexa skip slot or set it programmatically?Alexa跳过插槽或以编程方式设置它?
【发布时间】:2018-12-05 22:28:34
【问题描述】:

我正在研究一项 Alexa 技能,该技能基本上是一个测验,其中 Alexa 会根据存储在发电机表中的用户状态连续询问用户多个问题,主题会有所不同。这行得通。我这样做的目的是为每个答案都有一个槽,并且我使用对话管理来引发每个响应,直到它们都被填满。下面是一些代码:

if(!answers.NewWordSpanishAnswer) {
  const newWordIntroAudio = sound('intro');
  const promptAudio = sound(`new-word-${word}-spanish-intro`);
  return handlerInput.responseBuilder
    .speak(newWordIntroAudio + promptAudio)
    .reprompt(promptAudio)
    .addElicitSlotDirective('NewWordSpanishAnswer')
    .getResponse();
}

if(!answers.NewWordEnglishAnswer) {
  const responseAudio = sound(`new-word-${word}-spanish-correct`);
  const promptAudio = sound(`new-word-${word}-english-intro`);
  return handlerInput.responseBuilder
    .speak(responseAudio + promptAudio)
    .reprompt(promptAudio)
    .addElicitSlotDirective('NewWordEnglishAnswer')
    .getResponse();
}

// etc. repeat for each question

问题是我需要创建一个需要可变数量问题的测验,但模型中定义了插槽,因此我无法更改完成意图所需的答案数量。我认为这样做的方法是提供一些任意数量的answer 插槽并将默认值分配给我不需要的那些(所以如果测验有 3 个问题,但有 5 个插槽,最后 2 个插槽将被分配占位符值)。

我怎样才能做到这一点?有没有办法以编程方式设置槽值?

This Alexa blog post 似乎描述了我的需求,但不幸的是它是使用 ASK SDK v1 编写的,所以我不确定如何使用 v2 来完成它。

【问题讨论】:

    标签: javascript node.js alexa alexa-skills-kit alexa-skill


    【解决方案1】:

    是的,可以跳过 1 个或多个槽值。

    我可以想出两种解决方案来解决您的问题。

    1) 使用 addDelegateDirective 而不是 addElicitSlotDirective 来收集槽值并在 dialogState时用任意值填充不需要的槽> 是 'STARTED' Like the following sn-p.

    const { request } = handlerInput.requestEnvelope;
    const { intent } = request;
    if (request.dialogState === 'STARTED') {
      
      intent.slots.slotToSkip.value = 'skipped'
      
      return handlerInput.responseBuilder
          .addDelegateDirective(intent)
          .withShouldEndSession(false)
          .getResponse()
    }

    2) 在第二种解决方案中,您可以使用会话变量来跟踪要引出的插槽数。喜欢

    let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
    sessionAttributes.count = 3 //Suppose you want to elicit 3 slots;
    handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
    
    if (sessionAttributes.count >= 0)
    {
      //addElecitSlotDirective
      sessionAttributes.count = sessionAttributes.count--;
      handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
    }
    else{
      //here you will get the required number of slots
    }

    【讨论】:

    • 在第二种解决方案中,我会在收到足够的插槽值后使用withShouldEndSession 来停止意图吗?我想过这样做,但我认为在所有插槽都被填满之前停止意图可能会导致问题。不是这样吗?
    • 否,withShouldEndSession 决定了当前与用户的技能会话在传递响应后应该保持打开还是关闭。它与收集槽值无关。
    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 2011-05-04
    • 1970-01-01
    相关资源
    最近更新 更多