WebHook broker that accepts notifications from multiple platforms and performs simple actions in response
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slack.py 693B

12345678910111213141516171819202122232425
  1. import json
  2. from .service import Service
  3. class Slack(Service):
  4. def __init__(self):
  5. super().__init__("slack")
  6. def accept_hook(self, identifier, request):
  7. if request.content_type == "application/json":
  8. content = request.json
  9. else:
  10. content = json.loads(request.form["payload"])
  11. text = content["text"].strip()
  12. if "attachments" in content:
  13. text += " " + " ".join(
  14. filter(
  15. lambda x: len(x) > 0,
  16. (a["fallback"].strip() for a in content["attachments"]),
  17. )
  18. )
  19. yield {"type": f"slack", "source": identifier, "text": text}