feat: add feishu message push

This commit is contained in:
ihmily
2025-10-21 17:19:42 +08:00
parent 7041f006c6
commit 7e05bf37f3
7 changed files with 60 additions and 18 deletions

View File

@@ -16,18 +16,22 @@ class MessagePusher:
if self.settings.user_config.get("enable_proxy"):
return self.settings.user_config.get("proxy_address")
def is_any_push_channel_enabled(self) -> bool:
"""Check if any push channel is enabled"""
push_channels = [
@staticmethod
def _get_push_channels() -> list[str]:
return [
"dingtalk_enabled",
"wechat_enabled",
"feishu_enabled",
"bark_enabled",
"ntfy_enabled",
"telegram_enabled",
"email_enabled",
"serverchan_enabled"
"serverchan_enabled",
]
def is_any_push_channel_enabled(self) -> bool:
"""Check if any push channel is enabled"""
push_channels = self._get_push_channels()
return any(self.settings.user_config.get(channel) for channel in push_channels)
@staticmethod
@@ -47,7 +51,7 @@ class MessagePusher:
should_only_notify_no_record = user_config.get("only_notify_no_record")
is_stream_start_enabled = user_config.get("stream_start_notification_enabled")
is_stream_end_enabled = user_config.get("stream_end_notification_enabled")
if message_type is None:
if hasattr(recording, 'is_recording') and recording.is_recording:
message_type = 'end'
@@ -63,16 +67,7 @@ class MessagePusher:
if message_type == 'end' and not is_stream_end_enabled:
return False
push_channels = [
"dingtalk_enabled",
"wechat_enabled",
"bark_enabled",
"ntfy_enabled",
"telegram_enabled",
"email_enabled",
"serverchan_enabled"
]
push_channels = MessagePusher._get_push_channels()
any_channel_enabled = any(user_config.get(channel) for channel in push_channels)
if not any_channel_enabled:
@@ -166,3 +161,10 @@ class MessagePusher:
tags=self.settings.user_config.get("serverchan_tags", "Live Status Update"),
)
self.log_push_result("ServerChan", result)
if self.settings.user_config.get("feishu_enabled"):
result = await self.notifier.send_to_feishu(
url=self.settings.user_config.get("feishu_webhook_url"),
content=push_content,
)
self.log_push_result("Feishu", result)

View File

@@ -234,3 +234,20 @@ class NotificationService:
logger.info(f"ServerChan push failed, SCKEY/SendKey: {key}, Error message: {resp.get('message')}")
return results
async def send_to_feishu(
self, url: str, content: str
) -> dict[str, list[str]]:
results = {"success": [], "error": []}
api_list = [u.strip() for u in url.replace("", ",").split(",") if u.strip()]
for api in api_list:
json_data = {
"msg_type": "text",
"content": {"text": content}
}
resp = await self._async_post(api, json_data)
if resp.get("msg") == 'success':
results["success"].append(api)
else:
results["error"].append(api)
return results

View File

@@ -41,7 +41,7 @@ class CardDialog(ft.AlertDialog):
save_path = recording.recording_dir or self._["no_recording_dir_tip"]
status_info = RecordingStatus.MONITORING if recording.monitor_status else RecordingStatus.STOPPED_MONITORING
recording_status_info = self._[recording.status_info or status_info]
should_push_message = MessagePusher.should_push_message(self.app.settings, recording)
should_push_message = MessagePusher.should_push_message(self.app.settings, recording, message_type='other')
message_push = self._["enabled"] if should_push_message else self._["disabled"]
if not should_push_message and recording.enabled_message_push:
message_push = self._["disabled"] + f' ({self._["not_config_tip"]})'
@@ -73,4 +73,4 @@ class CardDialog(ft.AlertDialog):
def close_panel(self, _):
self.open = False
self.update()
self.update()

View File

@@ -632,6 +632,20 @@ class SettingsPage(PageBase):
),
],
),
self.create_channel_config(
self._["feishu"],
[
self.create_setting_row(
self._["feishu_webhook_url"],
ft.TextField(
value=self.get_config_value("feishu_webhook_url"),
width=300,
on_change=self.on_change,
data="feishu_webhook_url",
),
),
],
),
self.create_channel_config(
self._["serverchan"],
[
@@ -838,6 +852,9 @@ class SettingsPage(PageBase):
self.create_channel_switch_container(
self._["wechat"], ft.Icons.WECHAT, "wechat_enabled"
),
self.create_channel_switch_container(
self._["feishu"], ft.Icons.BOOK, "feishu_enabled"
),
self.create_channel_switch_container(
self._["serverchan"], ft.Icons.CLOUD_OUTLINED, "serverchan_enabled"
),

View File

@@ -33,6 +33,7 @@
"custom_stream_end_content": "",
"dingtalk_enabled": false,
"wechat_enabled": false,
"feishu_enabled": false,
"bark_enabled": false,
"ntfy_enabled": false,
"serverchan_enabled": false,
@@ -45,6 +46,7 @@
"dingtalk_at_objects": "",
"dingtalk_at_all": false,
"wechat_webhook_url": "",
"feishu_webhook_url": "",
"bark_webhook_url": "",
"bark_interrupt_level": "active",
"bark_sound": "",

View File

@@ -267,6 +267,7 @@
"push_channels": "Push Channels",
"dingtalk": "DingTalk",
"wechat": "Wechat",
"feishu": "Feishu",
"email": "Email",
"telegram": "Telegram",
"select_and_enable_channels": "Select and enable the channels you want to use",
@@ -278,6 +279,7 @@
"dingtalk_webhook_hint": "Enter DingTalk group webhook URL",
"dingtalk_phone_numbers_hint": "Enter DingTalk phone numbers",
"wechat_webhook_url": "WeChat Webhook URL",
"feishu_webhook_url": "Feishu Webhook URL",
"bark_webhook_url": "Bark Webhook URL",
"bark_interrupt_level": "Bark Interrupt Level",
"bark_sound": "Bark Sound",

View File

@@ -267,6 +267,7 @@
"push_channels": "推送渠道",
"dingtalk": "钉钉",
"wechat": "微信",
"feishu": "飞书",
"email": "邮箱",
"telegram": "电报",
"select_and_enable_channels": "选择并启用您希望使用的推送渠道",
@@ -278,6 +279,7 @@
"dingtalk_webhook_hint": "填写钉钉群Webhook连接",
"dingtalk_phone_numbers_hint": "填写钉钉手机号",
"wechat_webhook_url": "微信推送接口地址",
"feishu_webhook_url": "飞书推送接口地址",
"bark_webhook_url": "Bark推送接口地址",
"bark_interrupt_level": "Bark推送中断级别",
"bark_sound": "Bark推送铃声",