import requests
import json
class FeishuBot:
def __init__(self, webhook_url):
self.webhook_url = webhook_url
def send_text(self, text, mentions=None):
headers = {"Content-Type": "application/json"}
content = {"text": text}
if mentions:
content["text"] = f"<at user_id=\"{mentions}\">{text}</at>"
payload = {"msg_type": "text", "content": content}
response = requests.post(self.webhook_url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
print("消息发送成功")
else:
print(f"消息发送失败,错误代码:{response.status_code}, 错误信息:{response.text}")
# 使用示例
webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/30ff1b91-bd07-4e99-a716-2e3a96436862"
bot = FeishuBot(webhook_url)
bot.send_text("早上好")