__init__.py 1.2 KB

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