首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >alexa中的CanfulFillIntentRequest没有响应

alexa中的CanfulFillIntentRequest没有响应
EN

Stack Overflow用户
提问于 2018-10-12 13:29:02
回答 1查看 632关注 0票数 0

代码语言:javascript
复制
const HelloWorldIntentHandler = {
  canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'CanFulfillIntentRequest'

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

代码语言:javascript
复制
const MynameHandler = {
  
    handle(handlerInput) {
    
    const speechText = 'ALex';
    const repromtText = 'Please respond';
 return handlerInput.responseBuilder 
 .speak(speechText)
.withCanFulfillIntent( 
    {
        "canFulfill":"YES",
 
    })
.getResponse();

}

};

代码语言:javascript
复制
{
  "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

这是我的响应处理程序。

代码语言:javascript
复制
return handlerInput.responseBuilder
      .withCanFulfillIntent(
        {
          'canFulfill': 'MAYBE',
          'slots':{

              }
        })
        .getResponse();
    }

代码语言:javascript
复制
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请求,并且被重定向到错误处理程序代码。

EN

回答 1

Stack Overflow用户

发布于 2018-10-15 20:56:16

withCanFulfillIntent()响应构建器帮助器方法仅在 中可用

通过以下方式安装公共测试版

代码语言:javascript
复制
npm install --save ask-sdk-model@beta
npm install --save ask-sdk-core@beta

或者在package.json中使用它

代码语言:javascript
复制
"dependencies": {
    "ask-sdk-core": "^2.1.0-beta.1",
    "ask-sdk-model": "^1.4.0-beta.1"
  }

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

代码语言:javascript
复制
{
  "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"
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52772843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档