Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cron/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@
"wecom", "wecom_callback", "weixin", "sms", "email", "webhook", "bluebubbles",
"qqbot",
})
_ORIGIN_HOME_CHANNEL_FALLBACK_PLATFORMS = (
"matrix",
"telegram",
"discord",
"slack",
"bluebubbles",
"whatsapp",
"signal",
"mattermost",
"homeassistant",
"dingtalk",
"feishu",
"wecom",
"wecom_callback",
"weixin",
"sms",
"email",
"webhook",
"qqbot",
)

from cron.jobs import get_due_jobs, mark_job_run, save_job_output, advance_next_run

Expand Down Expand Up @@ -93,7 +113,7 @@ def _resolve_delivery_target(job: dict) -> Optional[dict]:
}
# Origin missing (e.g. job created via API/script) — try each
# platform's home channel as a fallback instead of silently dropping.
for platform_name in ("matrix", "telegram", "discord", "slack", "bluebubbles"):
for platform_name in _ORIGIN_HOME_CHANNEL_FALLBACK_PLATFORMS:
chat_id = os.getenv(f"{platform_name.upper()}_HOME_CHANNEL", "")
if chat_id:
logger.info(
Expand Down
13 changes: 13 additions & 0 deletions tests/cron/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ def test_bare_platform_falls_back_to_home_channel(self, monkeypatch):
"thread_id": None,
}

def test_origin_without_origin_falls_back_to_non_legacy_home_channel(self, monkeypatch):
monkeypatch.setenv("WHATSAPP_HOME_CHANNEL", "15551234567")
job = {
"id": "cron-whatsapp-fallback",
"deliver": "origin",
}

assert _resolve_delivery_target(job) == {
"platform": "whatsapp",
"chat_id": "15551234567",
"thread_id": None,
}

def test_explicit_discord_topic_target_with_thread_id(self):
"""deliver: 'discord:chat_id:thread_id' parses correctly."""
job = {
Expand Down
Loading