webhooks.py 514 B

123456789101112131415161718
  1. import json
  2. from django.conf import settings
  3. def send_moderator_webhook(contrib, request=None):
  4. """ Sends a notification to a webhook
  5. """
  6. if settings.WEBHOOK:
  7. import requests
  8. text = "Nouvelle demande de %s" % contrib.name
  9. if request is not None:
  10. text += ": %s" % contrib.get_absolute_url(request)
  11. requests.post(
  12. settings.WEBHOOK_URL, data=json.dumps({
  13. 'text': text,
  14. 'key': settings.WEBHOOK_KEY,
  15. }))