@@ -44,11 +44,11 @@ def send_follow_up_message(
4444 if template_content :
4545 message = render_template (session , template_content , profile )
4646
47- if _send_msg_pop_up (session , profile , message ) or _send_message (session , profile , message ):
48- logger .debug ("Message body: %s" , message )
49- return message
47+ if not _send_msg_pop_up (session , profile , message ):
48+ _send_message (session , profile , message )
5049
51- return None
50+ logger .debug ("Message body: %s" , message )
51+ return message
5252
5353
5454def _send_msg_pop_up (session : "AccountSession" , profile : Dict [str , Any ], message : str ) -> bool :
@@ -108,27 +108,21 @@ def _send_message(session: "AccountSession", profile: Dict[str, Any], message: s
108108 timeout = 30_000 ,
109109 error_message = "Error opening messaging" ,
110110 )
111- try :
112- # Search person
113- human_type (session .page .locator (SELECTORS ["connections_input" ]), full_name )
114- session .wait (0.5 , 1 )
111+ # Search person
112+ human_type (session .page .locator (SELECTORS ["connections_input" ]), full_name , min_delay = 10 , max_delay = 50 )
113+ session .wait (0.5 , 1 )
115114
116- item = session .page .locator (SELECTORS ["search_result_row" ]).first
117- session .wait (0.5 , 1 )
115+ item = session .page .locator (SELECTORS ["search_result_row" ]).first
116+ session .wait (0.5 , 1 )
118117
119- # Scroll into view + click (very reliable on LinkedIn)
120- item .scroll_into_view_if_needed ()
121- item .click (delay = 200 ) # small delay between mousedown/mouseup = very human
118+ # Scroll into view + click (very reliable on LinkedIn)
119+ item .scroll_into_view_if_needed ()
120+ item .click (delay = 200 ) # small delay between mousedown/mouseup = very human
122121
123- human_type (session .page .locator (SELECTORS ["compose_input" ]), message )
122+ human_type (session .page .locator (SELECTORS ["compose_input" ]), message , min_delay = 10 , max_delay = 50 )
124123
125- session .page .locator (SELECTORS ["compose_send" ]).click (delay = 200 )
126- session .wait (0.5 , 1 )
127- return True
128- except Exception as e :
129- public_identifier = profile .get ("public_identifier" )
130- logger .error ("Failed to send message to %s → %s" , public_identifier , e )
131- return False
124+ session .page .locator (SELECTORS ["compose_send" ]).click (delay = 200 )
125+ session .wait (0.5 , 1 )
132126
133127
134128if __name__ == "__main__" :
0 commit comments