@@ -51,6 +51,39 @@ def from_dict(cls, d: Dict[str, Any]) -> "Schedule":
5151 )
5252
5353
54+ @dataclass
55+ class DeliveryTarget :
56+ """Where to deliver the result when a scheduled job fires.
57+
58+ Attributes:
59+ channel: Platform name (``"telegram"``, ``"discord"``,
60+ ``"slack"``, ``"whatsapp"``).
61+ channel_id: Platform-specific chat / channel / group ID.
62+ thread_id: Optional thread ID for threaded delivery.
63+ """
64+
65+ channel : str = ""
66+ channel_id : str = ""
67+ thread_id : Optional [str ] = None
68+
69+ def to_dict (self ) -> Dict [str , Any ]:
70+ d : Dict [str , Any ] = {
71+ "channel" : self .channel ,
72+ "channel_id" : self .channel_id ,
73+ }
74+ if self .thread_id is not None :
75+ d ["thread_id" ] = self .thread_id
76+ return d
77+
78+ @classmethod
79+ def from_dict (cls , d : Dict [str , Any ]) -> "DeliveryTarget" :
80+ return cls (
81+ channel = d .get ("channel" , "" ),
82+ channel_id = d .get ("channel_id" , "" ),
83+ thread_id = d .get ("thread_id" ),
84+ )
85+
86+
5487@dataclass
5588class ScheduleJob :
5689 """A persisted scheduled job.
@@ -67,6 +100,8 @@ class ScheduleJob:
67100 delete_after_run: Auto-remove after first execution (one-shot).
68101 created_at: Epoch timestamp.
69102 last_run_at: Epoch timestamp of most recent execution.
103+ delivery: Optional delivery target for routing results back
104+ to a channel bot (e.g. Telegram chat).
70105 """
71106
72107 name : str = ""
@@ -79,11 +114,12 @@ class ScheduleJob:
79114 delete_after_run : bool = False
80115 created_at : float = field (default_factory = time .time )
81116 last_run_at : Optional [float ] = None
117+ delivery : Optional [DeliveryTarget ] = None
82118
83119 # ── serialisation ────────────────────────────────────────────────
84120
85121 def to_dict (self ) -> Dict [str , Any ]:
86- return {
122+ d : Dict [ str , Any ] = {
87123 "id" : self .id ,
88124 "name" : self .name ,
89125 "schedule" : self .schedule .to_dict (),
@@ -95,10 +131,14 @@ def to_dict(self) -> Dict[str, Any]:
95131 "created_at" : self .created_at ,
96132 "last_run_at" : self .last_run_at ,
97133 }
134+ if self .delivery is not None :
135+ d ["delivery" ] = self .delivery .to_dict ()
136+ return d
98137
99138 @classmethod
100139 def from_dict (cls , d : Dict [str , Any ]) -> "ScheduleJob" :
101140 sched_data = d .get ("schedule" , {})
141+ delivery_data = d .get ("delivery" )
102142 return cls (
103143 id = d .get ("id" , uuid .uuid4 ().hex [:12 ]),
104144 name = d .get ("name" , "" ),
@@ -110,4 +150,5 @@ def from_dict(cls, d: Dict[str, Any]) -> "ScheduleJob":
110150 delete_after_run = d .get ("delete_after_run" , False ),
111151 created_at = d .get ("created_at" , time .time ()),
112152 last_run_at = d .get ("last_run_at" ),
153+ delivery = DeliveryTarget .from_dict (delivery_data ) if isinstance (delivery_data , dict ) else None ,
113154 )
0 commit comments