__init__.py 1.2 KB

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