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 Dec 12, 2018
2 parents ee24ea8 + 6772d60 commit 2211699
Show file tree
Hide file tree
Showing 30 changed files with 290 additions and 734 deletions.
22 changes: 6 additions & 16 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
## Used to authenticate requests to API endpoints provided by this app
GAMBIT_API_KEY=totallysecret

##
## DS Campaigns
##

DS_CAMPAIGNS_API_BASEURI=https://www.dosomething.org/api/v2

##
## DS Activity
##

DS_ROGUE_API_BASEURI=https://activity.dosomething.org/api/v3
GAMBIT_API_KEY=totallysecret

##
## DS Northstar Oauth
## Gateway
##

DS_NORTHSTAR_API_OAUTH_CLIENT_ID=puppet
DS_NORTHSTAR_API_OAUTH_CLIENT_SECRET=totallysecret
DS_NORTHSTAR_API_OAUTH_TOKEN_HOST=https://identity.dosomething.org
DS_NORTHSTAR_API_OAUTH_TOKEN_PATH=/v2/auth/token
DS_NORTHSTAR_API_OAUTH_SCOPES="admin activity write"
DS_ROGUE_API_BASEURI=https://activity.dosomething.org/api/v3

##
## Chatbot content (replies, broadcasts) is created via Contentful.
## Contentful
##

CONTENTFUL_SPACE_ID=puP43Ts70tH
CONTENTFUL_ACCESS_TOKEN=totallysecret
## This is only used for dev or staging environments, to view draft Contentful entries via Preview API.
## The CONTENTFUL_ACCESS_TOKEN value is different depending on whther to use the Preview API or production CDN API.
## The CONTENTFUL_HOST is set for Preview API. The CONTENTFUL_ACCESS_TOKEN value is different depending on whether to use Preview API or production CDN API.
CONTENTFUL_HOST=preview.contentful.com

##
Expand Down
14 changes: 0 additions & 14 deletions config/lib/helpers/command.js

This file was deleted.

14 changes: 1 addition & 13 deletions config/lib/helpers/contentfulEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ const templateFieldTypes = {
transition: 'transition',
};

// Defaults for templates fields that are optional.
const campaignTitleTag = '{{topic.campaign.title}}';
const startCommand = 'START';
const askWhyParticipatedText = `Why was participating in ${campaignTitleTag} important to you? (No need to write an essay, one sentence is good).`;
const completedPhotoPostText = `To submit another post for ${campaignTitleTag}, text ${startCommand}.`;
const invalidInputText = 'Sorry, I didn\'t get that. Text Q if you have a question.';

