-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7adce37
commit 948af16
Showing
23 changed files
with
1,151 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# test directories | ||
__tests__ | ||
test | ||
tests | ||
powered-test | ||
|
||
# asset directories | ||
docs | ||
doc | ||
website | ||
images | ||
assets | ||
|
||
# examples | ||
example | ||
examples | ||
|
||
# code coverage directories | ||
coverage | ||
.nyc_output | ||
|
||
# build scripts | ||
Makefile | ||
Gulpfile.js | ||
Gruntfile.js | ||
|
||
# configs | ||
.tern-project | ||
.gitattributes | ||
.editorconfig | ||
.*ignore | ||
.eslintrc | ||
.jshintrc | ||
.flowconfig | ||
.documentup.json | ||
.yarn-metadata.json | ||
.*.yml | ||
*.yml | ||
|
||
# misc | ||
*.gz | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Thank you for previously completing the Watch Me Grow app. It is recommended that you complete this when your child is aged | ||
approximately 12, 18 and 24 months. This is a reminder to complete the Watch Me Grow app for your child again. As before, | ||
these results will be sent via email. These can also be sent to your nominated health professional. Please go to the | ||
<a href="https://watchmegrow.care">Watch Me Grow app.</a> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"use strict"; | ||
|
||
let https = require("https"); | ||
var aws = require("aws-sdk"); | ||
const moment = require("moment"); | ||
const mailgunJs = require("mailgun-js"); | ||
var markupJs = require("markup-js"); | ||
var fs = require("fs"); | ||
var strings = require("wmg-common/strings"); | ||
var questionnaires = require("wmg-common/questionnaires"); | ||
const _ = require("lodash"); | ||
|
||
const mailgun = mailgunJs({ | ||
apiKey: process.env.MAILGUN_API_KEY, | ||
domain: "auto.watchmegrow.care" | ||
}); | ||
|
||
process.env["PATH"] = | ||
process.env["PATH"] + ":" + process.env["LAMBDA_TASK_ROOT"]; | ||
|
||
const questionnaireReminderAges = questionnaires | ||
.filter(questionnaire => questionnaire.remind_at) | ||
.map(questionnaire => ({ | ||
id: questionnaire.id, | ||
remindAgeInDays: moment.duration(questionnaire.remind_at, "months").asDays() | ||
})); | ||
|
||
exports.handler = function(event, context, callback) { | ||
console.log(questionnaireReminderAges); | ||
|
||
return mailgun | ||
.lists("[email protected]") | ||
.members() | ||
.list() | ||
.then(members => { | ||
const children = _.flatMap(members.items, member => { | ||
return Object.keys(member.vars).map(varKey => | ||
Object.assign(member.vars[varKey], { | ||
name: varKey, | ||
email: member.address, | ||
ageInDays: moment().diff(moment(member.vars[varKey].dob), "days") | ||
}) | ||
); | ||
}); | ||
|
||
console.log(children); | ||
|
||
const toBeReminded = children.filter(child => | ||
questionnaireReminderAges.some( | ||
questionnaire => | ||
!child.completed[questionnaire.id] && | ||
questionnaire.remindAgeInDays === child.ageInDays | ||
) | ||
); | ||
|
||
const promises = toBeReminded.map(child => sendReminder(child)); | ||
|
||
return Promise.all(promises); | ||
}) | ||
.then(result => { | ||
console.log(result); | ||
callback(null, "Successfully executed"); | ||
}) | ||
.catch(e => callback(e)); | ||
}; | ||
|
||
const reminderTemplateBody = fs.readFileSync( | ||
__dirname + "/Reminder.html", | ||
"utf-8" | ||
); | ||
|
||
function sendReminder(child) { | ||
var params = { | ||
from: "[email protected]", | ||
to: child.email, | ||
subject: "Watch Me Grow Reminder for " + child.name, | ||
html: reminderTemplateBody | ||
}; | ||
|
||
return mailgun.messages().send(params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "wmg-email", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"lodash": "^4.17.4", | ||
"mailgun-js": "^0.11.2", | ||
"moment": "^2.18.1", | ||
"wmg-common": "file:../../common" | ||
} | ||
} |
Oops, something went wrong.