WhatsApp skill package extracted from ia_orchestrator core
Project description
zafiro-skill-whatsapp
Autonomous WhatsApp skill package for the Zafiro orchestrator ecosystem.
This package is designed to run as an external skill pack with no direct imports from core app.* modules or other skill packages.
Documentation map
- Core integration guide:
docs/CORE_INTEGRATION.md - Full tools contract:
docs/TOOLS_REFERENCE.md - Skill manifest/prompt:
skills/whatsapp.md
What this package contains
- Skill manifest:
skills/whatsapp.md - Skill entry-point registrar:
zafiro_skill_whatsapp.extensions.skills.whatsapp:register_whatsapp_skill - Tool entry-point registrar:
zafiro_skill_whatsapp.extensions.tools.whatsapp_tools:register_whatsapp_tools - WhatsApp adapter split by domain (
runtime_ops,message_ops,contacts_ops,sync_ops) - Policy tools (outbound allowlist and inbound auto-reply controls)
- CLI helpers for
/wa-style commands - Local integration layer (
zafiro_skill_whatsapp.integrations) with optional host hooks
Adapter layout
src/zafiro_skill_whatsapp/
├── integrations.py # backward-compat facade + legacy path constants
├── admin.py # backward-compat facade
├── storage/ # ORM models, engine, queries (all ≤300 lines)
│ ├── models.py # SQLAlchemy models
│ ├── engine.py # session scope, account resolution
│ ├── messages.py # archive_whatsapp_payload, read_archived_messages
│ ├── directory.py # load/save contacts+groups JSON directory
│ ├── access_rules.py # allowlist CRUD
│ ├── hooks.py # HostRuntimeHooks, configure_host_runtime
│ ├── runtime.py # analyze_image, transcribe_audio, reset_storage_for_tests
│ └── utils.py # normalize helpers
├── admin/ # channel + sync admin commands
│ ├── channel.py # wa_is_running, wa_start, wa_stop, wa_recover
│ └── sync.py # wa_sync_full, wa_sync_all, wa_sync_auto_read_archive
├── adapters/whatsapp/ # WhatsApp protocol adapter
│ ├── runtime_ops/ # lifecycle, state, config, connection, types
│ ├── message_ops/ # inbound, outbound, processing, auto-reply, queue
│ ├── contacts_ops/ # directory, discovery (_is_real_phone guard), policy
│ └── sync_ops/ # history, history_ingest, rounds, sync_multi, orchestrator
└── extensions/
├── skills/ # skill entry-point registrar
└── tools/ # tool handlers split by domain
├── messaging_send.py # wa_send, wa_reply
├── messaging_read.py # wa_read (with archive fallback), wa_read_archive
└── messaging_ops.py # wa_status, wa_recover, wa_sync_auto, wa_list_tools
Key architectural constraints
- All source files ≤ 300 lines with single responsibility
- Vertical slice organization: each domain folder owns its models, queries, and handlers
- Backward compatibility: old single-file modules become thin re-export facades
- Contact directory (JSON) is separate from the SQL message archive
@lidJID support: contacts can have alidfield for WhatsApp multi-device internal IDs_is_real_phone()guard indiscovery.pyprevents 14+ digit lid numbers from being saved as contacts
Local-only artifacts
Keep local execution artifacts out of git (logs, data, media, plan exports). For plan files generated during local experimentation, use:
local_runtime/plans_created/
This package .gitignore excludes these folders by default:
logs/data/media/local_runtime/plans_created/
Install
From repository root:
./venv/bin/python -m pip install -e packages/whatsapp_skill
Console Testing Script
There is now a standalone console tester for this package:
Quick shortcut from the whatsapp_skill/ directory:
./scripts/wa.sh tools # list all 17 tools
./scripts/wa.sh tool wa_status # channel state
./scripts/wa.sh tool wa_policy # send/reply permissions
./scripts/wa.sh tool wa_save_contacts "Gerald|50577427779|owner"
./scripts/wa.sh tool wa_send "Gerald|Hola" # send a message
./scripts/wa.sh tool wa_read "Gerald|10" # read last 10 messages
./scripts/wa.sh wa "status" # /wa admin: status
./scripts/wa.sh wa "sync" # /wa admin: adaptive sync
./scripts/wa.sh wa "sync Zafiro 50 12 8" # /wa admin: sync target
./scripts/wa.sh repl # interactive REPL
Direct python entrypoint (equivalent):
python scripts/wa_console.py list-tools
python scripts/wa_console.py tool wa_status
python scripts/wa_console.py tool wa_send "Gerald|Hola"
python scripts/wa_console.py repl
What it covers:
run-tool: Executes any registered WhatsApp tool from this skill package.run-wa: Executes/waadmin subcommands (on,off,status,link,unlink,actor, etc.).repl: Interactive shell where you can test tool/admin commands quickly.
/wa sync UX (recommended):
/wa sync: global adaptive sync validation./wa sync <target> [limit] [max_rounds] [wait_seconds]: one-shot target sync + archive read.- Compatibility aliases still available:
sync auto,sync oneshot,sync os,sync all.
Skill and tools
Skill name: WhatsApp
Declared tools (all use wa_* prefix):
| Tool | Purpose |
|---|---|
wa_save_contacts |
Save one or more contacts (batch with ;) |
wa_list_contacts |
List saved contacts; auto-refreshes when stale |
wa_save_groups |
Save one or more group JID mappings |
wa_list_groups |
List saved groups; auto-refreshes when stale |
wa_send |
Send outbound message to contact or group |
wa_read |
Read recent messages (live buffer + archive fallback) |
wa_read_archive |
Read persisted archive messages only |
wa_reply |
Reply to a specific message by id |
wa_status |
Channel connection state and linked number |
wa_recover |
Channel recovery workflow |
wa_sync_auto |
Adaptive history sync rounds |
wa_policy |
Show inbound/outbound permission lists |
wa_allow_send |
Enable outbound send for a target |
wa_block_send |
Disable outbound send for a target |
wa_allow_reply |
Enable auto-reply inbound for a target |
wa_block_reply |
Disable auto-reply inbound for a target |
wa_list_tools |
List all tools registered by this skill |
See docs/TOOLS_REFERENCE.md for exact argument formats, examples, and output semantics for each tool.
Runtime model
- Standalone defaults live in
zafiro_skill_whatsapp.integrations. - Archive/history, contacts, groups and access-rules use ORM-backed tables created by this skill.
- Data is scoped by connected WhatsApp number (multi-account safe).
- If host ORM is configured (
orm_session_factoryororm_engine_factory), tables are created/reused there. - If host ORM is not configured, the skill logs a warning and falls back to local SQLite at
WHATSAPP_LOCAL_DB_PATH. - Optional host runtime hooks can be provided with
configure_host_runtime(...)to bridge:- active-agent listing
- task execution
- effective-agent resolution
- host ORM session/engine and storage account resolver
See docs/CORE_INTEGRATION.md for a full bootstrap example and deployment checklist.
Host integration contract
- Contract metadata API:
get_host_runtime_contract(). - Contract validation API:
validate_host_runtime_contract(...). - Fail-fast API:
assert_host_runtime_contract(...).
Expected hooks by mode:
- Core shared database mode (recommended):
- required:
orm_session_factoryororm_engine_factory
- required:
- Multi-account strict mode (recommended):
- required:
resolve_storage_account_key
- required:
- Optional:
storage_schema_initializerget_active_agents,execute_task,resolve_effective_agent
Bootstrap order (recommended):
configure_host_runtime(...)assert_host_runtime_contract(...)- Load entry points and register skills/tools
Dependency contract:
- Python dependencies are installed by package manager when this skill is added:
sqlalchemy,python-magic,neonize
- System dependency required by runtime:
libmagic(OS package; must be present on host image)
Entry points
pyproject.toml exports:
zafiro.skills->whatsappzafiro.tools->whatsapp
Key environment variables
WHATSAPP_SESSION_NAMEWHATSAPP_DEVICE_PLATFORMWHATSAPP_DEVICE_OSWHATSAPP_DEVICE_VERSIONWHATSAPP_OUTBOX_DIRWHATSAPP_CONTACTS_PATHWHATSAPP_ACCESS_RULES_PATHWHATSAPP_MEDIA_DIRWHATSAPP_ACTIVE_ACCOUNT_PATHMESSAGE_ARCHIVE_PATHWHATSAPP_LOCAL_DB_PATHRECENT_SESSION_HISTORY_LIMITWHATSAPP_GROUPS_SYNC_TTL_SECONDSWHATSAPP_CONTACTS_SYNC_TTL_SECONDSWHATSAPP_DIRECTORY_SYNC_MIN_INTERVAL_SECONDSWHATSAPP_FORWARD_URLWHATSAPP_FORWARD_SECRETWHATSAPP_SIMULATE_TYPINGWHATSAPP_TYPING_MIN_MSWHATSAPP_TYPING_MAX_MSWHATSAPP_TYPING_MS_PER_CHARWHATSAPP_SEND_AVAILABLE_PRESENCEWHATSAPP_AUTO_MARK_READWHATSAPP_AUTO_REPLY_ENABLED
Integration tests
End-to-end integration tests run every tool via wa.sh and assert AOT response format:
cd whatsapp_skill
PYTHONPATH=src .venv/bin/python3 -m pytest tests/test_wa_sh_tools_integration.py -v
Coverage: 40 tests (38 standard + 2 skipped for live/send scenarios).
Optional live-mode env flags:
| Flag | Effect |
|---|---|
WA_SH_LIVE=1 |
Run wa_sync_auto live sync test |
WA_SH_ALLOW_SEND=1 |
Run wa_send live send to allowed contact |
Validation checklist (current)
- No AST-level imports from
app,zafiro_skill_hostal, orzafiro_skill_media - Package imports succeed:
zafiro_skill_whatsappzafiro_skill_whatsapp.integrationszafiro_skill_whatsapp.extensions.tools.whatsapp_toolszafiro_skill_whatsapp.extensions.skills.whatsapp
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 zafiro_skill_whatsapp-0.1.2.tar.gz.
File metadata
- Download URL: zafiro_skill_whatsapp-0.1.2.tar.gz
- Upload date:
- Size: 82.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
777c3dfdf1c403df734fc620f27de9fa50525df9041c6efa7bac01a42b85fea5
|
|
| MD5 |
dc7a1b784deb1eed07288ab749160dc3
|
|
| BLAKE2b-256 |
3af246849e116ee9b9ef3538ea041e1fa2f8ab3253b35d2f559661735d081989
|
Provenance
The following attestation bundles were made for zafiro_skill_whatsapp-0.1.2.tar.gz:
Publisher:
pypi-publish.yml on Zafiro-IA/whatsapp-skill
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zafiro_skill_whatsapp-0.1.2.tar.gz -
Subject digest:
777c3dfdf1c403df734fc620f27de9fa50525df9041c6efa7bac01a42b85fea5 - Sigstore transparency entry: 1482691294
- Sigstore integration time:
-
Permalink:
Zafiro-IA/whatsapp-skill@48d7ab82dc4ed3c3fe3a88314fee768c99555270 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Zafiro-IA
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@48d7ab82dc4ed3c3fe3a88314fee768c99555270 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file zafiro_skill_whatsapp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: zafiro_skill_whatsapp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 91.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95cc6801a65c46b6ae918708094e1523e334cebdf31db2aa92ea4240d3a7814e
|
|
| MD5 |
1df42bcd931feaac987b5b286038a0e9
|
|
| BLAKE2b-256 |
dd84a5de50977a8f5dea8bd7e9cbdd1ae51c1580602c53bb4c7ff07d5d0a19e7
|
Provenance
The following attestation bundles were made for zafiro_skill_whatsapp-0.1.2-py3-none-any.whl:
Publisher:
pypi-publish.yml on Zafiro-IA/whatsapp-skill
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zafiro_skill_whatsapp-0.1.2-py3-none-any.whl -
Subject digest:
95cc6801a65c46b6ae918708094e1523e334cebdf31db2aa92ea4240d3a7814e - Sigstore transparency entry: 1482691481
- Sigstore integration time:
-
Permalink:
Zafiro-IA/whatsapp-skill@48d7ab82dc4ed3c3fe3a88314fee768c99555270 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Zafiro-IA
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@48d7ab82dc4ed3c3fe3a88314fee768c99555270 -
Trigger Event:
workflow_dispatch
-
Statement type: