-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
52 lines (37 loc) · 2.05 KB
/
server.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
47
48
49
50
51
52
from flask import Flask, request, abort
import json
import bot
print(bot.token)
DEV_KEY = '193119f42d583601d5095b462bde9300'
app = Flask(__name__)
user_token = ''
@app.route('/webhook', methods=['POST','HEAD'])
def webhook():
if request.method == 'POST':
bot.send_info(123)
res = {
'action': request.json['action']['type'],
'comment': '',
'board': request.json['action']['data']['board']['name'],
'list': request.json['action']['data']['list']['name'],
'author': request.json['action']['memberCreator']['username']
}
comment = ''
if res['action'] == 'updateCard':
if request.json['action']['data'].get('listBefore'):
comment = f"Вас переместил {res['author']} из листа {request.json['action']['data']['listBefore']['name']} в {request.json['action']['data']['listAfter']['name']}"
elif request.json['action']['data'].get('old'):
comment = f"Название вашей карточки {request.json['action']['data']['old']} изменилось на {request.json['action']['data']['card']['name']} пользователем {res['author']}"
elif res['action'] == 'removeMemberFromCard':
comment = f"Вы удалены из карточки {request.json['action']['data']['card']['name']} пользователем {res['author']}"
elif res['action'] == 'addMemberToCard':
comment = f"Вы добавлены в карточку {request.json['action']['data']['card']['name']} пользователем {res['author']}"
elif res['action'] == 'commentCard':
comment = f"Комментарий к вашей карточке {request.json['action']['data']['card']['name']}:\n{request.json['action']['data']['text']}\n{res['author']}"
res['comment'] = comment
return res, 200
elif request.method == 'HEAD':
print('connect')
return 'success', 200
if __name__ == '__main__':
app.run()