Whatsappy is a Python library for creating whatsapp bots.
Creator: Italo Seara
Use the package manager pip to install whatsappy.
pip install whatsappy-py
from whatsappy import Whatsapp
whatsapp = Whatsapp()
whatsapp.login(visible=False) # Login whatsapp (Headless mode)
chat = whatsapp.chat('Mom') # Goes to the selected chat
chat.send('Hello') # Send a message
whatsapp.close() # Exit
from whatsappy import Whatsapp
whatsapp = Whatsapp() # Initialize the library
whatsapp.login(visible=False, timeout=0)
Arguments | Type | Default |
---|---|---|
visible | bool | False |
timeout | int | 0 |
P.S: timeout
should be in seconds
Successfully logged in
whatsapp.close() # Closes the webdriver
whatsapp.chat(name="Mom") # Opens the conversation
Arguments | Type | Default |
---|---|---|
name | str | - |
-
Properties
Property Type Default name str "" description str "" profile_picture str None invite_link str None admin bool False participants List[str] [] last_message Any - P.S.:
last_message
will be explained later on -
Functions
-
send
->None
: Sends a message to the chatArguments Type Default message str "" file str "" P.S.:
file
shoud be a file pathgroup.send(message="Hi <@Mom>!", file="flowers.jpg") # Use <@Contact Name> to mention someone
-
add
->None
: Adds new participants to the groupArguments Type Default contacts List[str] - group.add(["Grandma", "Cousin"])
-
remove
->None
: Removes participants from the groupArguments Type Default contacts List[str] - group.remove(["Boring Cousin"])
-
promote
->None
: Promotes participants to adminArguments Type Default contacts List[str] - group.promote(["Dad", "Mom"])
-
demote
->None
: Demotes participants to memberArguments Type Default contacts List[str] - group.demote(["Brother"])
-
leave
->None
: Leaves the groupArguments Type Default - - - group.leave()
-
-
Properties
Property Type Default name str "" number str "" about str "" profile_picture str None last_message Any - P.S.:
last_message
will be explained later on -
Functions
-
send
->None
: Sends a message to the chatArguments Type Default message str "" file str "" P.S.:
file
shoud be a file pathgroup.send(message="Hi <@Mom>!", file="flowers.jpg") # Use <@Contact Name> to mention someone
-
The last_message
property of a chat will return the type of the message (Location, Text, Contact card, etc.) as a class, it can be:
-
Properties
Property Type Default text str "" chat Any None author str None time datetime None forwarded bool False quote Quote - Quote.text str - Quote.author str - -
Functions
-
forward
->None
: Forward the message to a list of contactsArguments Type Default contacts List[str] - message.forward(["Mom", "Grandma"])
-
reply
->None
: Reply the message quoting the original oneArguments Type Default message str "" file str "" P.S.:
file
should be a file pathmessage.reply("Wow, that's awesome!")
-
reply_privately
->None
: Reply the message in private chat (Only works on groups)Arguments Type Default message str "" file str "" P.S.:
file
should be a file pathmessage.reply_privately("Long time since i saw you, huh?")
-
delete
->None
: Deletes the message only for youArguments Type Default - - - message.delete()
-
star
->None
: Stars the message for youArguments Type Default - - - message.star()
-
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default file File None File.size int 0 File.name str "" File.mimetype str "" File.content bytes b""
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default length int 0
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default file File None File.size int 0 File.length int 0 File.content bytes b"" isrecorded bool False
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default contacts List[Contact] [] Contact.name str "" Contact.numbers List[str] []
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default coords tuple () link str ""
Inherits all the Location
properties and functions
-
Properties
Arguments Type Default until datetime None
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default file File None File.size int 0 File.resolution tuple () File.content bytes b""
Inherits all the Image
properties and functions
-
Properties
Arguments Type Default - - -
group = whatsapp.new_group(
name="Family Group",
contacts=["Mom", "Dad", "Grandma", "+17873375275"]
)
print(group)
Whatsapp.Group(
name="Family Group",
description="",
profile_picture=None,
invite_link="https://chat.whatsapp.com/J6SwpsK5jzq5h0e5Tx3gBu",
admin=True
)
group = whatsapp.chat("Family Group")
group.name = "My Family" # Changes group name
group.description = "This is a family group" # Changes group description
group.profile_picture = "Family.jpeg" # Changes group profile picture
print(group)
Whatsapp.Group(
name="My Family",
description="This is a family group",
profile_picture="https://pps.whatsapp.net/v/t61.24694-24/187559880_805785283641101_6215437820834613111_n.jpg?ccb=11-4&oh=01_AVxyUwoLnQVdZ1bxDOx2zhYMWKKRitosP3wH-tILL8JNMw&oe=61F7B127",
invite_link="https://chat.whatsapp.com/J6SwpsK5jzq5h0e5Tx3gBu",
admin=True
)
contacts = whatsapp.contact_list
print(contacts)
["Mom", "Dad", "Cousin", "Friend", ...]
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.