@@ -79,7 +79,7 @@ async def start_all(self) -> None:
7979 channel_id = channel_id ,
8080 plugin = plugin ,
8181 config = config_dict ,
82- on_message = self ._dispatcher .dispatch ,
82+ on_message = self ._make_on_message ( plugin , self . _dispatcher .dispatch ) ,
8383 abort_event = abort_event ,
8484 ),
8585 name = f"channel-{ channel_id } " ,
@@ -182,7 +182,7 @@ async def start_channel(self, channel_id: str) -> None:
182182 channel_id = channel_id ,
183183 plugin = plugin ,
184184 config = config_dict ,
185- on_message = self ._dispatcher .dispatch ,
185+ on_message = self ._make_on_message ( plugin , self . _dispatcher .dispatch ) ,
186186 abort_event = abort_event ,
187187 ),
188188 name = f"channel-{ channel_id } " ,
@@ -328,6 +328,23 @@ async def _run_with_reconnect(
328328 # Reconnect helpers
329329 # ------------------------------------------------------------------
330330
331+ @staticmethod
332+ def _make_on_message (
333+ plugin : ChannelPlugin ,
334+ dispatch : Callable ,
335+ ) -> Callable :
336+ """Wrap *dispatch* so that each inbound message records a timestamp."""
337+ async def _on_message (msg ) -> None :
338+ plugin .record_message ()
339+ await dispatch (msg )
340+ return _on_message
341+
342+ def record_message (self , channel_id : str ) -> None :
343+ """Update last_message_at on a running channel plugin (e.g. from an HTTP handler)."""
344+ plugin = self ._running_plugins .get (channel_id ) or self ._registry .get (channel_id )
345+ if plugin :
346+ plugin .record_message ()
347+
331348 @staticmethod
332349 async def _mark_connected (plugin : ChannelPlugin , channel_id : str ) -> None :
333350 plugin .mark_connected ()
0 commit comments