-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: update sign off message * feat: list upcoming events addresses part of #28
- Loading branch information
1 parent
732916e
commit fa81aaf
Showing
4 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const isURL = require('validator/lib/isURL'); | ||
const firebase = require('../storage/firebase'); | ||
|
||
// // common functions | ||
const utils = { | ||
validArray(data) { | ||
return Array.isArray(data) && data.length > 0; | ||
}, | ||
currentTimestamp() { | ||
return Math.floor(new Date().getTime() / 1000); | ||
}, | ||
}; | ||
|
||
const getEventsElems = (events) => { | ||
const elems = []; | ||
events.forEach((event) => { | ||
const elem = { | ||
title: event.title, | ||
image_url: isURL(String(event.cover_img)) ? String(event.cover_img) : process.env.DEFAULT_EVENT_IMG, | ||
subtitle: event.description, | ||
buttons: [ | ||
{ | ||
type: 'web_url', | ||
url: isURL(String(event.url)) ? String(event.url) : process.env.FACEBOOK_GROUP_URL, | ||
title: 'View Event', | ||
}, | ||
{ | ||
type: 'postback', | ||
title: '♡ Interested', | ||
payload: `event:interest:${event.timestamp}`, | ||
}, | ||
], | ||
}; | ||
elems.push(elem); | ||
}); | ||
return elems; | ||
}; | ||
|
||
const upcomingEvents = (payload, chat) => { | ||
firebase.listEvents(null, (data) => { | ||
if (utils.validArray(data)) { | ||
const elems = getEventsElems(data); | ||
chat.sendGenericTemplate(elems); | ||
} | ||
else { | ||
chat.say('No events to display'); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
upcomingEvents, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters