Files
devplacepy/devplacepy/services/devii/actions/notification_actions.py
T
retoor e0e64c8d9e feat: add telegram notification channel with outbox service and per-user preferences
Extend the notification system with a third channel (telegram) alongside existing in_app and push channels. Add `telegram_enabled` column to `notification_preferences` table, update `NOTIFICATION_CHANNELS` and `_NOTIFICATION_CHANNEL_COLUMNS` mappings, and set telegram default to off (`_NOTIFICATION_CHANNEL_DEFAULTS`). Create `telegram_outbox` table with columns for uid, user_uid, chat_id, text, status, attempts, created_at, and sent_at, plus an index on status/id for efficient polling. Register `TelegramOutboxService` in the service manager lifecycle. Update API documentation strings to describe the new channel and its pairing requirement. Extend admin notification defaults view to include telegram column. Pass `notif_telegram_paired` flag to profile template based on `telegram_store.is_paired()` check. Update `NotificationPrefForm` and `NotificationDefaultForm` model literals to accept "telegram" as a valid channel value.
2026-06-22 20:52:02 +00:00

82 lines
2.5 KiB
Python

# retoor <retoor@molodetz.nl>
from __future__ import annotations
from .spec import Action, Param
def arg(
name: str, description: str, required: bool = False, kind: str = "string"
) -> Param:
return Param(
name=name,
location="body",
description=description,
required=required,
type=kind,
)
TYPES = (
"One of: comment, reply, mention, vote, follow, message, badge, level, issue."
)
NOTIFICATION_ACTIONS: tuple[Action, ...] = (
Action(
name="notification_list",
method="LOCAL",
path="",
summary="List the user's notification preferences (in-app, push and telegram per type)",
description=(
"Returns every notification type with the user's current in-app, push and telegram "
"setting and whether it has been customized. Use this before changing a setting."
),
handler="notification",
requires_auth=True,
read_only=True,
),
Action(
name="notification_set",
method="LOCAL",
path="",
summary="Enable or disable one notification type on one channel",
description=(
"Sets whether the user receives a given notification type on a given channel. The three "
"channels are independent: in-app (shown on DevPlace), push (sent to subscribed devices) "
"and telegram (delivered to the user's paired Telegram chat, off by default)."
),
handler="notification",
requires_auth=True,
params=(
arg("notification_type", TYPES, required=True),
arg("channel", "Either 'in_app', 'push' or 'telegram'.", required=True),
arg(
"value",
"true to deliver this notification on this channel, false to suppress it.",
required=True,
kind="boolean",
),
),
),
Action(
name="notification_reset",
method="LOCAL",
path="",
summary="Reset all notification preferences to the platform defaults",
description=(
"Clears every notification override for the user so all types fall back to the platform "
"default. This cannot be undone."
),
handler="notification",
requires_auth=True,
params=(
arg(
"confirm",
"Must be true after the user has confirmed the reset.",
required=True,
kind="boolean",
),
),
),
)