A simple SlackBot which runs in AWS and renders LaTeX equations for your channels.
This uses Maven so you should just be able to run mvn package
in the root of the workspace and then upload SlackLatexRenderer-1.0.0.jar
from the target
directory.
- Ensure you have a working AWS account
- Select an AWS region (all further work is done in this region)
- Create an S3 bucket in that region. (No special permissions are needed.)
- Create a DynamoDB Table with the following properties. Make a note of the table ARN.
- Primary partition key: EventId (String)
- Time to live attribute (must be set after creation: Expiration
- Capacity: 2/2 (you can always raise it later if you need to)
- Create a Lambda function
- Author from Scratch
- Name = Whatever you like
- Runtime = Java 8
- Role = Create existing (use default)
- Main configuration
- Handler =
com.nettgryppa.SlackLatexRenderer.LatexRenderingHandler
- Environment S3_REGION=(region selected above)
- Environment BUCKET=(bucket created above)
- Upload jar from compilation
- (Make a note of the function ARN in the upper right)
- SAVE
- Handler =
- "Add Trigger" - "API Gateway"
- "Create new API"
- Security = Open
- ADD
- Make a note of the API Endpoint (it's a URL)
- Author from Scratch
- Go to the IAM console and load the role you created earlier
- Substituting your bucket for
$BUCKET
and the function arn for$LAMBDA_ARN
, add the following policy:{ "Version": "2012-10-17", "Statement": [ { "Sid": "UploadImages", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObjectAcl", "s3:GetObject", "s3:PutObjectVersionAcl", "s3:GetObjectVersionAcl", "s3:ListBucket", "s3:PutObjectTagging", "s3:GetBucketLocation", "s3:PutObjectAcl", "s3:GetObjectVersion" ], "Resource": [ "arn:aws:s3:::$BUCKET/*", "arn:aws:s3:::$BUCKET" ] }, { "Sid": "InspectImagess", "Effect": "Allow", "Action": [ "s3:HeadBucket", "s3:ListObjects" ], "Resource": "*" }, { "Sid": "SelfCall", "Effect": "Allow", "Action": [ "lambda:InvokeFunction", "lambda:InvokeAsync" ], "Resource": "$LAMBDA_ARN" }, { "Sid": "AccessLockTable", "Effect": "Allow", "Action": [ "dynamodb:PutItem", "dynamodb:GetItem", "dynamodb:UpdateItem" ], "Resource": "$DYNAMO_TABLE_ARN" } ] }
- Substituting your bucket for
I don't currently remember how I set up the slack side of things, so this is a combination of bad memory and guess-work. (I'd love pull requests to fix this.)
- Create a new app
- "OAuth & Permissions"
- Record the "Bot User OAuth Access Token"
- Add the following scopes:
- channels:read
- chat:write:bot
- chat:write:user
- bot
- "Bot Users"
- Give it a display name and user name
- Mark as "Always show my bot as online"
- Go to "Event Subscriptions"
- Enable it (top right)
- Set the Request URL to the API Endpoint from earlier
- Subscribe to Bot Events: message.channels
- Go to "Basic Information" and record the "Verification Token"
Return to the Lambda function you created previously and add the following environment variables:
- SLACK_TOKEN = $VerificationToken
- OAUTH_TOKEN = $BotUserOAuthAccessToken
Return to Slack and under "Event Subscriptions" have it verify the endpoint
Figure out how to get it into your channels and it will respond to any LaTeX mathematic expression between two equals signs: