Нет ответа от CanfulFillIntentRequest в alexa - PullRequest
0 голосов
/ 12 октября 2018

const HelloWorldIntentHandler = {
  canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'CanFulfillIntentRequest'

  },
  handle(handlerInput) {
    if(handlerInput.requestEnvelope.request.intent.name === 'Myname'){
    return MynameHandler.handle(handlerInput);
      
  }

const MynameHandler = {
  
    handle(handlerInput) {
    
    const speechText = 'ALex';
    const repromtText = 'Please respond';
 return handlerInput.responseBuilder 
 .speak(speechText)
.withCanFulfillIntent( 
    {
        "canFulfill":"YES",
 
    })
.getResponse();

}

};

{
  "session":{
    "new": true,
    "sessionId":"SessionId.<My Session id>",
    "application":{
      "applicationId":"amzn1.ask.skill.<Application id>"
    },
    "attributes":{
      "key": "string value"
    },
    "user":{
      "userId":"amzn1.ask.account.<user id>
    }
  },
  "request":{
    "type":"CanFulfillIntentRequest",
    "requestId":"EdwRequestId.<request id>",
    "intent":{
      "name":"Myname"
    },
    "locale":"en-US",
    "timestamp":"2018-10-12T09:36:31Z"
  },
  "context":{
    "AudioPlayer":{
      "playerActivity":"IDLE"
    },
    "System":{
      "application":{
        "applicationId":"amzn1.ask.skill.<application id>"
      },
      "user":{
        "userId":"amzn1.ask.account.<user id>"
      },
      "device":{
        "supportedInterfaces":{

        }
      }
    }
  },
  "version":"1.0"
}

Я применяю CanfulFillIntentRequest в течение многих дней, но пока не повезло.Я использую alexa-sdk-nodejs v2.Я не могу построить ответ для CanfulFillIntent.Я попытался реализовать это точно, как указано в этих документах.https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html
https://developer.amazon.com/docs/custom-skills/implement-canfulfillintentrequest-for-name-free-interaction.html.

Это мой обработчик ответа.

return handlerInput.responseBuilder
      .withCanFulfillIntent(
        {
          'canFulfill': 'MAYBE',
          'slots':{

              }
        })
        .getResponse();
    }

const HelloWorldIntentHandler = {
  canHandle(handlerInput) {
    //return handlerInput.requestEnvelope.request.type === 'IntentRequest' || 'CanFulfillIntentRequest'
return handlerInput.requestEnvelope.request.type === 'CanFulfillIntentRequest'
     // && handlerInput.requestEnvelope.request.intent.name === 'Myname' || 'HotelIntent';
  },
  handle(handlerInput) {
    if(handlerInput.requestEnvelope.request.intent.name === 'Myname'){
    return MynameHandler.handle(handlerInput);
      
  }
  };

Когда я запускаю код JSON в ручном JSON, он не отвечает на запрос CanfulFillIntent и перенаправляется на код обработчика ошибок.

1 Ответ

0 голосов
/ 15 октября 2018

Вспомогательный метод построения ответов withCanFulfillIntent() доступен только в ASK SDK для Node.js (общедоступная бета-версия)

Установка общедоступной бета-версии

npm install --save ask-sdk-model@beta
npm install --save ask-sdk-core@beta

или используйте это в package.json

"dependencies": {
    "ask-sdk-core": "^2.1.0-beta.1",
    "ask-sdk-model": "^1.4.0-beta.1"
  }

Я попробовал ваш код с бета-версией и получил ожидаемые результаты:

{
  "version": "1.0",
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>ALex</speak>"
    },
    "reprompt": {
      "outputSpeech": {
        "type": "SSML",
        "ssml": "<speak>Please respond</speak>"
      }
    },
    "shouldEndSession": false,
    "canFulfillIntent": {
      "canFulfill": "YES"
    }
  },
  "userAgent": "ask-node/2.1.0-beta.4 Node/v8.10.0",
  "sessionAttributes": {
    "key": "string value"
  }
}
...