Whatsappy is a Python library for creating whatsapp bots.
Project description
whatsappy
Whatsappy is a Python library for creating whatsapp bots.
Creator: Italo Seara
Installation
Use the package manager pip to install whatsappy.
pip install whatsappy-py
Usage
Basic example:
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
1. Setup
from whatsappy import Whatsapp
whatsapp = Whatsapp() # Initialize the library
2. Login
Input
whatsapp.login(visible=False, timeout=0)
Arguments | Type | Default |
---|---|---|
visible | bool | False |
timeout | int | 0 |
P.S: timeout
should be in seconds
Output
After you scan it, you should wait for a message like this:
Successfully logged in
3. Close
whatsapp.close() # Closes the webdriver
4.1 Chat
Input
whatsapp.chat(name="Mom") # Opens the conversation
Arguments | Type | Default |
---|---|---|
name | str | - |
Output
Group
-
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()
-
Contact
-
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
-
4.2 Message
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:
Text
-
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()
-
Document
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""
Video
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default length int 0
Audio
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
ContactCard
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default contacts List[Contact] [] Contact.name str "" Contact.numbers List[str] []
Location
Inherits all the Text
properties and functions
-
Properties
Arguments Type Default coords tuple () link str ""
LiveLocation
Inherits all the Location
properties and functions
-
Properties
Arguments Type Default until datetime None
Image
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""
Sticker
Inherits all the Image
properties and functions
-
Properties
Arguments Type Default - - -
Create a new Group
Input
group = whatsapp.new_group(
name="Family Group",
contacts=["Mom", "Dad", "Grandma", "+17873375275"]
)
print(group)
Output
Whatsapp.Group(
name="Family Group",
description="",
profile_picture=None,
invite_link="https://chat.whatsapp.com/J6SwpsK5jzq5h0e5Tx3gBu",
admin=True
)
Change group information
Input
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)
Output
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
)
Get all your contacts
Input
contacts = whatsapp.contact_list
print(contacts)
Output
["Mom", "Dad", "Cousin", "Friend", ...]
Contributing
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.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.