Skip to main content

Whatsappy is a Python library for creating whatsapp bots.

Project description

whatsappy

Downloads

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

QRCode

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 chat

      Arguments Type Default
      message str ""
      file str ""

      P.S.: file shoud be a file path

      group.send(message="Hi <@Mom>!", file="flowers.jpg") # Use <@Contact Name> to mention someone
      
    • add -> None: Adds new participants to the group

      Arguments Type Default
      contacts List[str] -
      group.add(["Grandma", "Cousin"])
      
    • remove -> None: Removes participants from the group

      Arguments Type Default
      contacts List[str] -
      group.remove(["Boring Cousin"])
      
    • promote -> None: Promotes participants to admin

      Arguments Type Default
      contacts List[str] -
      group.promote(["Dad", "Mom"])
      
    • demote -> None: Demotes participants to member

      Arguments Type Default
      contacts List[str] -
      group.demote(["Brother"])
      
    • leave -> None: Leaves the group

      Arguments 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 chat

      Arguments Type Default
      message str ""
      file str ""

      P.S.: file shoud be a file path

      group.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 contacts

      Arguments Type Default
      contacts List[str] -
      message.forward(["Mom", "Grandma"])
      
    • reply -> None: Reply the message quoting the original one

      Arguments Type Default
      message str ""
      file str ""

      P.S.: file should be a file path

      message.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 path

      message.reply_privately("Long time since i saw you, huh?")
      
    • delete -> None: Deletes the message only for you

      Arguments Type Default
      - - -
      message.delete()
      
    • star -> None: Stars the message for you

      Arguments 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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whatsappy-py-3.3.2.tar.gz (17.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page