FeishuBot.py 638 B

1234567891011121314151617
  1. import requests
  2. class FeishuBot:
  3. webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/your_webhook_id"
  4. def __init__(self):
  5. self.webhook_url = self.webhook_url
  6. def send_message(self, message_text):
  7. headers = {'Content-Type': 'application/json'}
  8. data = {
  9. "msg_type": "text",
  10. "content": {"text": message_text}
  11. }
  12. response = requests.post(self.webhook_url, json=data, headers=headers)
  13. response.raise_for_status() # 如果响应状态码不是200,则抛出HTTPError异常
  14. return response.json() # 返回JSON响应(如果需要的话)