|
|
@@ -263,16 +263,19 @@ async def test_feishu_settings_are_validated_and_never_exposed(app_modules):
|
|
|
"feishu_webhook_url": webhook_url,
|
|
|
"feishu_webhook_signing_secret": "signing-secret",
|
|
|
"feishu_message_preview_enabled": True,
|
|
|
+ "feishu_outgoing_message_enabled": True,
|
|
|
},
|
|
|
)
|
|
|
assert stored["feishu_webhook_url"] == webhook_url
|
|
|
assert stored["feishu_webhook_signing_secret"] == "signing-secret"
|
|
|
+ assert stored["feishu_outgoing_message_enabled"] is True
|
|
|
|
|
|
public = dbassistant.public_account_settings(stored)
|
|
|
assert public["feishu_webhook_url"] == ""
|
|
|
assert public["feishu_webhook_signing_secret"] == ""
|
|
|
assert public["feishu_webhook_configured"] is True
|
|
|
assert public["feishu_signing_secret_configured"] is True
|
|
|
+ assert public["feishu_outgoing_message_enabled"] is True
|
|
|
|
|
|
connections, _total = await dbassistant.list_business_connections()
|
|
|
assert connections[0]["settings"]["feishu_webhook_url"] == ""
|
|
|
@@ -732,6 +735,66 @@ async def test_every_user_message_notifies_feishu_once(app_modules):
|
|
|
assert incoming["metadata"]["feishu_notification_status"] == "sent"
|
|
|
|
|
|
|
|
|
+async def test_outgoing_business_messages_notify_feishu_when_enabled(app_modules):
|
|
|
+ dbassistant, _service, runtime, _knowledge = await prepare_runtime(app_modules)
|
|
|
+ await dbassistant.update_account_settings(
|
|
|
+ "conn-a",
|
|
|
+ {
|
|
|
+ "assistant_enabled": False,
|
|
|
+ "feishu_webhook_enabled": True,
|
|
|
+ "feishu_webhook_url": "https://open.feishu.cn/open-apis/bot/v2/hook/12345678-abcd-4321-abcd-123456789abc",
|
|
|
+ "feishu_message_preview_enabled": True,
|
|
|
+ },
|
|
|
+ )
|
|
|
+ feishu = FakeFeishuWebhook()
|
|
|
+ runtime.feishu = feishu
|
|
|
+ await runtime.process_update(
|
|
|
+ {"update_id": 201, "business_message": customer_message(message_id=1)}
|
|
|
+ )
|
|
|
+ await runtime.process_update(
|
|
|
+ {
|
|
|
+ "update_id": 202,
|
|
|
+ "business_message": customer_message(
|
|
|
+ message_id=2, sender_id=900, text="默认不推送"
|
|
|
+ ),
|
|
|
+ }
|
|
|
+ )
|
|
|
+ assert len(feishu.sent) == 1
|
|
|
+
|
|
|
+ await dbassistant.update_account_settings(
|
|
|
+ "conn-a", {"feishu_outgoing_message_enabled": True}
|
|
|
+ )
|
|
|
+ owner_reply = customer_message(message_id=3, sender_id=900, text="人工回复")
|
|
|
+ await runtime.process_update({"update_id": 203, "business_message": owner_reply})
|
|
|
+ await runtime.process_update({"update_id": 204, "business_message": owner_reply})
|
|
|
+ assert len(feishu.sent) == 2
|
|
|
+ assert feishu.sent[-1]["title"] == "店主 · 托管账号"
|
|
|
+ assert "人工回复" in feishu.sent[-1]["text"]
|
|
|
+ assert feishu.sent[-1]["link_url"] == "https://t.me/user501"
|
|
|
+ conversation = await dbassistant.get_conversation_by_chat("conn-a", 501)
|
|
|
+ messages = await dbassistant.recent_conversation_messages(
|
|
|
+ conversation["conversation_id"], limit=10
|
|
|
+ )
|
|
|
+ human = next(
|
|
|
+ item
|
|
|
+ for item in messages
|
|
|
+ if item["direction"] == "human" and item["telegram_message_id"] == 3
|
|
|
+ )
|
|
|
+ assert human["metadata"]["feishu_notification_status"] == "sent"
|
|
|
+
|
|
|
+ await dbassistant.update_account_settings("conn-a", {"assistant_enabled": True})
|
|
|
+ await runtime.process_update(
|
|
|
+ {
|
|
|
+ "update_id": 205,
|
|
|
+ "business_message": customer_message(message_id=4, chat_id=503, sender_id=503),
|
|
|
+ }
|
|
|
+ )
|
|
|
+ assert len(feishu.sent) == 4
|
|
|
+ assert feishu.sent[-1]["title"] == "智能接待 · 托管账号"
|
|
|
+ assert "每天 09:00 至 18:00 营业" in feishu.sent[-1]["text"]
|
|
|
+ assert feishu.sent[-1]["link_url"] == "https://t.me/user503"
|
|
|
+
|
|
|
+
|
|
|
async def test_handoff_sensitive_non_text_provider_error_and_expired_window(app_modules):
|
|
|
dbassistant, service, runtime, _knowledge = await prepare_runtime(app_modules)
|
|
|
await dbassistant.update_account_settings(
|
|
|
@@ -1115,6 +1178,7 @@ async def test_business_assistant_api_permission_csrf_audit_and_clear(app_module
|
|
|
"connection_id": "conn-a",
|
|
|
"assistant_enabled": True,
|
|
|
"feishu_webhook_enabled": True,
|
|
|
+ "feishu_outgoing_message_enabled": True,
|
|
|
"feishu_webhook_url": "https://open.feishu.cn/open-apis/bot/v2/hook/12345678-abcd-4321-abcd-123456789abc",
|
|
|
"feishu_webhook_signing_secret": "api-secret",
|
|
|
"confirm": True,
|
|
|
@@ -1126,6 +1190,7 @@ async def test_business_assistant_api_permission_csrf_audit_and_clear(app_module
|
|
|
assert saved_data["feishu_webhook_url"] == ""
|
|
|
assert saved_data["feishu_webhook_signing_secret"] == ""
|
|
|
assert saved_data["feishu_webhook_configured"] is True
|
|
|
+ assert saved_data["feishu_outgoing_message_enabled"] is True
|
|
|
stored_settings = await dbassistant.get_account_settings("conn-a")
|
|
|
assert stored_settings["feishu_webhook_signing_secret"] == "api-secret"
|
|
|
listed_connections = await client.get(
|