Notify user when to book uber to reach destination on time. :)
In your node.js project, run:
npm install --save zunzuna
Run in your terminal:
node examples/template.js
NOTE: set GOOGLE_API_KEY & UBER_API_KEY environment variables
NOTE: update event.time
const Zunzuna = require('zunzuna');
const zunzuna = new Zunzuna();
const event = {
"id" : "1234",
"source": "Bengaluru Airport",
"destination": "Soul Space Spirit, Bengaluru",
"time": "2016-05-04T02:33:17+05:30",
"emailid": "[email protected]"
};
try {
zunzuna.createEvent(event);
} catch (e) {
console.log("Error occured: " + e.message);
}
zunzuna.on('notify', (params) => {
console.log(params);
});
node examples/messenger.js
Special Thanks to node-wit
####Messenger API integration with wit.ai and zunzuna
We assume you have:
- a Wit.ai bot setup (https://wit.ai/docs/quickstart)
- a Messenger Platform setup (https://developers.facebook.com/docs/messenger-platform/quickstart)
You need to npm install
the following dependencies: body-parser, express, request, node-wit, zunzuna
-
npm install body-parser express request node-wit zunzuna
-
Download and install ngrok from https://ngrok.com/download
-
./ngrok -http 8080
-
set following environment variables
WIT_TOKEN=your_access_token
FB_PAGE_ID=your_page_id
FB_PAGE_TOKEN=your_page_token
FB_VERIFY_TOKEN=verify_token
GOOGLE_API_KEY=your_google_api_key
UBER_API_KEY=your_uber_api_key
PORT=8080
-
Subscribe your page to the Webhooks using verify_token and
https://<your_ngrok_io>/fb
as callback URL. -
Talk to your bot on Messenger!
-
You need to define the sories to get the appropriate context from wit.ai
For now you can use these wit.ai stories
For windows users, set the environment variables using settoken.bat
file and run settoken.bat
on cmd prompt
- Get at the source (event.source), destination (event.destination), travel start time (event.startTravelAt) and email id (event.email) of an user event (event).
- Fetch the total travel time (travelTime) to destination (destination) at this instance (event.requestedAt).
- Set the maximum travel time (maxTravelTime) to (travelTime + maxDeviationToTravelTime = 60 mins )
- Set the maximum buffer time (maxBufferTime = 10 mins)
- Set the maximum time for the uber to reach source (maxWaitingTime = 15 mins)
- Calculate the best time to send a notification to user for booking cab (sendNotificationAt())
- Calculate the best time to fetch travel time from source to destination (getTravelTimeAt())
- set event.updateTravelTimeAt to currentTime and fetch the event.travelTime
- Calculate maxTravelTime = event.travelTime @ event.requestedAt + maxDeviationToTravelTime
- set event.updateTravelTimeAt to [event.startTravelAt - (maxBufferTime + maxTravelTime + maxWaitingTime)]
- set event.notificationTime to [event.startTravelAt - (maxBufferTime + event.travelTime + maxWaitingTime)]
- If the event.updateTravelTimeAt matches to currentTime, getTravelTime() [i.e update event.travelTime] and update event.notificationTime and calculate event.updateTravelTimeAt.
- If the event.udpateWaitingTimeAt matches to currentTIme, getWaitingTime() [i.e update event.waitingTime] and update event.notificationTime and calculate event.updateWaitingTime.
- If event.notificationTime matches to currentTime, send notification.
- Google api polling will start at (maxTravelTime + maxWaitingTime + maxBufferTime)
- Uber api polling will start at (notificationTime - startUberPolling)
- Google api polling stops 5 mins prior to notificationTime
- Uber api polls every 2 mins till the notificationTime
- NOTE: Values can be changed from node_modules/zunzuna/lib/algo.js file