-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathweb_api.py
46 lines (37 loc) · 1.49 KB
/
web_api.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, request, Response
import requests
import json
import api
app = Flask(__name__)
@app.route("/api/action", methods=['GET', 'POST'])
def action():
payload = json.loads(request.form["payload"])
# team_id = requestDict['team']['id']
responses = []
response_url = payload['response_url']
for action in payload['actions']:
responses.append(button_rsvp(
payload['user']['id'], action['value'], payload['original_message'], response_url))
return '', 200
def button_rsvp(user_id, rsvp, original_message, response_url):
if user_id in api.get_invited_users():
api.rsvp(user_id, rsvp)
if(rsvp == "attending"):
api.finalize_event_if_complete()
response_JSON = response_message(
original_message, "✅ Sweet! Det blir sykt nice! 😋")
requests.post(response_url, response_JSON)
elif (rsvp == "not attending"):
api.invite_if_needed()
response_JSON = response_message(
original_message, "⛔️ Ah, ok. Neste gang! 🤝")
requests.post(response_url, response_JSON)
else:
response_JSON = response_message(
original_message, "💣 Hmm, hva har du gjort for noe rart nå?")
requests.post(response_url, response_JSON)
def response_message(original_message, text):
original_message['attachments'] = [{'text': text}]
return json.dumps(original_message)