Giter VIP home page Giter VIP logo

alexa-bus-schedule's People

Contributors

dustincoates avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

alexa-bus-schedule's Issues

.ZIP file

Do i have to upload whole src folder as a zip or just index.js?

End point couldnt be called

Thanks for your response.

require('dotenv').load();

var http = require('http')
var AlexaSkill = require('./AlexaSkill')
var APP_ID = 'amzn1.ask.skill.c6c6069c-f72b-43a3-8614-9fd48656fbd7';
var MTA_KEY = "86384144-0f02-4256-b58c-e00161fceebb";

var url = function(stopId){
return 'http://bustime.mta.info/api/siri/stop-monitoring.json?key=' + MTA_KEY + '&OperatorRef=MTA&MaximumStopVisits=1&MonitoringRef=' + stopId;
};

var getJsonFromMta = function(stopId, callback){
http.get(url(stopId), function(res){
var body = '';

res.on('data', function(data){
body += data;
});

res.on('end', function(){
var result = JSON.parse(body);
callback(result);
});
}).on('error', function(e){
console.log('Error: ' + e);
});
};

var handleNextBusRequest = function(intent, session, response){
getJsonFromMta(intent.slots.bus.value, function(data){
if(data.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit){
var text = data
.Siri
.ServiceDelivery
.StopMonitoringDelivery[0]
.MonitoredStopVisit[0]
.MonitoredVehicleJourney
.MonitoredCall
.Extensions
.Distances
.PresentableDistance;
var cardText = 'The next bus is: ' + text;
} else {
var text = 'That bus stop does not exist.'
var cardText = text;
}

var heading = 'Next bus for stop: ' + intent.slots.bus.value;
response.tellWithCard(text, heading, cardText);
});
};

var BusSchedule = function(){
AlexaSkill.call(this, APP_ID);
};

BusSchedule.prototype = Object.create(AlexaSkill.prototype);
BusSchedule.prototype.constructor = BusSchedule;

BusSchedule.prototype.eventHandlers.onSessionStarted = function(sessionStartedRequest, session){
// What happens when the session starts? Optional
console.log("onSessionStarted requestId: " + sessionStartedRequest.requestId

  • ", sessionId: " + session.sessionId);
    };

BusSchedule.prototype.eventHandlers.onLaunch = function(launchRequest, session, response){
// This is when they launch the skill but don't specify what they want. Prompt
// them for their bus stop
var output = 'Welcome to Bus Schedule. ' +
'Say the number of a bus stop to get how far the next bus is away.';

var reprompt = 'Which bus stop do you want to find more about?';

response.ask(output, reprompt);

console.log("onLaunch requestId: " + launchRequest.requestId

  • ", sessionId: " + session.sessionId);
    };

BusSchedule.prototype.intentHandlers = {
GetNextBusIntent: function(intent, session, response){
handleNextBusRequest(intent, session, response);
},

HelpIntent: function(intent, session, response){
var speechOutput = 'Get the distance from arrival for any NYC bus stop ID. ' +
'Which bus stop would you like?';
response.ask(speechOutput);
}
};

exports.handler = function(event, context) {
var skill = new BusSchedule();
skill.execute(event, context);
};

I am trying to use your code to learn how this function works, I see that you used three require statements, does those need to be imported in zip file as well? i run this program but it is stating end point couldnt be called. Can you please figure out the bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.