1- """Google Voice notification helpers for strategy plugin alerts."""
1+ """Email notification helpers for strategy plugin alerts."""
22
33from __future__ import annotations
44
1818from .email import parse_email_recipients , send_smtp_email
1919
2020
21- _DEFAULT_GOOGLE_VOICE_SMTP_HOST = "smtp.gmail.com"
22- _DEFAULT_GOOGLE_VOICE_SMTP_PORT = 465
23- _DEFAULT_GOOGLE_VOICE_SMTP_SECURITY = "ssl"
21+ _DEFAULT_EMAIL_SMTP_HOST = "smtp.gmail.com"
22+ _DEFAULT_EMAIL_SMTP_PORT = 465
23+ _DEFAULT_EMAIL_SMTP_SECURITY = "ssl"
2424_SMTP_SECURITY_NONE = "none"
2525_SMTP_SECURITY_SSL = "ssl"
2626_SMTP_SECURITY_STARTTLS = "starttls"
3232
3333
3434@dataclass (frozen = True )
35- class StrategyPluginGoogleVoiceSettings :
35+ class StrategyPluginEmailSettings :
3636 recipients : tuple [str , ...] = ()
3737 sender_email : str | None = None
3838 sender_password : str | None = field (default = None , repr = False )
39- smtp_host : str = _DEFAULT_GOOGLE_VOICE_SMTP_HOST
40- smtp_port : int = _DEFAULT_GOOGLE_VOICE_SMTP_PORT
41- smtp_security : str = _DEFAULT_GOOGLE_VOICE_SMTP_SECURITY
39+ smtp_host : str = _DEFAULT_EMAIL_SMTP_HOST
40+ smtp_port : int = _DEFAULT_EMAIL_SMTP_PORT
41+ smtp_security : str = _DEFAULT_EMAIL_SMTP_SECURITY
4242 timeout : float = 10.0
4343
4444 @classmethod
45- def from_object (cls , value : object ) -> "StrategyPluginGoogleVoiceSettings " :
45+ def from_object (cls , value : object ) -> "StrategyPluginEmailSettings " :
4646 if isinstance (value , cls ):
4747 return value
4848 return cls (
4949 recipients = tuple (
50- parse_email_recipients (_get_value (value , "crisis_alert_google_voice_recipients " , ()))
50+ parse_email_recipients (_get_value (value , "crisis_alert_email_recipients " , ()))
5151 ),
52- sender_email = _first_non_empty (_get_value (value , "crisis_alert_google_voice_sender_email " )),
53- sender_password = _get_value (value , "crisis_alert_google_voice_sender_password " ),
52+ sender_email = _first_non_empty (_get_value (value , "crisis_alert_email_sender_email " )),
53+ sender_password = _get_value (value , "crisis_alert_email_sender_password " ),
5454 smtp_host = _first_non_empty (
55- _get_value (value , "crisis_alert_google_voice_smtp_host " )
55+ _get_value (value , "crisis_alert_email_smtp_host " )
5656 )
57- or _DEFAULT_GOOGLE_VOICE_SMTP_HOST ,
57+ or _DEFAULT_EMAIL_SMTP_HOST ,
5858 smtp_port = _coerce_int (
59- _get_value (value , "crisis_alert_google_voice_smtp_port " ),
60- _DEFAULT_GOOGLE_VOICE_SMTP_PORT ,
59+ _get_value (value , "crisis_alert_email_smtp_port " ),
60+ _DEFAULT_EMAIL_SMTP_PORT ,
6161 ),
6262 smtp_security = _coerce_smtp_security (
63- _get_value (value , "crisis_alert_google_voice_smtp_security " )
63+ _get_value (value , "crisis_alert_email_smtp_security " )
6464 ),
6565 )
6666
6767 def missing_fields (self ) -> tuple [str , ...]:
6868 missing : list [str ] = []
6969 if not parse_email_recipients (self .recipients ):
70- missing .append ("CRISIS_ALERT_GOOGLE_VOICE_RECIPIENTS " )
70+ missing .append ("CRISIS_ALERT_EMAIL_RECIPIENTS " )
7171 if not str (self .sender_email or "" ).strip ():
72- missing .append ("CRISIS_ALERT_GOOGLE_VOICE_SENDER_EMAIL " )
72+ missing .append ("CRISIS_ALERT_EMAIL_SENDER_EMAIL " )
7373 if not str (self .sender_password or "" ).strip ():
74- missing .append ("CRISIS_ALERT_GOOGLE_VOICE_SENDER_PASSWORD " )
74+ missing .append ("CRISIS_ALERT_EMAIL_SENDER_PASSWORD " )
7575 return tuple (missing )
7676
7777 @property
@@ -80,7 +80,7 @@ def is_configured(self) -> bool:
8080
8181
8282@dataclass (frozen = True )
83- class StrategyPluginGoogleVoiceAlertDelivery :
83+ class StrategyPluginEmailAlertDelivery :
8484 alert_key : str
8585 subject : str
8686 status : str
@@ -101,8 +101,8 @@ def to_dict(self) -> dict[str, Any]:
101101
102102
103103@dataclass (frozen = True )
104- class StrategyPluginGoogleVoiceAlertPublishResult :
105- deliveries : tuple [StrategyPluginGoogleVoiceAlertDelivery , ...] = ()
104+ class StrategyPluginEmailAlertPublishResult :
105+ deliveries : tuple [StrategyPluginEmailAlertDelivery , ...] = ()
106106
107107 @property
108108 def attempted_count (self ) -> int :
@@ -120,7 +120,7 @@ def skipped_count(self) -> int:
120120 def failed_count (self ) -> int :
121121 return sum (1 for delivery in self .deliveries if delivery .status == "failed" )
122122
123- def to_report_fields (self , * , prefix : str = "strategy_plugin_alert_google_voice " ) -> dict [str , Any ]:
123+ def to_report_fields (self , * , prefix : str = "strategy_plugin_alert_email " ) -> dict [str , Any ]:
124124 return {
125125 f"{ prefix } _attempted_count" : self .attempted_count ,
126126 f"{ prefix } _sent_count" : self .sent_count ,
@@ -131,11 +131,11 @@ def to_report_fields(self, *, prefix: str = "strategy_plugin_alert_google_voice"
131131
132132
133133@dataclass (frozen = True )
134- class StrategyPluginGoogleVoiceAlertMarkerStore :
134+ class StrategyPluginEmailAlertMarkerStore :
135135 local_dir : str | Path | None = None
136136 gcs_prefix_uri : str | None = None
137137 gcp_project_id : str | None = None
138- namespace : str = "strategy_plugin_google_voice_alerts "
138+ namespace : str = "strategy_plugin_email_alerts "
139139 client_factory : Any = None
140140
141141 def has_alert (self , alert_key : str ) -> bool :
@@ -152,7 +152,7 @@ def record_alert(
152152 metadata : Mapping [str , Any ] | None = None ,
153153 ) -> None :
154154 payload = {
155- "schema_version" : "strategy_plugin_google_voice_alert_marker .v1" ,
155+ "schema_version" : "strategy_plugin_email_alert_marker .v1" ,
156156 "alert_key" : str (alert_key ),
157157 "recorded_at" : datetime .now (timezone .utc ).isoformat (),
158158 "metadata" : dict (metadata or {}),
@@ -215,38 +215,38 @@ def build_strategy_plugin_alert_context_label(
215215 return " / " .join (str (part ).strip () for part in parts if str (part or "" ).strip ())
216216
217217
218- def publish_strategy_plugin_google_voice_alerts (
218+ def publish_strategy_plugin_email_alerts (
219219 signals : Sequence [object ],
220220 * ,
221- google_voice_settings : StrategyPluginGoogleVoiceSettings | object ,
221+ email_settings : StrategyPluginEmailSettings | object ,
222222 translator : Callable [..., str ] | None = None ,
223223 strategy_label : str | None = None ,
224224 context_label : str | None = None ,
225- alert_store : StrategyPluginGoogleVoiceAlertMarkerStore | object | None = None ,
225+ alert_store : StrategyPluginEmailAlertMarkerStore | object | None = None ,
226226 send_notification : Callable [..., bool ] = send_smtp_email ,
227227 log_message : Callable [..., Any ] = print ,
228- ) -> StrategyPluginGoogleVoiceAlertPublishResult :
229- settings = StrategyPluginGoogleVoiceSettings .from_object (google_voice_settings )
228+ ) -> StrategyPluginEmailAlertPublishResult :
229+ settings = StrategyPluginEmailSettings .from_object (email_settings )
230230 messages = build_strategy_plugin_alert_messages (
231231 signals ,
232232 translator = translator ,
233233 strategy_label = strategy_label ,
234234 context_label = context_label ,
235- alert_namespace = "strategy_plugin_google_voice_alert " ,
235+ alert_namespace = "strategy_plugin_email_alert " ,
236236 )
237- deliveries : list [StrategyPluginGoogleVoiceAlertDelivery ] = []
237+ deliveries : list [StrategyPluginEmailAlertDelivery ] = []
238238 missing_fields = settings .missing_fields ()
239239 if missing_fields :
240240 for message in messages :
241241 deliveries .append (
242242 _delivery (
243243 message ,
244244 status = "skipped" ,
245- reason = "missing_google_voice_config " ,
245+ reason = "missing_email_config " ,
246246 error = "," .join (missing_fields ),
247247 )
248248 )
249- result = StrategyPluginGoogleVoiceAlertPublishResult (tuple (deliveries ))
249+ result = StrategyPluginEmailAlertPublishResult (tuple (deliveries ))
250250 _log_publish_result (result , log_message = log_message )
251251 return result
252252
@@ -268,7 +268,7 @@ def publish_strategy_plugin_google_voice_alerts(
268268 record_error = _store_record_error (alert_store , alert_key , message )
269269 combined_error = "; " .join (error for error in (store_error , record_error ) if error )
270270 deliveries .append (_delivery (message , status = "sent" , error = combined_error or None ))
271- result = StrategyPluginGoogleVoiceAlertPublishResult (tuple (deliveries ))
271+ result = StrategyPluginEmailAlertPublishResult (tuple (deliveries ))
272272 _log_publish_result (result , log_message = log_message )
273273 return result
274274
@@ -279,8 +279,8 @@ def _delivery(
279279 status : str ,
280280 reason : str | None = None ,
281281 error : str | None = None ,
282- ) -> StrategyPluginGoogleVoiceAlertDelivery :
283- return StrategyPluginGoogleVoiceAlertDelivery (
282+ ) -> StrategyPluginEmailAlertDelivery :
283+ return StrategyPluginEmailAlertDelivery (
284284 alert_key = message .alert_key or _fallback_alert_key (message ),
285285 subject = message .subject ,
286286 status = status ,
@@ -293,7 +293,7 @@ def _delivery(
293293def _send_message (
294294 send_notification : Callable [..., bool ],
295295 message : StrategyPluginAlertMessage ,
296- settings : StrategyPluginGoogleVoiceSettings ,
296+ settings : StrategyPluginEmailSettings ,
297297) -> tuple [bool , str | None ]:
298298 try :
299299 sent = send_notification (
@@ -347,7 +347,7 @@ def _store_record_error(
347347
348348
349349def _log_publish_result (
350- result : StrategyPluginGoogleVoiceAlertPublishResult ,
350+ result : StrategyPluginEmailAlertPublishResult ,
351351 * ,
352352 log_message : Callable [..., Any ],
353353) -> None :
@@ -356,7 +356,7 @@ def _log_publish_result(
356356 _call_log_message (
357357 log_message ,
358358 (
359- "strategy_plugin_alert_google_voice_result "
359+ "strategy_plugin_alert_email_result "
360360 f"attempted={ result .attempted_count } "
361361 f"sent={ result .sent_count } "
362362 f"skipped={ result .skipped_count } "
@@ -400,11 +400,11 @@ def _coerce_smtp_security(value: Any) -> str:
400400 security = str (value or "" ).strip ().lower ()
401401 if security in _SMTP_SECURITY_VALUES :
402402 return security
403- return _DEFAULT_GOOGLE_VOICE_SMTP_SECURITY
403+ return _DEFAULT_EMAIL_SMTP_SECURITY
404404
405405
406406def _fallback_alert_key (message : StrategyPluginAlertMessage ) -> str :
407- return "strategy_plugin_google_voice_alert /" + _clean_relative_key (message .subject or "unknown" )
407+ return "strategy_plugin_email_alert /" + _clean_relative_key (message .subject or "unknown" )
408408
409409
410410def _clean_relative_key (value : str ) -> str :
0 commit comments