Как вернуть директиву Dialog.Delegate в модель Alexa Skill?

Я хочу создать простой многооборотный диалог с моделью Alexa Skill. Мое намерение состоит из 3-х слотов, каждый из которых необходим для выполнения намерения. Я подсказываю каждый слот и определяю все необходимые высказывания.

Теперь я хочу обработать запрос с помощью лямбда-функции. Это моя функция для этого конкретного намерения:

function getData(intentRequest, session, callback) {
    if (intentRequest.dialogState != "COMPLETED"){
        // return a Dialog.Delegate directive with no updatedIntent property.
    } else {
        // do my thing
    }
}

Итак, как я могу продолжить свой ответ с помощью директивы Dialog.Delegate, как указано в документации Alexa?

https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html#scenario-delegate.

Заранее спасибо.


person Ipsider    schedule 07.08.2018    source источник


Ответы (3)


С директивой Dialog.Delegate вы не можете отправлять outputSpeech или reprompt из своего кода. Вместо этого будут использоваться те, которые определены в модели взаимодействия.

Не включайте outputSpeech или reprompt с Dialog.Directive. Alexa использует запросы, определенные в модели диалога, чтобы запросить у пользователя значения слотов и подтверждения.

Это означает, что вы не можете delegate и предоставить свой собственный ответ, но вместо этого вы можете использовать любую другую директиву Dialog для предоставления ваших outputSpeech и reprompt.

Пример: Dialog.ElicitSlot, Dialog.ConfirmSlot и Dialog.ConfirmIntent.

В любой момент вы можете перейти к диалогу, а не продолжать делегировать его Alexa.

...
    const updatedIntent = handlerInput.requestEnvelope.request.intent;
    if (intentRequest.dialogState != "COMPLETED"){
       return handlerInput.responseBuilder
              .addDelegateDirective(updatedIntent)
              .getResponse();
    } else {
        // Once dialoState is completed, do your thing.
        return handlerInput.responseBuilder
              .speak(speechOutput)
              .reprompt(reprompt)
              .getResponse();
    }
...

Параметр updatedIntent в addDelegateDirective() не является обязательным. Это объект намерения, представляющий намерение, направленное на ваш навык. Вы можете использовать это свойство для установки или при необходимости изменить значения слотов и статус подтверждения.

Подробнее о директивах Dialog здесь

person johndoe    schedule 07.08.2018
comment
Отлично спасибо. Я боролся с документацией alexa, это было очень полезно. - person Ipsider; 07.08.2018
comment
@Cicil Я бы порекомендовал вам добавить, как получить currentIntent для справки - person German; 07.09.2018
comment
const currentIntent = handlerInput.requestEnvelope.request.intent - person German; 08.09.2018

В nodejs вы можете использовать

if (this.event.request.dialogState != 'COMPLETED'){
    //your logic
    this.emit(':delegate');
} else {
     this.response.speak(message);
     this.emit(':responseReady');
}
person Charan    schedule 07.08.2018
comment
Спасибо, что помогли разобраться с механикой в ​​работе. - person Ipsider; 07.08.2018
comment
это код v1. ответ от Cicil использует v2, поэтому предпочтительнее - person German; 07.09.2018

В nodeJS мы можем проверить dialogState и действовать соответственно.

if (this.event.request.dialogState === 'STARTED') {
      let updatedIntent = this.event.request.intent;
      this.emit(':delegate', updatedIntent);
} else if (this.event.request.dialogState != 'COMPLETED'){
     if(//logic to elicit slot if any){
          this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech);
     } else {
          this.emit(':delegate');
     }
} else {
     if(this.event.request.intent.confirmationStatus == 'CONFIRMED'){
           //logic for message
           this.response.speak(message);
           this.emit(':responseReady');
     }else{
           this.response.speak("Sure, I will not create any new service request");
           this.emit(':responseReady');
     }
}
person Suneet Patil    schedule 07.08.2018
comment
Спасибо за предоставленный фрагмент кода. Я выбрал другое решение, но оно очень помогло понять эту функциональность elicitSlot. - person Ipsider; 07.08.2018