UNPKG

dcupachatbot

Version:

DCU Personal Assistant chat bot for CA400 project

24 lines (19 loc) 823 B
'use strict'; var request = require('request'); var getBusStopInfo = function getBusStopInfo(stopId, callback) { var url = 'https://data.dublinked.ie/cgi-bin/rtpi/busstopinformation?stopid=' + stopId + '&format=json'; request(url, function (error, response, body) { if (!error && response.statusCode == 200) { var returnedData = JSON.parse(body); var stopid = returnedData.results[0].stopid; var fullname = returnedData.results[0].fullname; var routes = returnedData.results[0].operators.routes; var reply = 'Stop ' + stopid + ' (' + fullname + ') serves routes ' + routes + '.'; callback(reply); } else { // There was an error callback(error); } }); }; module.exports = getBusStopInfo;