Alexa 测试响应不包含 outputSpeech

Alexa Test Response does not contain outputSpeech

我是 Alexa 的新手,已经按照机场信息教程进行操作,我已经从 github https://github.com/bignerdranch/alexa-airportinfo 复制了代码,当我使用 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-app 版本已过期。使用最新的 alexa-app npm 版本 (4.0.0) 时,如果您是 运行 异步函数,.intent() 函数的 return 值应该是 Promise 而不是布尔值。

在您的 index.js 中,添加:

return faaHelper.getAirportStatus(....) {}.catch(){}

并删除 catch 后的 return false;

这是完整的 skill.intent() 代码

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;
    }
  }
);