Freshbot makes it easy to see how many hours your team has left on active FreshBooks projects. It's a Slack bot that runs as an AWS Lambda function, making setup and maintenance easy.
To set up your own Freshbot, you'll need to configure two services: AWS and Slack. To get started, follow the steps below.
- Create a new Lambda function and select Go 1.x as the language. Choose "Create new role from template(s)". Select the "KMS decryption permissions" policy template.
- Set the "Handler" to be
freshbot
. - In the "Environment Variables" section for your function:
- Create a KMS key, if you haven't already. The console will offer to create one for you if you check the "Enable helpers for encryption in transit" box. When asked to define key usage permissions, select the service role that you created in step (1). When you're finished, return to the page for your Lambda function. (If you want to use your own KMS key, visit the "Encryption Keys" section in IAM.)
- Select the KMS key for encryption in transit.
- Add your FreshBooks API key as
FBKS_API_KEY
. Encrypt it. If you want to verify the decryption code that's being used by this library, click the "Code" button to see the sample. - Add your organization's Freshbooks name as
FBKS_ORG_NAME
. For example, if your Freshbooks address is bitlancer.freshbooks.com, then your org name should be "bitlancer".
- In the Basic Setting section, we recommend increasing the timeout value to 10 seconds. In most cases the response will be much faster than that, but it will provide a small buffer in case there are network or server issues.
- Create a new API. The name, description, and endpoint type are up to you.
- Using the "Actions" menu, create a new
POST
method. The integration type should be Lambda Function, and you must check "Use Lambda Proxy integration". - Select the Lambda function that you created in the Lambda section.
- Using the "Actions" menu, deploy the API. You'll need to create a stage.
- Take note of the "Invoke URL" that it gives you, as you'll need that in the next section.
- Visit the Slack Apps page and click "Create New App".
- Give the app a name and select your workspace. Click on "Slash Commands" on the next step, then "Create New Command".
- The command can be anything you like, but the Request URL must be the Invoke URL that you got from API Gateway in step (4).
- Navigate to the "Basic Information" page for your app and follow the instructions to install the app into your workspace.
For security reasons, we recommend adding an FBKS_SLACK_VERIFICATION_TOKEN
environment variable to your Lambda function and using the verification token that Slack displays on your app's basic information page. If that variable is present, then Freshbot will refuse any requests that don't contain the token.
See releases. Those packages can be uploaded directly to AWS Lambda.
To build Freshbot, clone this repository and place it in your GOPATH. Then, to build it, run:
$ GOOS=linux go build
$ zip bundle.zip freshbot
There should now be a bundle.zip
file. To deploy the bot, upload that bundle as your Lambda function package.
At this point, your command should be available in Slack. Give it a try. If everything is configured correctly, then you should see a list of active FreshBooks projects and the number of hours remaining for each of them.