Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. bp.route('/request', methods=['GET', 'POST'])
  2. def process_request():
  3. approved = False
  4. payload = json.loads(request.form['payload'])
  5. print(payload['actions'])
  6. actions = payload['actions']
  7. for action in actions:
  8. if action['text']['text'] == 'Approve':
  9. approved = True
  10. if action['text']['text'] == 'Deny':
  11. approved = False
  12.  
  13. print(payload['user']['username'])
  14. username = payload['user']['username']
  15. if approved:
  16. message = f"*@{username}* approved this request"
  17. else:
  18. message = f"*@{username}* denied this request"
  19. test = {"type": "section", "text": {"type": "mrkdwn", "text": message}}
  20. for block in payload['message']['blocks']:
  21. if block.get('type', None) == "actions":
  22. payload['message']['blocks'].remove(block)
  23. payload['message']['blocks'].append(test)
  24. response_url = payload['response_url']
  25. print(payload['response_url'])
  26. resp = requests.post(response_url, data=json.dumps(payload['message']), headers={'Content-Type': 'application/json'})
  27. print(resp.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement