Defines an aws lambda function to convert slack text into party parrots
Inspired by https://github.com/Shrugs/partyparrot, we're doing basically the same thing except in golang and running as an aws lambda function.
I've also moved to a 4x4 grid for each character as personal preference, as friends that use mobile are destroyed by this and every little bit helps.
However, the main motivation was to save $$$, as paying for even a micro ec2 instance is waaaay more expensive for my use case.
To build:
-
Build the code (I use windows and you'll need to setup your go environment and navigate to your go root before this): go get github.com/brnsampson/go-partyparrot/pplambda $env:GOOS="linux" $env:GOARCH="amd64" go build -o pplambda src\github.com\brnsampson\go-partyparrot\pplambda (or just
GOOS=linux GOARCH=amd64 go build -o pplambda src\github.com\brnsampson\go-partyparrot\pplambda
if you're running linux) -
Download the lambda packages go get github.com/aws/aws-lambda-go/events go get github.com/aws/aws-lambda-go/lambda
3.a. (only if you're on windows like me :'( ) get the lambda zip creater go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip ~\go\bin\build-lambda-zip.exe -o .\pplambda.zip .\pplambda
3.b. (for linux) chmod +x pplambda zip pplambda.zip pplambda
To deploy:
- Get an AWS account. See https://aws.amazon.com/
- Create the lambda function by going to Services > compute/lambda and clicking "Create function"
- Add the API Gateway as a trigger for your function
- Upload your zip file as the function code
- Create an environment variable named
SLACK_TEAM_TOKENS
and add all of the slack tokens you wish to use delimited by a colon (:) - Save your function
- Add a test that looks like this: { "Body": "token=&team_id=WTFBBQ&team_domain=dangerouspeople&channel_id=NUMBERS&channel_name=directmessage&user_id=DANGEROUSPERSON&user_name=cooldude&command=%2Fparty&text=test&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT0BKPG7MM%2F320588249252%2FpVJ4B4U3ndfluZaY4UMkWvZ2" }
- Your test should work at this point.
- You should have been prompted to set up a minimal api gateway resource/method if you didn't already have one. If you already had one, I assume you should know how to add a resource for your new function.
- To get the URL you can use, go to API Gateway > APIs > > Stages and then click on whatever stage you created or added your lambda function to.
- The URL to use will be the "Invoke URL" at the top of the pane. The URL to put into slack is /
Whew! Too much detail. But hopefully it'll help someone out some day.