Skip to content

Commit

Permalink
updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-kolda committed Sep 24, 2017
1 parent cc89097 commit 7cb7450
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -16,3 +16,20 @@ This a proof of concept Slack bot example, which:
* verifies all incoming messages with [Slack verification token](https://api.slack.com/events-api#subscriptions),
* can run for free within [GCP Free Tier](https://cloud.google.com/free/) if there is a small traffic,
* can automatically scale for larger traffic (requires billing enabled).

# Installation

1. Create a GCP project in [GCP Cloud Console](https://console.cloud.google.com) - see [docs](https://support.google.com/cloud/answer/6251787?hl=en&ref_topic=6158848) for details,
1. Create a Slack app on https://api.slack.com/apps/,
1. Add a bot user for your app,
1. Update bot access token and verification token in [settings.py](settings.py),
1. Install [gcloud](https://cloud.google.com/sdk/docs/) tool,
1. Deploy app using [gcloud app deploy](https://cloud.google.com/sdk/gcloud/reference/app/deploy) command, e.g.
`gcloud app deploy --version v1 --project your-gcp-project-id app.yaml`
1. Visiting https://your-gcp-project-id.appspot.com page should trigger 'Hello World' message on #general channel. Slack Web API is now working!
1. Subscribe to [message.channels](https://api.slack.com/events/message.channels) and [message.im](https://api.slack.com/events/message.im) event types by providing `https://your-gcp-project-id.appspot.com/slack/event` url - see [docs](https://api.slack.com/events-api#subscriptions) for details
1. Your bot is now working!

# Development

You can find all development setup in [.travis.yml](.travis.yml)
7 changes: 4 additions & 3 deletions src/main.py
Expand Up @@ -18,7 +18,7 @@

@app.route('/')
def root():
text = "Hello from Google App Engine! :tada:, build date: {}, git "\
text = "Hello from Google App Engine! :tada:, build date: {}, git " \
"commit: {}".format(settings.BUILD_DATE, settings.GIT_COMMIT)
slack_client.post_message(channel='#general',
text=text)
Expand All @@ -30,10 +30,11 @@ def slack_event():
logging.debug("Request payload: %s", request.data)
event = request.get_json()
if 'token' not in event:
logging.error("There is no token in the JSON")
logging.error(
"There is no verification token in the JSON, discarding event")
abort(401)
if event['token'] != verification_token:
logging.error("Wrong token in JSON")
logging.error("Wrong verification token in JSON, discarding event")
abort(403)
if 'challenge' in event:
return jsonify({'challenge': event['challenge']})
Expand Down

0 comments on commit 7cb7450

Please sign in to comment.