Automate the publishing of IJPO letters to PEP-Web Disqus comments
Report Bug
·
Request Feature
Table of Contents
This project has been built to automate the publishing of letters from Manuscript Central to PEP-Web Disqus comments using AWS Step Functions.
The infrastructure is deployed via CDK and defined within the lib/stack.ts
entrypoint.
Letters within Manuscript can be exported via email directly to this service's COMMENT_EMAIL_ADDRESS
email address.
Once an email is received, an SNS notification will be triggered and fed into a new execution of the commenting state machine via an intermediary Lambda function.
This intemediary step is necessary, as Step Functions cannot yet be triggered diretly from SNS.
The email contents are then parsed and the resultant values are used to determine IJPO consent status and assert that the relevant article is live on PEP-Web before publishing a comment via the Disqus API.
Any errors are caught and sent as an email notification to the EMAIL_NOTIFICATION_RECIPIENT
using SES.
The state machine expects to recieve email notifications with the following format:
ARTICLE_ID.REVISION@IJP_OPEN_CONSENT_WITHDRAWN
Examples:
- IJPOPEN.001.0001A.r3@no - consent not withdrawn, proceed with comment
- IJPOPEN.003.0003B.r1@yes - consent withdrawn, exit early
The entire plain text body of the email will be posted to the Disqus thread of the PEP-Web article.
Please ensure the total body length is less than 20,000 characters.
Before you start, you'll need to install the AWS CDK and AWS CLI:
-
Install the AWS CLI
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
-
Install CDK
npm install -g aws-cdk
- Clone the repo
git clone https://github.com/jordanallen-dev/disqus-comment-service.git
- Install NPM packages
npm install
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest testsnpm run lint
perform lintingnpm run test:watch
perform the jest tests in watch modenpm run deploy:ci
deploy the stack, skipping user confirmationcdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
There are currently 9 required environment variables:
AWS_ACCESS_KEY
- IAM user with admin permissions for CDK deploymentsAWS_SECRET_KEY
- IAM user with admin permissions for CDK deploymentsDISQUS_FORUM
- Disqus shortnameDISQUS_PUBLIC
- Disqus application public keyDISQUS_SECRET
- Disqus application secret keyCOMMENT_EMAIL_ADDRESS
- Internal email address to receive IJPO lettersEMAIL_NOTIFICATION_RECIPIENT
- Email notification recipientPEP_API_KEY
- PEP API KeyPEP_API_BASE_URL
- PEP API base URLEMAIL_WHITELIST
- comma-delimited string of email addresses or domains to allow actions fromWITHDRAW_EMAIL_ADDRESS
- Internal email address to recieve IJPO withdrawal requests
Make a copy of the included .env-template
file and call it .env
.
Fill your .env
file with the values for each listed variable.
If you plan on using the included GitHub Action workflows for continuous deployment (CD), you'll need to configure each of the required variables within the GitHub secrets of your repo:
If you are deploying the project to an AWS account for the first time, you'll need to configure your AWS environment using CDK's bootstrap command:
-
Configure your AWS credentials
aws configure # follow on-screen prompts
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html
-
Bootstrap your AWS account
cdk bootstrap aws://ACCOUNT-NUMBER/REGION
-
You can now deploy using
cdk deploy
or (recommended) the included GitHub Actions workflows
In order to receive inbound emails and send outbound notifications, you'll need to manually configure your domain and recipient email in SES.
- Visit the verified identities page of SES within the AWS console (https://us-east-1.console.aws.amazon.com/ses/home?region=us-east-1#/verified-identities)
- Click "Create Identity"
- Select "Domain" and enter the domain of your
COMMENT_EMAIL_ADDRESS
- Click "Create Identity" again
- If your domain is not configured in Route53, follow the on-screen instructions to validate your domain using CNAME DNS records.
- Wait until the identity status displays as "Verified"
If your AWS SES is still in sandbox mode, you'll need to verify the external EMAIL_NOTIFICATION_RECIPIENT
address that you wish to recieve error notifications on:
- Visit the verified identities page again
- Click "Create Identity"
- Select "Email address" and enter your
EMAIL_NOTIFICATION_RECIPIENT
address - Click "Create Identity" again
- Click the link in the confirmation email in the
EMAIL_NOTIFICATION_RECIPIENT
inbox
To enable email receiving on the domain of your COMMENT_EMAIL_ADDRESS
, create an MX
record with the value 10 inbound-smtp.region.amazonaws.com
where region
is AWS region you have configured your SES identity on.
See the "Publising an MX record for AWS SES email receiving" on AWS for more information: https://docs.aws.amazon.com/ses/latest/dg/receiving-email-mx-record.html
Lastly, you'll need to activate the email receiving rule set created by the CDK stack:
- Navigate to the email receiving section of SES within the AWS console (https://us-east-1.console.aws.amazon.com/ses/home?region=us-east-1#/email-receiving)
- Select the rulset with the prefix
DisqusCommentServiceStackEmailRuleSet
- Press "Set as active" and confirm the prompt
The project contains a full suite of test that are executed using the Jest test runner.
npm run test # run all tests
npm run test:watch # run in interactive watch mode
To invoke individual Lambdas directly on your machine, you can use the AWS SAM CLI. Please follow the Locally testing AWS CDK applications guide on AWS to learn more.
It's also possible to execute entire Step Functions locally. Please follow the Testing Step Functions State Machines Locally guide on AWS if you're interested in trying it out.
If you want to manually trigger a step function for testing / debugging, you can use the following payload stub:
{
"notificationType": "Received",
"content": "Return-Path: <[email protected]>\r\nReceived: from a9-183.smtp-out.amazonses.com (a9-183.smtp-out.amazonses.com [54.240.9.183])\r\n by inbound-smtp.us-east-1.amazonaws.com with SMTP id d6iitobk75ur44p8kdnnp7g2n800\r\n for [email protected];\r\n Fri, 11 Sep 2015 20:32:33 +0000 (UTC)\r\nDKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\r\n\ts=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1442003552;\r\n\th=From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID:Feedback-ID;\r\n\tbh=DWr3IOmYWoXCA9ARqGC/UaODfghffiwFNRIb2Mckyt4=;\r\n\tb=p4ukUDSFqhqiub+zPR0DW1kp7oJZakrzupr6LBe6sUuvqpBkig56UzUwc29rFbJF\r\n\thlX3Ov7DeYVNoN38stqwsF8ivcajXpQsXRC1cW9z8x875J041rClAjV7EGbLmudVpPX\r\n\t4hHst1XPyX5wmgdHIhmUuh8oZKpVqGi6bHGzzf7g=\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: IJP.103.0001A@no\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\nDate: Fri, 11 Sep 2015 20:32:32 +0000\r\nMessage-ID: <[email protected]>\r\nX-SES-Outgoing: 2015.09.11-54.240.9.183\r\nFeedback-ID: 1.us-east-1.Krv2FKpFdWV+KUYw3Qd6wcpPJ4Sv/pOPpEPSHn2u2o4=:AmazonSES\r\n\r\nExample content\r\n"
}
Please replace IJP.103.0001A@no
with your email subject and Example content
with your body content.
If you have a suggestion that would make this better please create a pull request. You can also simply open an issue with the tag "enhancement".
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request