feishu_api.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from applications.decorator import retryOnTimeout
  7. @retryOnTimeout()
  8. def bot(title, detail, mention=True):
  9. """
  10. 机器人
  11. """
  12. title_obj = {
  13. "content": "{}<at id=all></at>\n".format(title) if mention else "{}\n".format(title),
  14. "tag": "lark_md",
  15. }
  16. head_title = "【重点关注】" if mention else "【普通通知】"
  17. url = "https://open.feishu.cn/open-apis/bot/v2/hook/b44333f2-16c0-4cb1-af01-d135f8704410"
  18. headers = {"Content-Type": "application/json"}
  19. payload = {
  20. "msg_type": "interactive",
  21. "card": {
  22. "elements": [
  23. {
  24. "tag": "div",
  25. "text": title_obj,
  26. },
  27. {
  28. "tag": "div",
  29. "text": {
  30. "content": json.dumps(
  31. detail, ensure_ascii=False, indent=4
  32. ),
  33. "tag": "lark_md",
  34. },
  35. },
  36. ],
  37. "header": {"title": {"content": head_title, "tag": "plain_text"}},
  38. },
  39. }
  40. requests.request("POST", url=url, headers=headers, data=json.dumps(payload), timeout=10)