Node.js Alexa测试响应不包含outputSpeech

Node.js Alexa测试响应不包含outputSpeech,node.js,npm,alexa,alexa-skill,Node.js,Npm,Alexa,Alexa Skill,我是Alexa的新手,我学习了airportinfo教程,从github复制了代码,当我使用npm测试它并输入机场代码(如SFO)时,没有“outputSpeech:”我试着用同样的问题使用类似的技巧,我不确定我做错了什么。我有index.js和FAADataInfo.js,提前感谢您的帮助 这是index.js文件 'use strict'; module.change_code = 1; var _ = require('lodash'); var Alexa = require('alex

我是Alexa的新手,我学习了airportinfo教程,从github复制了代码,当我使用npm测试它并输入机场代码(如SFO)时,没有“outputSpeech:”我试着用同样的问题使用类似的技巧,我不确定我做错了什么。我有index.js和FAADataInfo.js,提前感谢您的帮助

这是index.js文件

'use strict';
module.change_code = 1;
var _ = require('lodash');
var Alexa = require('alexa-app');
var skill = new Alexa.app('airportinfo');
var FAADataHelper = require('./faa_data_helper');

skill.launch(function(req, res) {
  var prompt = 'For delay information, tell me an Airport code.';
  res.say(prompt).reprompt(prompt).shouldEndSession(false);
});

skill.intent('airportInfoIntent', {
    'slots': {
      'AIRPORTCODE': 'FAACODES'
    },
    'utterances': [
      '{|flight|airport} {|delay|status} {|info} {|for} {-|AIRPORTCODE}'
    ]
  },
  function(req, res) {
    var airportCode = req.slot('AIRPORTCODE');
    var reprompt = 'Tell me an airport code to get delay information.';
    if (_.isEmpty(airportCode)) {
      var prompt = 'I didn\'t hear an airport code. Tell me an airport code.';
      res.say(prompt).reprompt(reprompt).shouldEndSession(false);
      return true;
    } else {
      var faaHelper = new FAADataHelper();
      console.log(airportCode);
      faaHelper.getAirportStatus(airportCode).then(function(airportStatus) {
        console.log(airportStatus);
        res.say(faaHelper.formatAirportStatus(airportStatus)).send();
      }).catch(function(err) {
        console.log(err.statusCode);
        var prompt = 'I didn\'t have data for an airport code of ' +
          airportCode;
        res.say(prompt).reprompt(reprompt).shouldEndSession(false).send();
      });
      return false;
    }
  }
);
module.exports = skill;
这里是FAADataInfo.js

    'use strict';
var _ = require('lodash');
var requestPromise = require('request-promise');
var ENDPOINT = 'http://services.faa.gov/airport/status/';

function FAADataHelper() {
}

FAADataHelper.prototype.getAirportStatus = function(airportCode) {
  var options = {
    method: 'GET',
    uri: ENDPOINT + airportCode,
    json: true
  };
  return requestPromise(options);
};

FAADataHelper.prototype.formatAirportStatus = function(aiportStatusObject) {
  if (aiportStatusObject.delay === 'true') {
    var template = _.template('There is currently a delay for ${airport}. ' +
      'The average delay time is ${delay_time}.');
    return template({
      airport: aiportStatusObject.name,
      delay_time: aiportStatusObject.status.avgDelay
    });
  } else {
    //no delay
    var template =_.template('There is currently no delay at ${airport}.');
    return template({
      airport: aiportStatusObject.name
    });
  }
};

module.exports = FAADataHelper;
这就是我得到的回应

{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true
  },
  "sessionAttributes": {},
  "dummy": "text"
}

教程使用的alexa应用程序版本已过期。使用最新的alexa app npm版本(4.0.0)时,.intent()函数的返回值应为承诺值,而不是布尔值(如果运行异步函数)

在index.js中,添加:

返回faaHelper.getAirportStatus(..){}.catch(){}

并删除
返回false在捕获之后

下面是完整的skill.intent()代码


我会这么做,但我不知道程序的哪一部分不起作用,所以我不知道如何简化它以解决问题,我能做一个hello world技能你需要展示你是如何获得数据的,以及你后来做了什么,我现在查一下。airportStatus是如何设置的?或者我可以为其指定任何名称吗?调用FAADataHelper.prototype.getAirportStatus()时,airportStatus在FAADataInfo.js类中设置。这将进行API调用,并将返回的JSON值设置为airportStatus变量。
skill.intent('airportInfoIntent', {
    'slots': {
      'AIRPORTCODE': 'FAACODES'
    },
    'utterances': [
      '{|flight|airport} {|delay|status} {|info} {|for} {-|AIRPORTCODE}'
    ]
  },
  function(req, res) {
    var airportCode = req.slot('AIRPORTCODE');
    var reprompt = 'Tell me an airport code to get delay information.';
    if (_.isEmpty(airportCode)) {
      var prompt = 'I didn\'t hear an airport code. Tell me an airport code.';
      res.say(prompt).reprompt(reprompt).shouldEndSession(false);
      return true;
    } else {
      var faaHelper = new FAADataHelper();
      console.log(airportCode);

      return faaHelper.getAirportStatus(airportCode).then(function(airportStatus) {
        console.log(airportStatus);
        res.say(faaHelper.formatAirportStatus(airportStatus)).send();
      }).catch(function(err) {
        console.log(err.statusCode);
        var prompt = 'I didn\'t have data for an airport code of ' +
          airportCode;
        res.say(prompt).reprompt(reprompt).shouldEndSession(false).send();
      });
      //return false;
    }
  }
);