@@ -329,6 +329,32 @@ def _build_notification_delivery_log_for_report(
329329 }
330330
331331
332+ def _build_notification_delivery_summary (delivery_events : list [dict ]) -> dict :
333+ safe_fields = (
334+ "sink" ,
335+ "delivery_status" ,
336+ "transport_acknowledged" ,
337+ "error_type" ,
338+ "compact_text_sha256" ,
339+ "compact_text_length" ,
340+ )
341+ events = [
342+ {key : event [key ] for key in safe_fields if key in event }
343+ for event in (dict (item ) for item in delivery_events )
344+ ]
345+ if not events :
346+ return {}
347+ sent_count = sum (event .get ("delivery_status" ) == "sent" for event in events )
348+ failed_count = sum (event .get ("delivery_status" ) == "failed" for event in events )
349+ return {
350+ "attempted_count" : len (events ),
351+ "sent_count" : sent_count ,
352+ "failed_count" : failed_count ,
353+ "all_acknowledged" : failed_count == 0 and sent_count == len (events ),
354+ "delivery_events" : events ,
355+ }
356+
357+
332358signal_text = build_signal_text (t )
333359strategy_display_name = build_strategy_display_name (t )(
334360 STRATEGY_PROFILE ,
@@ -516,16 +542,28 @@ def _notify_runtime_error(exc: Exception, *, route_label: str) -> bool:
516542 print ("LongBridge runtime error notification skipped: no Telegram target configured." , flush = True )
517543 return False
518544 message = _runtime_error_notification_message (exc , route_label = route_label )
545+ outcomes = []
519546 for token , chat_id in targets :
520547 try :
521- requests .post (
548+ response = requests .post (
522549 f"https://api.telegram.org/bot{ token } /sendMessage" ,
523550 json = {"chat_id" : chat_id , "text" : message },
524551 timeout = 10 ,
525552 )
553+ status_code = int (getattr (response , "status_code" , 200 ) or 200 )
554+ acknowledged = 200 <= status_code < 300
555+ load_payload = getattr (response , "json" , None )
556+ payload = load_payload () if acknowledged and callable (load_payload ) else None
557+ if isinstance (payload , dict ) and payload .get ("ok" ) is False :
558+ acknowledged = False
559+ outcomes .append (acknowledged )
526560 except Exception as send_exc :
527- print (f"LongBridge runtime error Telegram send failed: { send_exc } " , flush = True )
528- return True
561+ print (
562+ f"LongBridge runtime error Telegram send failed: { type (send_exc ).__name__ } " ,
563+ flush = True ,
564+ )
565+ outcomes .append (False )
566+ return bool (outcomes ) and all (outcomes )
529567
530568
531569def _handle_route_runtime_error (exc : Exception , * , route_label : str ):
@@ -722,6 +760,11 @@ def run_strategy(*, force_run: bool = False, validation_only: bool = False, vali
722760 )
723761 if notification_delivery_log :
724762 execution_summary ["notification_delivery_log" ] = notification_delivery_log
763+ notification_delivery_summary = _build_notification_delivery_summary (
764+ notification_delivery_events
765+ )
766+ if notification_delivery_summary :
767+ execution_summary ["notification_delivery_summary" ] = notification_delivery_summary
725768 if signal_snapshot :
726769 reporting_adapters .log_event (
727770 log_context ,
0 commit comments