Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronschachter committed Aug 9, 2018
2 parents 8329828 + d017d0c commit 25cbeb9
Show file tree
Hide file tree
Showing 32 changed files with 1,777 additions and 2,711 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.11.1
8.11.3
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
'use strict';

const config = require('./config');
const express = require('express');
const favicon = require('serve-favicon');
const path = require('path');
const bodyParser = require('body-parser');

const app = express();
/**
* Set app locals
* @see https://expressjs.com/en/4x/api.html#app.locals
*/
app.locals.forceHttps = config.forceHttps;

// serve favicon
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
// parse application/json Content-Type
Expand Down
4 changes: 4 additions & 0 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const statusRoute = require('./status');
const authenticateConfig = require('../../config/lib/middleware/authenticate');

// middleware
const enforceHttpsMiddleware = require('../../lib/middleware/enforce-https');
const timeoutMiddleware = require('../../lib/middleware/timeouts');
const authenticateMiddleware = require('../../lib/middleware/authenticate');

function regGlobalMiddleware(app) {
// Enforce https
app.use(enforceHttpsMiddleware(app.locals.forceHttps));

// 504 timeouts middleware
Object.keys(timeoutMiddleware).forEach((name) => {
app.use(timeoutMiddleware[name]);
Expand Down
7 changes: 7 additions & 0 deletions config/env/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const configVars = {
forceHttps: true,
};

module.exports = configVars;
7 changes: 7 additions & 0 deletions config/env/thor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const configVars = {
forceHttps: true,
};

module.exports = configVars;
2 changes: 2 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const defaultConfig = {
webConcurrency: process.env.WEB_CONCURRENCY || 1,
dbUri: process.env.DB_URI || 'mongodb://localhost/ds-mdata-responder',
apiKey: process.env.GAMBIT_API_KEY || 'totallysecret',
// overridden in production to true
forceHttps: false,
};

const configVars = underscore.extend({}, defaultConfig, envConfig);
Expand Down
24 changes: 0 additions & 24 deletions config/lib/helpers/broadcast.js

This file was deleted.

68 changes: 68 additions & 0 deletions config/lib/helpers/contentfulEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

/**
* This maps the fields in our Contentful types into broadcast, topic, and defaultTopicTriggers.
*
* Content types with either a templates or postType property set are returned as topics.
* If the type contains a templates array, each array item should correspond to a single value text
* field defined on the content type, which is used as a bot reply template in the topic.
* If the type contains a postType string property instead, its an older content type and its
* templates are configured via config/lib/helpers/topic. Ideally we should consolidate, but it'd
* take a bit of refactoring as the topic helper config contains default values for certain text
* fields to use if the field values are blank.
*
* A broadcastable content type currently requires a text field named "text" and attachments field
* named "attachments" to define content for the outbound broadcast.
*
*/
module.exports = {
contentTypes: {
askYesNo: {
type: 'askYesNo',
broadcastable: true,
templates: [
'saidYes',
'saidNo',
'invalidAskYesNoResponse',
'autoReply',
],
},
autoReply: {
type: 'autoReply',
templates: [
'autoReply',
],
},
autoReplyBroadcast: {
type: 'autoReplyBroadcast',
broadcastable: true,
},
defaultTopicTrigger: {
type: 'defaultTopicTrigger',
},
message: {
type: 'message',
},
photoPostConfig: {
type: 'photoPostConfig',
postType: 'photo',
},
textPostConfig: {
type: 'textPostConfig',
postType: 'text',
},
// Legacy types:
// Ideally we'd backfill all legacy entries as their new types, but we likely can't change the
// the type of a Contentful entry without changing its id (if that's the case - we'd need to
// bulk update all documents in the Conversations messages DB)
// This externalPostConfig type will deprecated by an autoReply:
externalPostConfig: {
type: 'externalPostConfig',
postType: 'external',
},
legacyBroadcast: {
type: 'broadcast',
broadcastable: true,
},
},
};
3 changes: 0 additions & 3 deletions config/lib/helpers/defaultTopicTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@

module.exports = {
allDefaultTopicTriggersCacheKey: 'all',
contentTypes: [
'defaultTopicTrigger',
],
};
30 changes: 0 additions & 30 deletions config/lib/helpers/topic.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
'use strict';

// @see documentation/endpoints/topics
const contentTypes = {
askChangeTopicBroadcast: {
type: 'askChangeTopicBroadcast',
isBroadcast: true,
postType: null,
},
autoReplyBroadcast: {
type: 'autoReplyBroadcast',
isBroadcast: true,
postType: null,
},
externalPostConfig: {
type: 'externalPostConfig',
isBroadcast: false,
postType: 'external',
},
photoPostConfig: {
type: 'photoPostConfig',
isBroadcast: false,
postType: 'photo',
},
textPostConfig: {
type: 'textPostConfig',
isBroadcast: false,
postType: 'text',
},
};

const defaultText = {
declined: 'Text MENU if you\'d like to find a different action to take.',
invalidInput: 'Sorry, I didn\'t get that.',
Expand All @@ -49,7 +20,6 @@ const photoPostDefaultText = {

module.exports = {
allTopicsCacheKey: 'all',
contentTypes,
defaultPostType: 'photo',
/*
* Maps each content type with a map of templateNames and its corresponding field name and
Expand Down
51 changes: 38 additions & 13 deletions documentation/endpoints/broadcasts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ Name | Type | Description
-----|------|------------
`id` | String | The Contentful entry id
`name` | String | Internal name used to reference the broadcast
`type` | String | The Contentful entry type, e.g. `autoReplyBroadcast`, `broadcast`
`type` | String | The Contentful entry type, e.g. `askYesNo`, `autoReplyBroadcast`, `broadcast`
`message` | Object | Contains the [outbound message content](https://github.com/DoSomething/gambit-conversations/blob/master/documentation/endpoints/messages.md) to send to user
`message.text` | String |
`message.attachments` | Array |
`message.template` | String |
`topic` | String | If set, updates the conversation topic to this string.*
`campaignId` | Number | If set, updates the conversation topic to the given campaign's topic.*
`message.topic` | Object | If an id property exists, its saved to the [conversation topic](https://github.com/DoSomething/gambit-campaigns/blob/master/documentation/endpoints/topics.md) when broadcast is sent
`templates` | Object | Defines replies for when this broadcast is saved as a [conversation topic](https://github.com/DoSomething/gambit-campaigns/blob/master/documentation/endpoints/topics.md) -- used in `askYesNo`, which will update the conversation topic again if user answers yes

Legacy fields (only used for type `broadcast`)

Name | Type | Description
-----|------|------------
`topic` | String | (Legacy) If set, updates the conversation topic to this string.*
`campaignId` | Number | (Legacy) If set, updates the conversation topic to the given campaign's topic.*

* Note: These fields will likely be deprecated by a `topicId` per https://www.pivotaltracker.com/story/show/157369418


## Retrieve broadcasts
Expand Down Expand Up @@ -64,18 +70,37 @@ curl http://localhost:5000/v1/broadcasts?skip=20
"topic": "survey_response"
},
{
"id": "4C2gkDV8oUAaewSMYeokEC",
"name": "VoterRegistration2018_Jul8_OhioSpecialHouseGeneralReminder",
"type": "broadcast",
"createdAt": "2018-07-06T18:28:51.478Z",
"updatedAt": "2018-07-06T18:31:55.968Z",
"id": "2X4r3fZrTGA2mGemowgiEI",
"name": "askYesNo test",
"type": "askYesNo",
"createdAt": "2018-08-06T23:34:56.395Z",
"updatedAt": "2018-08-08T22:20:14.822Z",
"message": {
"text": "It's Freddie! Guess what -- Ohio needs YOU. Voters have the power to make a huge difference in your state, so make sure you're registered to vote in Ohio's special house general election before tonight's deadline! It takes just 2 mins: https://vote.dosomething.org/?r=user:{{user.id}},campaignID:8017,campaignRunID:8022,source:sms,source_details:broadcastID_4C2gkDV8oUAaewSMYeokEC",
"text": "Join Pump it Up? \n\nYes No",
"attachments": [],
"template": "rivescript"
"template": "askYesNo",
"topic": {}
},
"templates": {
"saidYes": {
"text": "Great! Text START to submit a photo.",
"topic": {
"id": "4xXe9sQqmIeiWauSUu6kAY"
}
},
"saidNo": {
"text": "Ok, we'll check in with you later.",
"topic": {}
},
"invalidAskYesNoResponse": {
"text": "Sorry, I didn't get that - did you want to join for Pump It Up? Yes or No",
"topic": {}
},
"autoReply": {
"text": "Sorry, I didn't understand that. Text Q if you have a question.",
"topic": {}
}
},
"campaignId": null,
"topic": "survey_response"
},
...
},
Expand Down
Loading

0 comments on commit 25cbeb9

Please sign in to comment.