1+ import os
12import time
23import webbrowser as web
34from datetime import datetime
45from re import fullmatch
56from typing import List
67from urllib .parse import quote
7-
8+ import paperclip
89import pyautogui as pg
9-
10+ import pyperclip
11+ import keyboard
1012from pywhatkit .core import core , exceptions , log
1113
1214pg .FAILSAFE = False
1517
1618
1719def sendwhatmsg_instantly (
18- phone_no : str ,
19- message : str ,
20- wait_time : int = 15 ,
21- tab_close : bool = False ,
22- close_time : int = 3 ,
20+ phone_no : str ,
21+ message : str ,
22+ wait_time : int = 15 ,
23+ tab_close : bool = False ,
24+ close_time : int = 3 ,
2325) -> None :
2426 """Send WhatsApp Message Instantly"""
2527
@@ -41,14 +43,90 @@ def sendwhatmsg_instantly(
4143 core .close_tab (wait_time = close_time )
4244
4345
46+ def sendimg_or_video_immediately (
47+ phone_no : str ,
48+ path : str ,
49+ wait_time : int = 15 ,
50+ tab_close : bool = False ,
51+ close_time : int = 3 ,
52+ ) -> None :
53+ """Send WhatsApp Message Instantly"""
54+
55+ if not core .check_number (number = phone_no ):
56+ raise exceptions .CountryCodeException ("Country Code Missing in Phone Number!" )
57+
58+ phone_no = phone_no .replace (" " , "" )
59+ if not fullmatch (r"^\+?[0-9]{2,4}\s?[0-9]{9,15}" , phone_no ):
60+ raise exceptions .InvalidPhoneNumber ("Invalid Phone Number." )
61+
62+ web .open (f"https://web.whatsapp.com/send?phone={ phone_no } " )
63+ time .sleep (wait_time )
64+ core .find_link ()
65+ time .sleep (1 )
66+ core .find_photo_or_video ()
67+
68+ pyperclip .copy (os .path .abspath (path ))
69+ print ("Copied" )
70+ time .sleep (1 )
71+ keyboard .press ("ctrl" )
72+ keyboard .press ("v" )
73+ keyboard .release ("v" )
74+ keyboard .release ("ctrl" )
75+ time .sleep (1 )
76+ keyboard .press ("enter" )
77+ keyboard .release ("enter" )
78+ time .sleep (1 )
79+ keyboard .press ("enter" )
80+ keyboard .release ("enter" )
81+ if tab_close :
82+ core .close_tab (wait_time = close_time )
83+
84+ def sendwhatdoc_immediately (
85+ phone_no : str ,
86+ path : str ,
87+ wait_time : int = 15 ,
88+ tab_close : bool = True ,
89+ close_time : int = 3 ,
90+ ) -> None :
91+ """Send WhatsApp Message Instantly"""
92+
93+ if not core .check_number (number = phone_no ):
94+ raise exceptions .CountryCodeException ("Country Code Missing in Phone Number!" )
95+
96+ phone_no = phone_no .replace (" " , "" )
97+ if not fullmatch (r"^\+?[0-9]{2,4}\s?[0-9]{9,15}" , phone_no ):
98+ raise exceptions .InvalidPhoneNumber ("Invalid Phone Number." )
99+
100+ web .open (f"https://web.whatsapp.com/send?phone={ phone_no } " )
101+ time .sleep (wait_time )
102+ core .find_link ()
103+ time .sleep (1 )
104+ core .find_document ()
105+ pyperclip .copy (os .path .abspath (path ))
106+ print ("Copied" )
107+ time .sleep (1 )
108+ keyboard .press ("ctrl" )
109+ keyboard .press ("v" )
110+ keyboard .release ("v" )
111+ keyboard .release ("ctrl" )
112+ time .sleep (1 )
113+ keyboard .press ("enter" )
114+ keyboard .release ("enter" )
115+ time .sleep (1 )
116+ keyboard .press ("enter" )
117+ keyboard .release ("enter" )
118+ if tab_close :
119+ core .close_tab (wait_time = close_time )
120+
121+
44122def sendwhatmsg (
45- phone_no : str ,
46- message : str ,
47- time_hour : int ,
48- time_min : int ,
49- wait_time : int = 15 ,
50- tab_close : bool = False ,
51- close_time : int = 3 ,
123+ phone_no : str ,
124+ message : str ,
125+ time_hour : int ,
126+ time_min : int ,
127+ wait_time : int = 15 ,
128+ tab_close : bool = False ,
129+ close_time : int = 3 ,
52130) -> None :
53131 """Send a WhatsApp Message at a Certain Time"""
54132 if not core .check_number (number = phone_no ):
@@ -86,13 +164,13 @@ def sendwhatmsg(
86164
87165
88166def sendwhatmsg_to_group (
89- group_id : str ,
90- message : str ,
91- time_hour : int ,
92- time_min : int ,
93- wait_time : int = 15 ,
94- tab_close : bool = False ,
95- close_time : int = 3 ,
167+ group_id : str ,
168+ message : str ,
169+ time_hour : int ,
170+ time_min : int ,
171+ wait_time : int = 15 ,
172+ tab_close : bool = False ,
173+ close_time : int = 3 ,
96174) -> None :
97175 """Send WhatsApp Message to a Group at a Certain Time"""
98176
@@ -124,11 +202,11 @@ def sendwhatmsg_to_group(
124202
125203
126204def sendwhatmsg_to_group_instantly (
127- group_id : str ,
128- message : str ,
129- wait_time : int = 15 ,
130- tab_close : bool = False ,
131- close_time : int = 3 ,
205+ group_id : str ,
206+ message : str ,
207+ wait_time : int = 15 ,
208+ tab_close : bool = False ,
209+ close_time : int = 3 ,
132210) -> None :
133211 """Send WhatsApp Message to a Group Instantly"""
134212
@@ -141,13 +219,13 @@ def sendwhatmsg_to_group_instantly(
141219
142220
143221def sendwhatsmsg_to_all (
144- phone_nos : List [str ],
145- message : str ,
146- time_hour : int ,
147- time_min : int ,
148- wait_time : int = 15 ,
149- tab_close : bool = False ,
150- close_time : int = 3 ,
222+ phone_nos : List [str ],
223+ message : str ,
224+ time_hour : int ,
225+ time_min : int ,
226+ wait_time : int = 15 ,
227+ tab_close : bool = False ,
228+ close_time : int = 3 ,
151229):
152230 for phone_no in phone_nos :
153231 sendwhatmsg (
@@ -156,14 +234,14 @@ def sendwhatsmsg_to_all(
156234
157235
158236def sendwhats_image (
159- receiver : str ,
160- img_path : str ,
161- time_hour : int ,
162- time_min : int ,
163- caption : str = "" ,
164- wait_time : int = 15 ,
165- tab_close : bool = False ,
166- close_time : int = 3 ,
237+ receiver : str ,
238+ img_path : str ,
239+ time_hour : int ,
240+ time_min : int ,
241+ caption : str = "" ,
242+ wait_time : int = 15 ,
243+ tab_close : bool = False ,
244+ close_time : int = 3 ,
167245) -> None :
168246 """Send Image to a WhatsApp Contact or Group at a Certain Time"""
169247
0 commit comments