forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhatsappBot.py
63 lines (53 loc) · 1.84 KB
/
WhatsappBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pywhatkit
import datetime
import random
import re
def validate_phone_number(number):
pattern = re.compile(r"^\+\d{1,3}\d{10}$")
return pattern.match(number)
def send_otp(number):
otp = random.randint(100000, 999999)
message = f"Dear Customer, your OTP is {otp}. Do not share it with anyone."
pywhatkit.sendwhatmsg_instantly(number, message)
print("OTP sent successfully.")
def send_custom_message(number):
message = input("Enter your custom message: ")
pywhatkit.sendwhatmsg_instantly(number, message)
print("Custom message sent successfully.")
def send_scheduled_message(number):
message = input("Enter your message: ")
hour = int(input("Enter the hour (24-hour format): "))
minute = int(input("Enter the minute: "))
pywhatkit.sendwhatmsg(number, message, hour, minute)
print("Message scheduled successfully.")
def main():
# Password check
correct_password = "password123"
password = input("Enter the password: ")
if password != correct_password:
print("Incorrect password. Access denied.")
return
number = input("Enter the phone number (with country code): ")
if not validate_phone_number(number):
print("Invalid phone number format. Please enter a valid number.")
return
print("""Choose your option:
1. Send OTP
2. Send Custom Message
3. Send a message at a particular time
""")
try:
choice = int(input("Enter your choice: "))
except ValueError:
print("Invalid input. Please enter a number between 1 and 3.")
return
if choice == 1:
send_otp(number)
elif choice == 2:
send_custom_message(number)
elif choice == 3:
send_scheduled_message(number)
else:
print("Invalid choice. Please enter a number between 1 and 3.")
if __name__ == "__main__":
main()