dustincoates / alexa-bus-schedule Goto Github PK
View Code? Open in Web Editor NEWAn Amazon Echo Skill that gets the distance away from a given stop for a New York City bus.
An Amazon Echo Skill that gets the distance away from a given stop for a New York City bus.
Do i have to upload whole src folder as a zip or just index.js?
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
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.