WhatsApp integration for Agntrick agents
Project description
agntrick-whatsapp
WhatsApp integration for Agntrick agents. Connect LLM's to your personal WhatsApp account with QR code login.
Installation
pip install agntrick-whatsapp
Features
- WhatsApp Channel: Bidirectional communication via personal WhatsApp account
- QR Code Login: Easy authentication with your phone
- Router Agent: Routes messages to different specialist modes based on commands
- Audio Transcription: Transcribe voice messages using Groq Whisper API
- Contact Filtering: Privacy-focused with allowed contacts only
- Scheduling: Schedule reminders and agent tasks with natural language time parsing
- Notes: Save and retrieve notes through WhatsApp
Requirements
System Dependencies
The WhatsApp channel uses neonize which requires:
- libmagic: For file type detection
- macOS:
brew install libmagic - Ubuntu/Debian:
sudo apt-get install libmagic1 - Fedora:
sudo dnf install file-devel
- macOS:
Audio Transcription (Optional)
For audio transcription, you need:
-
ffmpeg: For audio format conversion
- macOS:
brew install ffmpeg - Ubuntu/Debian:
sudo apt-get install ffmpeg - Fedora:
sudo dnf install ffmpeg
- macOS:
-
Groq API Key: Set
GROQ_AUDIO_API_KEYorGROQ_API_KEYenvironment variable
Quick Start
1. Install Dependencies
pip install agntrick-whatsapp
2. Create Configuration
Create a whatsapp.yaml configuration file:
# Agent model configuration
model: "glm-4.7"
# Channel configuration
channel:
storage_path: "./storage"
# Privacy and filtering - only allow your own number
privacy:
allowed_contact: "+12 6XX X6X XX6" # Your phone number
# Feature flags
features:
text_messages: true # Enable text messages
media_messages: true # Enable media (images, videos, documents, audio)
group_messages: false # Enable group messages
presence_updates: true # Enable presence (online/typing status)
typing_indicators: true # Send typing indicators when processing
# WhatsApp bridge settings
whatsapp_bridge:
auto_setup: true # Auto-clone Go bridge on first run
auto_connect: true # Auto-connect on startup
bridge_timeout_sec: 180 # Max wait for bridge startup
poll_interval_sec: 5 # Check for new messages every N seconds
# Logging
logging:
level: "INFO" # DEBUG, INFO, WARNING, ERROR
file: "./logs/agent.log" # Log file location
3. Run the WhatsApp Agent
Create a simple Python script run_whatsapp.py:
import asyncio
from pathlib import Path
from agntrick_whatsapp import WhatsAppChannel, WhatsAppRouterAgent
async def main():
# Create channel - storage is where session data is saved
channel = WhatsAppChannel(
storage_path="./storage",
allowed_contact="+34 6XX XXX XXX", # Your phone number
)
# Create and start the router agent
agent = WhatsAppRouterAgent(
channel=channel,
model_name="glm-4.7",
)
await agent.start()
asyncio.run(main())
Run it:
python run_whatsapp.py
4. Scan QR Code
On first run, you'll see a QR code in your terminal. Open WhatsApp on your phone:
- Go to Settings > Linked Devices
- Tap Link a Device
- Scan the QR code
That's it! Your agent is now connected and will respond to messages from your allowed contact.
Directory Structure Example
Here's how you can organize a project using the agntrick-whatsapp package:
~/code/agntrick/
├── whatsapp/
│ ├── run_whatsapp.py # Main entry point
│ ├── whatsapp.yaml # Configuration file
│ ├── storage/ # WhatsApp session data (created on first run)
│ └── logs/ # Application logs
└── prompts/ # Custom prompts for agents
The storage/ directory contains your WhatsApp session data after QR code login - you don't need to recreate this on subsequent runs.
First Time Setup
-
Install system dependencies (if needed):
# macOS brew install libmagic ffmpeg
-
Install the package:
pip install agntrick-whatsapp
-
Create your config file (
whatsapp.yaml):- Set your phone number in
allowed_contact - Choose a storage path for session data
- Set your phone number in
-
Run the agent:
python run_whatsapp.py -
Scan the QR code displayed in your terminal using WhatsApp:
- Open WhatsApp → Settings → Linked Devices → Link a Device
- Point your camera at the QR code
-
Start chatting! Send a message from your allowed contact number.
Session Persistence
After the first QR code login, your session is saved in the storage_path directory. On subsequent runs, you don't need to scan again - the agent will auto-connect using the saved session.
Resetting the Session
If you need to re-login (new phone number, etc.), simply delete the storage directory:
rm -rf ./storage
Then run python run_whatsapp.py again to scan a new QR code.
Commands
The router agent supports the following commands:
| Command | Description |
|---|---|
/learn <topic> |
Learning/tutorial mode |
/youtube <url> |
YouTube video analysis |
/remind <time> <message> |
Set a reminder |
/schedule <time> <agent> [task] |
Schedule an agent task |
/schedules |
List all scheduled tasks |
/note <content> |
Save a note |
/notes |
List all saved notes |
/help |
Show available commands |
Examples
/learn Python decorators- Get a step-by-step tutorial on Python decorators/youtube https://youtube.com/watch?v=xyz- Analyze a YouTube video/remind in 30 min check the oven- Set a reminder/schedule tomorrow 9am assistant summarize news- Schedule a task/note Remember to call mom- Save a noteWhat's the weather in Tokyo?- General question
Audio Transcription
Voice messages are automatically transcribed using Groq's Whisper API:
from agntrick_whatsapp import AudioTranscriber
transcriber = AudioTranscriber()
result = await transcriber.transcribe_audio("/path/to/voice.ogg")
print(result)
Configuration Reference
PrivacyConfig
| Field | Type | Required | Description |
|---|---|---|---|
allowed_contact |
str | Yes | Phone number to allow messages from |
log_filtered_messages |
bool | No | Log filtered messages for debugging |
FeatureFlags
| Field | Type | Default | Description |
|---|---|---|---|
text_messages |
bool | true | Enable text messages |
media_messages |
bool | true | Enable media messages |
group_messages |
bool | false | Enable group messages |
presence_updates |
bool | true | Enable presence updates |
typing_indicators |
bool | true | Send typing indicators |
AudioTranscriberConfig
| Field | Type | Default | Description |
|---|---|---|---|
model |
str | whisper-large-v3-turbo | Groq Whisper model |
timeout |
float | 60.0 | Request timeout in seconds |
config_file |
str? | None | Optional config file path |
Development
Setup
# Clone the repository
git clone https://github.com/jeancsil/agntrick-whatsapp.git
cd agntrick-whatsapp
# Install dependencies with uv (required for this project)
uv sync
# Run tests
make test
# Run linting
make check
# Format code
make format
Using as a Local Package
To use your local development version in another project:
cd ~/code/agntrick-whatsapp
uv pip install -e .
Now your other projects will use your local version.
Release
make release VERSION=0.4.0
Troubleshooting
Import Error: "neonize dependency is unavailable"
Install system dependencies and reinstall:
# macOS
brew install libmagic
pip install agntrick-whatsapp --force-reinstall
# Ubuntu/Debian
sudo apt-get install libmagic1
pip install agntrick-whatsapp --force-reinstall
QR Code Not Appearing
- Check storage path permissions - ensure the directory is writable
- Delete existing session:
rm -rf ./storage(triggers new QR code on next run) - Restart the agent
Session Lost / Need to Re-login
Delete the storage directory and run again:
rm -rf ./storage
python run_whatsapp.py
Audio Transcription Not Working
- Verify Groq API key is set:
echo $GROQ_AUDIO_API_KEY - Check ffmpeg is installed:
ffmpeg -version - Voice messages must be under 25MB
Messages Not Being Processed
- Check that your phone number exactly matches
allowed_contactin config - Verify logging level - set to
DEBUGin config to see what's happening - Check logs:
tail -f ./logs/agent.log
License
MIT
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.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agntrick_whatsapp-0.3.7.tar.gz.
File metadata
- Download URL: agntrick_whatsapp-0.3.7.tar.gz
- Upload date:
- Size: 306.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8daf377ba91e4862d2735f54e69cece5faf48eeec2a63ee0a08566cc15c9a987
|
|
| MD5 |
0f9babe1848d7637f1fe64673bbad41f
|
|
| BLAKE2b-256 |
09d712a6b0a6b03c8b33ca03ffdf8bae306e07d6dc65de70284eb1b49e756710
|
Provenance
The following attestation bundles were made for agntrick_whatsapp-0.3.7.tar.gz:
Publisher:
release.yml on jeancsil/agntrick-whatsapp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agntrick_whatsapp-0.3.7.tar.gz -
Subject digest:
8daf377ba91e4862d2735f54e69cece5faf48eeec2a63ee0a08566cc15c9a987 - Sigstore transparency entry: 1154491429
- Sigstore integration time:
-
Permalink:
jeancsil/agntrick-whatsapp@d96d6a0b6f8bf258db46ca0b137b7599175ed323 -
Branch / Tag:
refs/tags/v0.3.7 - Owner: https://github.com/jeancsil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d96d6a0b6f8bf258db46ca0b137b7599175ed323 -
Trigger Event:
release
-
Statement type:
File details
Details for the file agntrick_whatsapp-0.3.7-py3-none-any.whl.
File metadata
- Download URL: agntrick_whatsapp-0.3.7-py3-none-any.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
521e5033504c77e303e67540bdaa83caaedd31bf53e2e66bea1afe2bb181ae98
|
|
| MD5 |
0d599592532df6690db240769f6b1bbd
|
|
| BLAKE2b-256 |
baa0c6922e979e6e3a37845974d7866490c1703423f0cd59ea3c82650c6066a6
|
Provenance
The following attestation bundles were made for agntrick_whatsapp-0.3.7-py3-none-any.whl:
Publisher:
release.yml on jeancsil/agntrick-whatsapp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agntrick_whatsapp-0.3.7-py3-none-any.whl -
Subject digest:
521e5033504c77e303e67540bdaa83caaedd31bf53e2e66bea1afe2bb181ae98 - Sigstore transparency entry: 1154491431
- Sigstore integration time:
-
Permalink:
jeancsil/agntrick-whatsapp@d96d6a0b6f8bf258db46ca0b137b7599175ed323 -
Branch / Tag:
refs/tags/v0.3.7 - Owner: https://github.com/jeancsil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d96d6a0b6f8bf258db46ca0b137b7599175ed323 -
Trigger Event:
release
-
Statement type: