Use Python to send a WhatsApp message to someone.
Here's how you can send a WhatsApp message to someone using Python and the pywhatkit library:
Step-by-Step Guide
Step 1: Install the Required Library
First, install the pywhatkit
library if you haven't already:
pip install pywhatkit
Step 2: Write the Python Script
Below is the Python script to send a WhatsApp message:
import pywhatkit as kit
# Parameters
phone_number = "+1234567890" # Replace with recipient's phone number (with country code)
message = "Hello! This is a message sent using Python. ๐" # Your message
hour = 14 # Hour in 24-hour format
minute = 30 # Minute
try:
# Schedule the message
kit.sendwhatmsg(phone_number, message, hour, minute)
print("Message successfully sent!")
except Exception as e:
print(f"An error occurred: {e}")
How It Works
kit.sendwhatmsg
Parameters:phone_number
: The recipient's WhatsApp number (include the country code).message
: The text you want to send.hour
andminute
: When to send the message.
Execution:
The script will open WhatsApp Web in your default browser.
The message will be sent automatically at the specified time.
Ensure:
Your system has a stable internet connection.
You're logged into WhatsApp Web on your browser.
Additional Features of pywhatkit
Send Messages to Groups:
Usekit.sendwhatmsg_to_group("GroupID", "Message", Hour, Minute)
.Instant Message Sending:
Usekit.sendwhatmsg_instantly(phone_number, "Message")
.Message with Media:
Usekit.sendwhats_image(phone_number, "Path_to_Image", "Caption")
.
Output
The program will automatically open WhatsApp Web and send the message at the scheduled time.
Let me know if you encounter any issues or need further assistance! ๐