0

I'm new to Alexa, and have followed the airportinfo tutorial and I have copied the code from github https://github.com/bignerdranch/alexa-airportinfo and when i test it using npm and input an airport code e.g. SFO, Theres no "outputSpeech:" and i tried making a similar skill with the same issue, I'm not sure what I'm doing wrong. I have both index.js and FAADataInfo.js Thanks in advance for your help.

This is the index.js file

'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;

and heres 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;

This is the response that I get

{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true
  },
  "sessionAttributes": {},
  "dummy": "text"
}
james
  • 101
  • 1
  • 8
  • http://stackoverflow.com/help/mcve – Rob Apr 10 '17 at 11:51
  • I would do that but i dont know what part of the program isnt working so I dont know how to simplify it to still have the problem, I'm able to make a hello world skill – james Apr 10 '17 at 11:58
  • You need to show how you obtained that data and what you did with it afterwards. – Rob Apr 10 '17 at 12:01
  • well the two files are linked to git ill put the code here though Thanks :) – james Apr 10 '17 at 19:11

1 Answers1

0

The alexa-app version that the tutorial is using is out of date. When using the latest alexa-app npm version (4.0.0), the return value for the .intent() function should be a Promise and not a boolean if you are running asynchronous functions.

In your index.js, add:

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

and remove the return false; after the catch.

Here's the full skill.intent() code

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;
    }
  }
);
  • Thanks, Ill check that now. How does airportStatus get set though? or can i assign whatever name I want to it? – james May 02 '17 at 07:28
  • The airportStatus is set in your FAADataInfo.js class when you call FAADataHelper.prototype.getAirportStatus(). This makes the API call and sets the returning JSON value to the airportStatus variable. – Ronnie Rocha May 02 '17 at 19:57