A lightweight, Python-based WhatsApp bot powered by Green‑API that listens to your specified chats in real time and automatically saves every attachment—images, documents, audio, video, and more—to your local (or cloud) storage. Perfect for archiving media without lifting a finger.
This solution leverages the following technologies:
Before proceeding with the setup, ensure that you have the following:
- Docker and Docker Compose installed
- A registered Green API Account
-
Visit https://green-api.com/en and register for a new account.
-
Complete the registration form by entering your details and then click Register.
-
Once registered, select Create an instance.
-
Choose the Developer instance (Free Tier).
-
Copy the generated InstanceId and Token—these will be required for integration.
-
To link your WhatsApp account, navigate to the API section on the left under Account and select QR. Open the provided QR URL in your browser, then click on Scan QR code:
-
Scan the QR code to complete the linking process:
-
Once linked, the instance status will display a green light, indicating it is active:
Important: Do not configure a webhook URL for your instance, as this will interfere with the bot’s functionality.
- Duplicate the sample environment file by running:
cp .env.example .env
- Edit the
.env
file with your credentials:
# WhatsApp API Credentials
GREEN_API_INSTANCE=your_whatsapp_instance_id
GREEN_API_TOKEN=your_whatsapp_api_token
- Use the following docker-compose.yaml :
services:
whatsapp-media-vault:
container_name: whatsapp-media-vault
image: techblog/whatsapp-media-vault:latest
ports:
- "7020:7020"
environment:
- GREEN_API_INSTANCE=${GREEN_API_INSTANCE}
- GREEN_API_TOKEN=${GREEN_API_TOKEN}
volumes:
- ./whatsapp-media/vault:/app/vault
restart: unless-stopped
Where:
- ./whatsapp-media/vault is the volume for the saved attacments.
-
Start the application:
docker-compose up -d
-
The application will be available at
http://[Server_IP]:[Port]
Under the config folder you will find a file named config.yaml with the following content:
chats:
GroupName:
media_path: Path_to_save_content
chat_ids:
- 97200000000000011111111@g.us
- 97200000000000011111111@c.us
- GroupName: The name of the group/commnity (Free text)
- media_path: The base path for saving the files (Relative, the bot will create it under the vault path.).
- chat_ids: list of whatsapp chats (Groups or Contacts) to monitor.
In order to get the list of groups, enter the following URL: http://[server_ip]:[port]/contacts
The web page will contain a table with the list of contacts and group:
⚠️ IMPORTANT⚠️ : After updating the config file, restart the container to reload the configuration
The images will be saved in the following structure
vault
|──group/
├── image/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ...
├── video/
│ ├── video1.mp4
│ └── ...
└── documents/
├── doc1.doc
└── pdf1.pdf
Congrats, you can now use the bot.