Skip to content

Commit

Permalink
upgrade node version to 10.x and twilio
Browse files Browse the repository at this point in the history
  • Loading branch information
schuyler1d committed Mar 9, 2020
1 parent 6d8e644 commit 4d8b899
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.3
10
2 changes: 1 addition & 1 deletion docs/DEPLOYING_AWS_LAMBDA.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Create an RDS instance running Postgres 10.4 with the following settings:

### Configure Deploy Environment

1. First make sure you are running node 10.3 (compatible with AWS Lambda) `nvm install 10.3; nvm use`
1. First make sure you are running node 10.x (compatible with AWS Lambda) `nvm install 10; nvm use`
2. Install Claudia js: `npm install -g claudia`
3. Create an admin user on AWS selecting programmatic access. Add that profile to `~/.aws/credentials` giving it a nickname to use later in shell commands:
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"rollbar": "^0.6.2",
"thinky": "^2.3.3",
"timezonecomplete": "^5.5.0",
"twilio": "^2.11.0",
"twilio": "^3.40.0",
"uuid": "^3.1.0",
"wait-for-expect": "^1.1.1",
"webpack": "^3.8.1",
Expand Down
5 changes: 4 additions & 1 deletion src/server/api/lib/twilio.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const DISABLE_DB_LOG = process.env.DISABLE_DB_LOG || global.DISABLE_DB_LOG;

if (process.env.TWILIO_API_KEY && process.env.TWILIO_AUTH_TOKEN) {
// eslint-disable-next-line new-cap
twilio = Twilio(process.env.TWILIO_API_KEY, process.env.TWILIO_AUTH_TOKEN);
twilio = new Twilio(
process.env.TWILIO_API_KEY,
process.env.TWILIO_AUTH_TOKEN
);
} else {
log.warn("NO TWILIO CONNECTION");
}
Expand Down
58 changes: 30 additions & 28 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import nexmo from "./api/lib/nexmo";
import twilio from "./api/lib/twilio";
import { seedZipCodes } from "./seeds/seed-zip-codes";
import { setupUserNotificationObservers } from "./notifications";
import { TwimlResponse } from "twilio";
import { twiml } from "twilio";
import { existsSync } from "fs";
import { rawAllMethods } from "../integrations/contact-loaders";

Expand Down Expand Up @@ -103,19 +103,6 @@ Object.keys(configuredIngestMethods).forEach(ingestMethodName => {
}
});

app.post(
"/nexmo",
wrap(async (req, res) => {
try {
const messageId = await nexmo.handleIncomingMessage(req.body);
res.send(messageId);
} catch (ex) {
log.error(ex);
res.send("done");
}
})
);

app.post(
"/twilio",
twilio.webhook(),
Expand All @@ -126,24 +113,39 @@ app.post(
log.error(ex);
}

const resp = new TwimlResponse();
const resp = new twiml.MessagingResponse();
res.writeHead(200, { "Content-Type": "text/xml" });
res.end(resp.toString());
})
);

app.post(
"/nexmo-message-report",
wrap(async (req, res) => {
try {
const body = req.body;
await nexmo.handleDeliveryReport(body);
} catch (ex) {
log.error(ex);
}
res.send("done");
})
);
if (process.env.NEXMO_API_KEY) {
app.post(
"/nexmo",
wrap(async (req, res) => {
try {
const messageId = await nexmo.handleIncomingMessage(req.body);
res.send(messageId);
} catch (ex) {
log.error(ex);
res.send("done");
}
})
);

app.post(
"/nexmo-message-report",
wrap(async (req, res) => {
try {
const body = req.body;
await nexmo.handleDeliveryReport(body);
} catch (ex) {
log.error(ex);
}
res.send("done");
})
);
}

app.post(
"/twilio-message-report",
Expand All @@ -154,7 +156,7 @@ app.post(
} catch (ex) {
log.error(ex);
}
const resp = new TwimlResponse();
const resp = new twiml.MessagingResponse();
res.writeHead(200, { "Content-Type": "text/xml" });
res.end(resp.toString());
})
Expand Down
Loading

0 comments on commit 4d8b899

Please sign in to comment.