-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (41 loc) · 1.63 KB
/
app.py
File metadata and controls
53 lines (41 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sentry_sdk
from flask import Flask, request
from misc import constants, exceptions
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
from sentry_sdk.integrations.flask import FlaskIntegration
from service import account_service, command_service
sentry_sdk.init(
dsn=constants.SENTRY_DSN,
environment=constants.STAGE,
integrations=[FlaskIntegration(), AwsLambdaIntegration()],
traces_sample_rate=0,
)
app = Flask(__name__)
@app.route("/api/slack", methods=["POST"])
def slack():
form_data = request.form
token = form_data.get("token")
text = form_data.get("text")
account_id = form_data.get("team_id")
account_domain = form_data.get("team_domain")
user = form_data.get("user_id")
if token != constants.SLACK_VERIFICATION_TOKEN:
exceptions.capture_exception(exceptions.SlackTokenMismatch(token))
return "Slack request token could not be verified. Please try again later."
account = account_service.get_or_create_account(account_id, account_domain)
try:
target_method, kwargs = command_service.parse_command(text)
return target_method(account=account, user=user, **kwargs)
except exceptions.HoldException as e:
return e.message
except Exception as e:
exceptions.report_exception(e)
return "An unknown error occurred. Please try again later or contact us at letsfinditio@gmail.com."
@app.route("/api/slack/redirect", methods=["GET", "POST"])
def slack_redirect():
return account_service.handle_oauth(request)
@app.route("/api")
def hello():
return "Hello!"
if __name__ == "__main__":
app.run(debug=True)