slackapi / python-slack-events-api

Slack Events API adapter for Python (Flask required)
https://api.slack.com/events
MIT License
343 stars 116 forks source link

added health endpoint and associated tests #25

Closed mike-schiller closed 6 years ago

mike-schiller commented 6 years ago

Summary

The goal of this PR is to add a flexible heath endpoint to make it easy for this service to run inside of a platform like Kubernetes. Further details in: #24

Requirements (place an x in each [ ])

codecov[bot] commented 6 years ago

Codecov Report

Merging #25 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #25   +/-   ##
=======================================
  Coverage   89.36%   89.36%           
=======================================
  Files           3        3           
  Lines          47       47           
=======================================
  Hits           42       42           
  Misses          5        5

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 561ccc6...52b8980. Read the comment docs.

mike-schiller commented 6 years ago

Closing per comments in issue: #24

Roach commented 6 years ago

Here's roughly what you'd want:

from flask import Flask
import json
import os
from slackeventsapi import SlackEventAdapter
from slackclient import SlackClient

app = Flask(__name__)

@app.route("/", methods=['GET'])
def events(event_data):
    return "Hello"

@app.route("/health", methods=['GET'])
    def health():
        return make_response("healthy", 200)

# Our app's Slack Event Adapter for receiving actions via the Events API
SLACK_VERIFICATION_TOKEN = os.environ["SLACK_VERIFICATION_TOKEN"]
slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, "/slack/events", app)

# Example message listener
@slack_events_adapter.on("message")
def message(event_data):
    print("\n\n\n\nmessage\n\n")
    print(json.dumps(event_data, indent=4))

# Once we have our event listeners configured, we can start the Flask server 
if __name__ == "__main__":
    app.run(port=3000)