Police Rewired social
A tool for sharing key news with our community.
Usage
This tool is intended to run as an AWS lambda.
Scripts
After you have set up your environment and AWS cli client credentials, you can use the following scripts for quick actions:
init.sh- install the dotnet amazon lambda toolsbuild.sh- rebuild the lambda projectdeploy.sh- deploy the lambda project to AWSpost-dry-run.sh- composes a post from the input parameters, does not send to any social networkspost-message.sh- composes a post from the input parameters, sends to the specified social networksauto-dry-run.sh- chooses a list, and a post from that list's plan, does not send to any social networksauto-message.sh- chooses a list, and a post from that list's plan, sends to the specified social networksrecalculate-plans.sh- recalculates the plan for each listclear-plans.sh- clears all plans for all lists
Invoking the lambda
Invoke the lambda from your local machine with dotnet lambda invoke-function, provide the local profile and a payload.
dotnet lambda invoke-function DistributeSocialLambda --profile sa-social-distributor --payload '{ some: "json here" }'
Sample inputs
{
"command": "post-dry-run",
"networks": [ "facebook", "twitter", "discord" ],
"text": "test message invocation",
"tags": "#test",
"linkUrl": "https://policerewired.org",
"imageUrl": "https://policerewired.github.io/social-distributor-resources/images/test-card.jpeg"
}{
"command": "auto-dry-run",
"networks": [ "facebook", "twitter", "discord" ],
"postsCsvUrl": "https://docs.google.com/spreadsheets/d/e/2PACX-1vSTur9fXXlA0eosd3jpzeOOe9Pi7Dk3T2LdKTobKjIrs2zZWZSMpwlNwDHHYl34wz1F_P2s7p7ya_3B/pub?gid=0&single=true&output=csv",
"rulesCsvUrl": "https://docs.google.com/spreadsheets/d/e/2PACX-1vSTur9fXXlA0eosd3jpzeOOe9Pi7Dk3T2LdKTobKjIrs2zZWZSMpwlNwDHHYl34wz1F_P2s7p7ya_3B/pub?gid=1551543415&single=true&output=csv"
}NB. Police Rewired library posts are published as CSV for consumption by the tool, and as an open data source:
CSV format
CSVs provided for auto mode should conform to the following formats.
posts
| Field | Description |
|---|---|
| ListId | Identity of the list this post belongs to. |
| Text | Text of the post. |
| Tags | Any tags (include the #, eg. #test |
| URL | URL of the link this post is about. |
| ImageURL | URL to an image. (Optional.) |
Many of the images used by Police Rewired are held in the social-distributor-resources repository.
rules
For each post automatically chosen, a list is selected randomly, and weighted by ratio.
| Field | Description |
|---|---|
| ListId | Identity of the list. |
| Ratio | Weight to attribute to the list. |
| Tags | Default tags to apply to posts for this list (optional). |
Manual testing
You can test the tool locally, and issue posts manually using the associated command line app DistributeSocialApp.
- Enter the directory:
cd Distributor/DistributeSocialApp - Pick a name for your environment, eg.
prod - Create an env file in the same directory as your binary, eg.
.env.prod - Place your environment variables in the
.env.prodfile, asKEY=value, one per line. - Configure that file in your project: Build action:
Content, Copy to output directory:Always copy - Build and run the app:
dotnet run <environment> <network> <text> <tags> <link url> [<image url>]
- For environment, provide
prodif you named your environment file.env.prod - Surround values in
'single quotes'to preserve spacing and special characters. - For network, provide one of:
twitter,facebook,discord
State variables
When operating in automatic mode, the distributor keeps state using a JSON file stored in an S3 bucket. Provide the following environment variables:
S3_STATE_BUCKETS3_STATE_KEY
Social network variables
Provide the following environment variables per network you intend to use.
Provide the following environment variables:
TWITTER_CONSUMER_KEYTWITTER_CONSUMER_KEY_SECRETTWITTER_ACCESS_TOKENTWITTER_ACCESS_TOKEN_SECRET
- At the Graph API Explorer, generate a user token for the right app, the right page, and with permissions:
pages_show_list,pages_read_engagement,pages_manage-posts,public_profile - At the Token Debugger, examine that user token. (Expected lifetime is ~60 days.)
- At the Graph API Explorer, provide that access token, and explore
me/accounts - The
data[0].access_tokenfield should contain an indefinite access token. Store it safely. - The
data[0].idfield should contain the page id. Store it safely. - At the Token Debugger, ensure that the token does not expire.
Provide the following environment variables:
FACEBOOK_PAGE_ID- the id of the page to post toFACEBOOK_ACCESS_TOKEN- an unlimited access token derived from the user token
Discord
Provide the following environment variables:
DISCORD_TOKEN- access token belonging to the discord appDISCORD_SERVER_ID- id of the server (enable developer view for a quicker, easier view of this)DISCORD_CHANNEL- the name of the channel you wish to post to (the app will look it up)