@@ -14,6 +14,19 @@ pub async fn send_email(
1414 subject : & str ,
1515 body : & str ,
1616) -> Result < ( ) , String > {
17+ if cfg. email_api_url . trim ( ) . is_empty ( )
18+ || cfg. email_api_key . trim ( ) . is_empty ( )
19+ || cfg. email_from . trim ( ) . is_empty ( )
20+ {
21+ return Err ( "email provider is not configured" . to_string ( ) ) ;
22+ }
23+ if to. trim ( ) . is_empty ( ) {
24+ return Err ( "email recipient is empty" . to_string ( ) ) ;
25+ }
26+ if subject. trim ( ) . is_empty ( ) || body. trim ( ) . is_empty ( ) {
27+ return Err ( "email content is empty" . to_string ( ) ) ;
28+ }
29+
1730 let client = Client :: new ( ) ;
1831 // SendGrid-compatible POST /v3/mail/send
1932 let payload = json ! ( {
@@ -46,6 +59,20 @@ pub async fn send_email(
4659}
4760
4861pub async fn send_sms ( cfg : & NotificationConfig , to : & str , body : & str ) -> Result < ( ) , String > {
62+ if cfg. sms_api_url . trim ( ) . is_empty ( )
63+ || cfg. sms_account_sid . trim ( ) . is_empty ( )
64+ || cfg. sms_auth_token . trim ( ) . is_empty ( )
65+ || cfg. sms_from . trim ( ) . is_empty ( )
66+ {
67+ return Err ( "sms provider is not configured" . to_string ( ) ) ;
68+ }
69+ if to. trim ( ) . is_empty ( ) {
70+ return Err ( "sms recipient is empty" . to_string ( ) ) ;
71+ }
72+ if body. trim ( ) . is_empty ( ) {
73+ return Err ( "sms content is empty" . to_string ( ) ) ;
74+ }
75+
4976 let client = Client :: new ( ) ;
5077 // Twilio-compatible POST /2010-04-01/Accounts/{sid}/Messages.json
5178 let url = format ! (
@@ -81,6 +108,19 @@ pub async fn send_push(
81108 title : & str ,
82109 body : & str ,
83110) -> Result < ( ) , String > {
111+ if cfg. push_api_url . trim ( ) . is_empty ( )
112+ || cfg. push_project_id . trim ( ) . is_empty ( )
113+ || cfg. push_server_key . trim ( ) . is_empty ( )
114+ {
115+ return Err ( "push provider is not configured" . to_string ( ) ) ;
116+ }
117+ if token. trim ( ) . is_empty ( ) {
118+ return Err ( "push token is empty" . to_string ( ) ) ;
119+ }
120+ if title. trim ( ) . is_empty ( ) || body. trim ( ) . is_empty ( ) {
121+ return Err ( "push content is empty" . to_string ( ) ) ;
122+ }
123+
84124 let client = Client :: new ( ) ;
85125 // FCM v1 HTTP API
86126 let payload = json ! ( {
@@ -102,7 +142,7 @@ pub async fn send_push(
102142 . map_err ( |e| e. to_string ( ) ) ?;
103143
104144 if res. status ( ) . is_success ( ) {
105- info ! ( "Push sent to token {}" , & token[ .. 8 ] ) ;
145+ info ! ( "Push sent to token {}" , token_preview ( token) ) ;
106146 Ok ( ( ) )
107147 } else {
108148 let msg = format ! (
@@ -114,3 +154,12 @@ pub async fn send_push(
114154 Err ( msg)
115155 }
116156}
157+
158+ fn token_preview ( token : & str ) -> & str {
159+ let end = token
160+ . char_indices ( )
161+ . nth ( 8 )
162+ . map ( |( idx, _) | idx)
163+ . unwrap_or ( token. len ( ) ) ;
164+ & token[ ..end]
165+ }
0 commit comments