簡體   English   中英

Alexa跳過插槽還是以編程方式設置?

[英]Alexa skip slot or set it programmatically?

我正在研究一種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插槽,並將默認值分配給我不需要的answer插槽(因此,如果測驗中有3個問題,但有5個插槽,則將分配最后2個插槽占位符值)。

我該怎么做? 有沒有辦法以編程方式設置插槽值?

這個Alexa博客帖子似乎描述了我的需求,但是不幸的是,它是使用ASK SDK v1編寫的,因此我不確定如何使用v2完成它。

是的,可以跳過1個或多個插槽值。

我可以想到兩種解決您的問題的方法。

1)使用addDelegateDirective代替addElicitSlotDirective收集槽值和填充時dialogState是“ 已啟動 ”像下面的代碼片段你不一些任意值,需要的插槽。

 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 } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM