actions/closeStops.js (view raw)
1const requestTPG = require("../tpgRequest");
2
3const formatData = dataTPG => {
4 const stopsData = dataTPG.data.stops.slice(0, 4);
5 if (!stopsData.length) return null;
6 return {
7 keyboard: stopsData.map(stop => ({
8 label: stop.stopName,
9 })),
10 };
11};
12
13module.exports = (request, response) => {
14 const location = request.content.location;
15 return requestTPG("GetStops", location)
16 .then(dataTPG => {
17 const keyboard = formatData(dataTPG);
18 if (!keyboard)
19 return response.sendText(
20 "Il n'y a aucun arrêt TPG à moins de 500m de cette position"
21 );
22 return response.sendText(
23 "Voilà les arrêts les plus proches de votre position",
24 keyboard
25 );
26 })
27 .catch(error => {
28 console.log({ error });
29 response.sendText(
30 "Désolé, Je ne parviens pas à reconnaître un nom d'arrêt TPG"
31 );
32 });
33};