Commit 8be69937 authored by Jonah Meijers's avatar Jonah Meijers

Using environment variables for configuration

parent 0e164924
......@@ -5,7 +5,7 @@
When you're in an active slack-community quite often someone says something funny, or otherwise noteworthy.
'Back in the old days or IRC' having bots in channels that performed all kind of functions were standard. Some of them
even contained functionality to save and retrieve quotes.
Nowadays I found this lacking, and decided to build this using the serverless architecture.
Nowadays I find this to be lacking, and decided to build it myself using the serverless architecture.
By leveraging AWS technologies like Lambda, API-Gateway and DynamoDB, I found it was possible to re-create the old-school quote bots.
In this repository you will find a bot-lambda.py file which contains the code for a lambda which performs this role.
......@@ -29,8 +29,16 @@ Note: Your Lambda will need to use an api-gateway and use a role that has access
Use the code in the repository as your function.
#### Environment Variables
The lambda uses environment variables to get its configuration.
Set the following variables:
- expected_token: The token being sent by slack for authentication purposes.
- channel_identifier: This is just a 'set' value for the primary partition key. ( I use the name of my slack community, but this can be anything)
- quote_table_name: The name of the table in DynamoDB being used to store the quotes. (quote-table is a sane default)
- quote_page_size: The amount of quotes per page when listing quotes. (10 is a sane default value)
### Create a slack 'Slash-command'
Go to <yourcommunityname>.slack.com/apps/manage/custom-integrations, create your slash-command and point it to the endpoint of your api-gateway. It will show you the token it will use to authenticate. Insert this into the code of your lambda function.
Go to <yourcommunityname>.slack.com/apps/manage/custom-integrations, create your slash-command and point it to the endpoint of your api-gateway. It will show you the token it will use to authenticate. Insert this into the correct environment variable for your lambda.
## How does it work?
DynamoDB is an advanced highly-scalable key-value store developed by Amazon to allow for high-volume high-performance datastorage.
......
......@@ -23,13 +23,11 @@ from urlparse import parse_qs
import boto3
from boto3.dynamodb.conditions import Key
expected_token = 'THE TOKEN BEING SENT BY SLACK'
expected_token = os.environ['expected_token']
#This is not really being used except for having a set partition key
channel_identifier = '#SOMESLACKCHANNEL'
quote_table_name = 'quote-table'
quote_page_size = 10
channel_identifier = os.environ['channel_identifier']
quote_table_name = os.environ['quote_table_name']
quote_page_size = int(os.environ['quote_page_size'])
logger = logging.getLogger()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment