Skip to content

Commit

Permalink
add multiple card deck support
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamq committed Aug 21, 2018
1 parent 0ae2b03 commit 929ba0a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ Deployment version:

### v0.1.0
- Add prep cards

### v0.1.1
- Allow multiple card decks
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cognicity-reports-facebook",
"version": "0.1.0",
"version": "0.1.1",
"description": "Facebook Messenger bot running on AWS lambda",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
BLACKLIST: (process.env.BLACKLIST || '').split(','),
CARDS_API: process.env.CARDS_API || 'https://data.riskmap.us/cards/',
CARDS_API_KEY: process.env.CARDS_API_KEY,
CARDS_DECK: (process.env.CARDS_DECK || 'flood' ).split(','),
CARDS_URL: process.env.CARDS_URL || 'https://cards.riskmap.us/flood/',
PREP_URL: process.env.PREP_URL || 'https://cards.riskmap.us/prep/',
DEFAULT_INSTANCE_COUNTRY_CODE: process.env.DEFAULT_INSTANCE_COUNTRY_CODE || 'us',
Expand Down
46 changes: 29 additions & 17 deletions src/lib/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ export default class Facebook {
* @return {Object} - Request object
**/
_prepareCardResponse(properties) {
const floodButton = {
type: 'web_url',
title: buttons[properties.language].text.report,
url: properties.message.link,
};

const prepButton = {
type: 'web_url',
title: buttons[properties.language].text.prep,
url: properties.message.prepLink,
};

const mapViewButton = {
type: 'web_url',
url: this.config.MAP_URL,
title: buttons[properties.language].text.map,
};

let customButtons = [];
if (this.config.CARDS_DECK.indexOf('flood') >= 0) {
customButtons.push(floodButton);
}

if (this.config.CARDS_DECK.indexOf('prep') >= 0) {
customButtons.push(prepButton);
}
// always push the view map button
customButtons.push(mapViewButton);
const body = {
recipient: {
id: properties.userId,
Expand All @@ -45,23 +73,7 @@ export default class Facebook {
payload: {
template_type: 'button',
text: properties.message.text,
buttons: [
{
type: 'web_url',
title: buttons[properties.language].text.report,
url: properties.message.link,
},
{
type: 'web_url',
title: buttons[properties.language].text.prep,
url: properties.message.prepLink,
},
{
type: 'web_url',
url: this.config.MAP_URL,
title: buttons[properties.language].text.map,
},
],
buttons: customButtons,
},
},
},
Expand Down

0 comments on commit 929ba0a

Please sign in to comment.