【问题标题】:No response from CanfulFillIntentRequest in alexaAlexa 中的 CanfulFillIntentRequest 没有响应
【发布时间】:2018-10-12 05:29:01
【问题描述】:

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 请求并被重定向到错误处理程序代码。

【问题讨论】:

  • 请求负载是什么?
  • 它的 CanFulfillIntent 请求
  • 共享请求负载以及 canHandle() 函数。
  • 如果您将其放在评论中,则很难阅读。更新原始问题中的内容,使其可读。
  • 我更新了问题

标签: node.js alexa alexa-skills-kit alexa-sdk-nodejs


【解决方案1】:

withCanFulfillIntent() 响应构建器辅助方法仅在 ASK SDK for Node.js (Public Beta) 中可用

安装公测版

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"
  }

我用 beta 测试了你的代码并得到了预期的结果:

{
  "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"
  }
}

【讨论】:

  • 您好,我通过手动 JSON 进行了测试,并且成功了。现在,我如何使用 echo dot 设备进行检查。我如何知道我的技能是否被调用?我还有什么需要做的吗?我的技能目前处于开发阶段,我需要发布我的技能吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-13
  • 2020-07-21
  • 1970-01-01
  • 2021-04-18
  • 1970-01-01
  • 2018-09-30
  • 1970-01-01
相关资源
最近更新 更多