Missing files?
Opened this issue · 1 comments
Unless I'm confused the slack.template HTML file references some JavaScript files that you have left out of this repo due to some rules in the .gitignore. Is there a reason those are not included or another place that I can get them? Currently getting this when clicking "invite" button:
Uncaught ReferenceError: apigClientFactory is not defined
FWIW, there are a ton of steps missing from the documentation, the files that you are missing are created after you setup the API Gateway, you can then generate the SDK package from the deployment.
Deployment steps
- Build the lambda package with the appropriate information
- Create the lambda function in your AWS account. I'd recommend creating a zip file (see below for help on that), and remember to set the
Handler
torun.lambda_handler
- Create a new API Gateway API
- After API has been created, click the
Actions
button and create a POST handler, and tell it to execute the lambda function you created before. It will ask you to confirm that the API Gateway will be allowed to execute your lambda, this is required so say yes. - Once you've created the POST method, click it, then click on the
Actions
button again, and clickEnable CORS
(if you get errors from the website about missing authentication you forgot this step). This creates a handler for the OPTIONS method automatically, which is required for CORS to work - Click
Actions
button, and then clickDeploy API
. On the screen that comes up, you'll need to provide a name for the endpoint, for exampleprod
orstaging
depending on the type of deployment you want to do - Once the API has been deployed it brings you to a page for the newly deployed API, that should contain a tab called
SDK Generation
, go there and select Javascript from the dropdown menu and then clickGenerate SDK
. This will generate and start the download of a zip file that contains all the extra files missing from the web folder. - Unzip the SDK files to a new folder, and copy the
lib
folder and theapigClient.js
file into theweb
folder - Upload the contents of the web folder to your web-server / S3 bucket for hosting
- ???
- Profit
Lambda zip file generation
To create the zip-file for the Lambda you'd need to run the following commands:
cd lambda
cp slack-invite/run.template slack-invite/run.py
sed -i '' 's/"token": ".*"/"token": "YOUR_SLACK_API_TOKEN_HERE"/' slack-invite/run.py
pip install -Ur slack-invite/requirements.txt -t slack-invite
(cd slack-invite; zip -r ../slack-invite.zip request* run.py)
This will create a zip file in the lambda
folder that you can upload to the Lambda service, already configured for your Slack workspace.
If you are running OSX with Python installed from homebrew, you'll need to create a new file, setup.cfg
in the lambda
folder with the following content
[install]
prefix=
Makefile
I also played around a bit, and wrote a small Makefile that will let you easily configure and create the zip file.
UNAME := $(shell uname -s)
PYDIR := slack-invite
ZIP := slack-invite.zip
PIP ?= $(shell which pip)
all: | silent
@echo $(PIP)
$(info Available targets: build, clean)
build:
# Ensure that we have pip in our path, or prompt the user to tell us where pip is located
ifeq ($(PIP),)
@echo PIP: $(PIP)
$(error Couldnt find pip in your path. You can tell make where it is with: make build PIP=/path/to/pip)
endif
# Required for Python installed from homebrew on OSX, so creating the file just in case if we are running
# on OSX
ifeq ($(UNAME),Darwin)
@echo "[install]\nprefix=" > setup.cfg
endif
# Make sure that the SLACK API token is defined in the environment
ifeq ($(TOKEN),)
$(error You must pass TOKEN as an argument, ex; make build TOKEN="SLACK_API_TOKEN")
endif
@if [ ! -f slack-invite/run.py ]; then cp $(PYDIR)/run.template $(PYDIR)/run.py; fi
@sed -i '' 's/"token": ".*"/"token": "$(TOKEN)"/' $(PYDIR)/run.py
@$(PIP) install -Ur $(PYDIR)/requirements.txt -t $(PYDIR) > /dev/null
@(cd $(PYDIR); zip -r ../$(ZIP) request* run.py > /dev/null)
clean:
$(info Cleaning up temp files created during build)
@rm -rf setup.cfg
silent:
@:
,PHONY: all build clean silent
I've done some quick testing, works for my environment on OSX, but YMMV, but worst case, you can just run the following commands