feishuBotApi.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from applications.decoratorApi import retryOnTimeout
  7. @retryOnTimeout()
  8. def bot(title, detail):
  9. """
  10. 机器人
  11. """
  12. url = "https://open.feishu.cn/open-apis/bot/v2/hook/b44333f2-16c0-4cb1-af01-d135f8704410"
  13. headers = {"Content-Type": "application/json"}
  14. payload = {
  15. "msg_type": "interactive",
  16. "card": {
  17. "elements": [
  18. {
  19. "tag": "div",
  20. "text": {
  21. "content": "{}<at id=all></at>\n".format(title),
  22. "tag": "lark_md",
  23. },
  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": "【重点关注】", "tag": "plain_text"}},
  36. },
  37. }
  38. requests.request("POST", url=url, headers=headers, data=json.dumps(payload), timeout=10)