feishuBotApi.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from applications.decoratorApi 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. url = "https://open.feishu.cn/open-apis/bot/v2/hook/b44333f2-16c0-4cb1-af01-d135f8704410"
  17. headers = {"Content-Type": "application/json"}
  18. payload = {
  19. "msg_type": "interactive",
  20. "card": {
  21. "elements": [
  22. {
  23. "tag": "div",
  24. "text": title_obj,
  25. },
  26. {
  27. "tag": "div",
  28. "text": {
  29. "content": json.dumps(
  30. detail, ensure_ascii=False, indent=4
  31. ),
  32. "tag": "lark_md",
  33. },
  34. },
  35. ],
  36. "header": {"title": {"content": "【重点关注】", "tag": "plain_text"}},
  37. },
  38. }
  39. requests.request("POST", url=url, headers=headers, data=json.dumps(payload), timeout=10)