diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e60498..28ffbf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,3 +22,6 @@ Deployment version: ### v0.1.0 - Add prep cards + +### v0.1.1 +- Allow multiple card decks diff --git a/package-lock.json b/package-lock.json index 8a523c1..cf4dbae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cognicity-reports-facebook", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 008c98e..46cbd24 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/config.js b/src/config.js index c1e0e09..b0e9285 100644 --- a/src/config.js +++ b/src/config.js @@ -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', diff --git a/src/lib/facebook.js b/src/lib/facebook.js index 710a051..45935ac 100644 --- a/src/lib/facebook.js +++ b/src/lib/facebook.js @@ -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, @@ -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, }, }, },