/**
* This maps the fields in our Contentful types into broadcast, topic, and defaultTopicTriggers.
*
Expand Down Expand Up @@ -117,20 +110,17 @@ module.exports = {
type: 'photoPostConfig',
templates: {
startPhotoPostAutoReply: {
defaultText: `${invalidInputText}\n\nText ${startCommand} when you're ready to submit a post for ${campaignTitleTag}.`,
fieldName: 'invalidSignupMenuCommandMessage',
fieldType: templateFieldTypes.text,
name: 'startPhotoPostAutoReply',
},
completedPhotoPost: {
defaultText: `Thanks for your submission. ${completedPhotoPostText}`,
fieldName: 'completedMenuMessage',
fieldType: templateFieldTypes.text,
name: 'completedPhotoPost',
},
completedPhotoPostAutoReply: {
fieldName: 'invalidCompletedMenuCommandMessage',
defaultText: `${invalidInputText}\n\n${completedPhotoPostText}`,
fieldType: templateFieldTypes.text,
name: 'completedPhotoPostAutoReply',
},
Expand Down Expand Up @@ -161,19 +151,17 @@ module.exports = {
name: 'askCaption',
},
invalidCaption: {
defaultText: `${invalidInputText}\n\nText back a caption for your photo -- keep it short & sweet, under 60 characters please. (but more than 3!)`,
defaultText: 'Sorry, I didn\'t get that. Text Q if you have a question.\n\nText back a caption for your photo -- keep it short & sweet, under 60 characters please. (but more than 3!)',
fieldName: 'invalidCaptionMessage',
fieldType: templateFieldTypes.text,
name: 'invalidCaption',
},
askWhyParticipated: {
defaultText: `Last question: ${askWhyParticipatedText}`,
fieldName: 'askWhyParticipatedMessage',
fieldType: templateFieldTypes.text,
name: 'askWhyParticipated',
},
invalidWhyParticipated: {
defaultText: `${invalidInputText}\n\n${askWhyParticipatedText}`,
fieldName: 'invalidWhyParticipatedMessage',
fieldType: templateFieldTypes.text,
name: 'askWhyParticipated',
Expand Down
7 changes: 0 additions & 7 deletions config/lib/phoenix.js

This file was deleted.

15 changes: 1 addition & 14 deletions documentation/endpoints/broadcasts.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,7 @@ curl http://localhost:5000/v1/broadcasts?skip=20
"createdAt": "2018-08-01T14:41:30.242Z",
"updatedAt": "2018-08-13T13:31:32.583Z",
"postType": "photo",
"campaign": {
"id": 8142,
"title": "Pump It Up",
"tagline": "Print & post our tire flyers to keep friends safe on the road.",
"status": "active",
"currentCampaignRun": {
"id": 8161
},
"endDate": {
"date": "2018-09-30 23:59:00.000000",
"timezone_type": 1,
"timezone": "-04:00"
}
},
"campaign": { ... },
"templates": {
...
}
Expand Down
24 changes: 12 additions & 12 deletions documentation/endpoints/campaigns.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Campaigns

The `campaigns` resource queries the Phoenix API for a campaign, and our Contentful space for chatbot configurations.
The `campaigns` resource queries the Rogue API for a campaign, and our Contentful space for chatbot configurations.


Fields:

Name | Type | Description
-----|------|------------
`id` | Number | The campaign id
`title` | String | The campaign title, available as a `{{title}}` tag within a topic template
`tagline` | String | The campaign tagline, available as a `{{tagline}}` tag within a topic template
`internalTitle` | String | The internal campaign title
`title` | String | To be deprecated (same as `internalTitle`)
`status` | String | Either `'active'` or `'closed'`. Users may not participate in chatbot topics for closed campaigns.
`currentCampaignRun` | Object | Contains a numeric `id` property to be passed when creating a post for the campaign
`startDate` | Date |
`endDate` | Date | Used to determine `status` - if endDate is set and passed, status is `closed`
`config` | Object | The chatbot configuration for this campaign
`config.id` | String | The id of the chatbot configuration
`config.templates` | Object | Message templates defined for the campaign
Expand All @@ -28,7 +29,7 @@ Returns a campaign and its config if set.

Name | Type | Description
-----|------|------------
`cache` | string | If set to `false`, fetches campaign from Phoenix and campaignConfig from Contentful and resets each cache.
`cache` | string | If set to `false`, fetches campaign from Rogue and campaignConfig from Contentful and resets each cache.

<details><summary>**Example Request**</summary><p>

Expand All @@ -45,18 +46,17 @@ curl http://localhost:5000/v1/campaigns/7
```
{
"data": {
"id": 7,
"title": "Mirror Messages",
"tagline": "Boost a stranger's self-esteem with just a sticky note!",
"id": 72332,
"internalTitle": "Mirror Messages Run 87",
"title": "Mirror Messages Run 87",
"startDate": "2018-03-29T00:00:00+00:00",
"endDate": "2029-03-29T00:00:00+00:00",
"status": "active",
"currentCampaignRun": {
"id": 8076
},
"config": {
"id": "68Oy1FcaR2EiaMieicaoom",
"templates": {
"webSignup": {
"text": "Hi this is Freddie from DoSomething! Thanks for signing up for mirror messages. When youve posted some notes and ready to send a photo, text START",
"text": "Hi this is Freddie from DoSomething! Thanks for signing up for Mirror Messages. When you've posted some notes and ready to send a photo, text START",
"attachments": [],
"template": "webSignup",
"topic": {
Expand Down
7 changes: 2 additions & 5 deletions documentation/endpoints/topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ curl http://localhost:5000/v1/topics/6swLaA7HKE8AGI6iQuWk4y?cache=false \
"updatedAt": "2018-11-01T17:06:26.833Z",
"campaign": {
"id": 8190,
"title": "Escape the Vape",
"tagline": "Take this 5-question quiz to learn what's really in e-cigs.",
"internal_title": "Escape the Vape",
"status": "active",
"currentCampaignRun": {
"id": 8191
},
"startDate": "2015-12-16T03:59:00Z",
"endDate": "2018-12-16T03:59:00Z"
},
"templates": {
Expand Down
25 changes: 25 additions & 0 deletions lib/gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const { GatewayClient } = require('@dosomething/gateway/server');

let gatewayClient;

function getClient() {
if (!gatewayClient) {
gatewayClient = GatewayClient.getNewInstance();
}
return gatewayClient;
}

/**
* @param {Number} campaignId
* @return {Promise}
*/
function fetchCampaignById(campaignId) {
return module.exports.getClient().Rogue.Campaigns.get(campaignId);
}

module.exports = {
fetchCampaignById,
getClient,
};
25 changes: 0 additions & 25 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@ Object.keys(helpers).forEach((helperName) => {
module.exports[helperName] = helpers[helperName];
});

/**
* Replaces mustache tags used in raw Campaign Template strings with given variables.
* @param {string} input
* @param {object} campaign
* @return string.
*/
module.exports.replacePhoenixCampaignVars = function (input, campaign) {
if (!input) {
return '';
}

let scope = input;
if (campaign) {
scope = scope.replace(/{{title}}/gi, campaign.title);
scope = scope.replace(/{{tagline}}/i, campaign.tagline);
}

// TODO: Get tags to search for from helpers.command instead of hardcoding here.
// This whole function should be refactored with Mustache and moved into the topic helper.
scope = scope.replace(/{{cmd_reportback}}/i, helpers.command.getStartCommand());
scope = scope.replace(/{{cmd_member_support}}/i, helpers.command.getRequestSupportCommand());

return scope;
};

/**
* Formats given Express response and sends an object including given message, with given code.
* @param {object} res - Express response
Expand Down
Loading

0 comments on commit 2211699

Please sign in to comment.