delegate-connector-whatsapp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. delegate_connector_whatsapp-0.1.0/.env.example +28 -0
  2. delegate_connector_whatsapp-0.1.0/.gitignore +74 -0
  3. delegate_connector_whatsapp-0.1.0/LICENSE +201 -0
  4. delegate_connector_whatsapp-0.1.0/PKG-INFO +165 -0
  5. delegate_connector_whatsapp-0.1.0/README.md +136 -0
  6. delegate_connector_whatsapp-0.1.0/pyproject.toml +65 -0
  7. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/__init__.py +118 -0
  8. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/cloud_api.py +498 -0
  9. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/compose.py +286 -0
  10. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/connector.py +623 -0
  11. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/directory.py +129 -0
  12. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/redaction.py +177 -0
  13. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/templates.py +236 -0
  14. delegate_connector_whatsapp-0.1.0/src/delegate_connectors/whatsapp/webhook.py +310 -0
  15. delegate_connector_whatsapp-0.1.0/tests/conformance/conftest.py +6 -0
  16. delegate_connector_whatsapp-0.1.0/tests/conformance/loader.py +110 -0
  17. delegate_connector_whatsapp-0.1.0/tests/conformance/test_canonical_set.py +260 -0
  18. delegate_connector_whatsapp-0.1.0/tests/conformance/vector_driver.py +447 -0
  19. delegate_connector_whatsapp-0.1.0/tests/conftest.py +82 -0
  20. delegate_connector_whatsapp-0.1.0/tests/integration/__init__.py +2 -0
  21. delegate_connector_whatsapp-0.1.0/tests/integration/_cloud_api_double.py +146 -0
  22. delegate_connector_whatsapp-0.1.0/tests/integration/_live_meta.py +69 -0
  23. delegate_connector_whatsapp-0.1.0/tests/integration/conftest.py +24 -0
  24. delegate_connector_whatsapp-0.1.0/tests/integration/test_e2e.py +200 -0
  25. delegate_connector_whatsapp-0.1.0/tests/integration/test_send_roundtrip.py +237 -0
  26. delegate_connector_whatsapp-0.1.0/tests/regression/__init__.py +22 -0
  27. delegate_connector_whatsapp-0.1.0/tests/regression/conftest.py +151 -0
  28. delegate_connector_whatsapp-0.1.0/tests/regression/test_pii_redaction.py +152 -0
  29. delegate_connector_whatsapp-0.1.0/tests/regression/test_receipt_identity_binding.py +174 -0
  30. delegate_connector_whatsapp-0.1.0/tests/regression/test_reject_gate_no_send.py +199 -0
  31. delegate_connector_whatsapp-0.1.0/tests/regression/test_webhook_hmac_boundary.py +181 -0
  32. delegate_connector_whatsapp-0.1.0/tests/unit/test_cloud_api.py +292 -0
  33. delegate_connector_whatsapp-0.1.0/tests/unit/test_compose.py +151 -0
  34. delegate_connector_whatsapp-0.1.0/tests/unit/test_connector.py +375 -0
  35. delegate_connector_whatsapp-0.1.0/tests/unit/test_directory.py +83 -0
  36. delegate_connector_whatsapp-0.1.0/tests/unit/test_redaction.py +141 -0
  37. delegate_connector_whatsapp-0.1.0/tests/unit/test_templates.py +244 -0
  38. delegate_connector_whatsapp-0.1.0/tests/unit/test_webhook.py +264 -0
@@ -0,0 +1,28 @@
1
+ # Copyright 2026 Terrene Foundation
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # WhatsApp connector configuration. Copy to .env and fill in real values.
5
+ # NEVER commit a populated .env (root .gitignore excludes .env).
6
+ # All credentials are read from the environment — never hardcoded.
7
+
8
+ # --- Meta Cloud API (outbound, Wave 2 transport) ---
9
+ # System-User permanent access token (Bearer). Never logged.
10
+ WHATSAPP_ACCESS_TOKEN=
11
+ # The phone-number-id of the sending WhatsApp Business number.
12
+ WHATSAPP_PHONE_NUMBER_ID=
13
+ # Graph API version, e.g. v21.0. Endpoint URL is config, not code.
14
+ WHATSAPP_GRAPH_VERSION=
15
+
16
+ # --- Webhook ingest (inbound) ---
17
+ # App secret used to verify the X-Hub-Signature-256 HMAC over the raw body.
18
+ WHATSAPP_APP_SECRET=
19
+ # Verify-token echoed back during the hub.challenge handshake.
20
+ WHATSAPP_WEBHOOK_VERIFY_TOKEN=
21
+
22
+ # --- PII redaction (binding) ---
23
+ # Key for the salted-HMAC-SHA256 phone-number redaction token (wa:<8-hex>).
24
+ WHATSAPP_PII_HMAC_KEY=
25
+
26
+ # --- Outbound gating ---
27
+ # Comma-separated allowlist of approved template names (window-exempt sends).
28
+ WHATSAPP_APPROVED_TEMPLATES=
@@ -0,0 +1,74 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ !.claude/hooks/lib/
15
+ lib64/
16
+ parts/
17
+ sdist/
18
+ var/
19
+ wheels/
20
+ *.egg-info/
21
+ .installed.cfg
22
+ *.egg
23
+ MANIFEST
24
+
25
+ # Virtual environments
26
+ .env
27
+ .venv
28
+ env/
29
+ venv/
30
+ ENV/
31
+ env.bak/
32
+ venv.bak/
33
+ .python-version
34
+
35
+ # IDE specific files
36
+ .idea/
37
+ .vscode/
38
+ *.swp
39
+ *.swo
40
+ .DS_Store
41
+ .jbeval/
42
+ output.txt
43
+
44
+ # Testing
45
+ .coverage
46
+ htmlcov/
47
+ .pytest_cache/
48
+ .mypy_cache/
49
+
50
+ # Secrets
51
+ *.pem
52
+ *.key
53
+ secrets/
54
+
55
+ # Workspace session notes (per-session, not versioned)
56
+ **/.session-notes
57
+
58
+ # Per-project learning data (generated at runtime)
59
+ .claude/learning/
60
+ .claude/rules/learned-instincts.md
61
+
62
+ # Runtime telemetry logs (generated by hooks at runtime)
63
+ .claude/logs/
64
+
65
+ # Internal docs (not for distribution)
66
+ /docs/01-kailash-vibe-cc-internals/
67
+
68
+ # Generated script outputs (sdk-users examples)
69
+ **/scripts/data/
70
+ **/scripts/outputs/
71
+ **/scripts/*.log
72
+
73
+ # Journal-hook runtime bookkeeping (per-clone skip log; not source)
74
+ **/.journal-skipped.log
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Terrene Foundation
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: delegate-connector-whatsapp
3
+ Version: 0.1.0
4
+ Summary: OSS WhatsApp connector for the Terrene Delegate substrate (kailash.delegate).
5
+ Project-URL: Homepage, https://github.com/terrene-foundation/delegate-connectors
6
+ Project-URL: Changelog, https://github.com/terrene-foundation/delegate-connectors/blob/main/CHANGELOG.md
7
+ Author: Terrene Foundation
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: cloud-api,connector,delegate,kailash,meta,whatsapp
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Communications :: Chat
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: cryptography>=42.0
22
+ Requires-Dist: httpx>=0.27
23
+ Requires-Dist: kailash>=2.28.0
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
26
+ Requires-Dist: pytest>=8.0; extra == 'test'
27
+ Requires-Dist: python-dotenv>=1.0; extra == 'test'
28
+ Description-Content-Type: text/markdown
29
+
30
+ <!--
31
+ Copyright 2026 Terrene Foundation
32
+ SPDX-License-Identifier: Apache-2.0
33
+ -->
34
+
35
+ # delegate-connector-whatsapp
36
+
37
+ An OSS Python connector for the Terrene Delegate substrate. Implements the
38
+ shipped `kailash.delegate.Connector` ABC (kailash 2.26.2) for WhatsApp over the
39
+ first-party Meta Cloud API:
40
+
41
+ - **`write`** — Cloud API outbound send (`httpx POST /messages`), executed under
42
+ audit, returns a real `SignedActionEnvelope`. Every send passes the
43
+ template / service-window pre-flight gate (below).
44
+ - **`read`** — drains verified inbound messages from the webhook ingest buffer,
45
+ executed under audit, returns `(messages, AttestedReadReceipt)`. Inbound is
46
+ webhook-only: the connector ships the ingest protocol + buffer, NOT a running
47
+ HTTP server (owning the public TLS socket is a deploy concern, not a
48
+ connector-contract concern — WA-ADR-2).
49
+ - **`authenticate`** — resolves an E.164 sender to a `Principal` against the
50
+ `PrincipalDirectory` (exact-match in v0; unknown sender → fail-closed
51
+ `Reject` via `ConnectorAuthenticationError`).
52
+ - **`invoke`** — single-method dispatch entry (used by the dispatch hot path);
53
+ dispatches a send and returns a `ConnectorInvocationResult`.
54
+ - Trust properties — `auth_verifier` returns the wired `Ed25519Verifier`;
55
+ `ledger` / `revocation` return shipped concretes (framework-first; no custom
56
+ trust primitives).
57
+
58
+ It subclasses `Connector` **directly** (mirroring email ADR-1) — NOT
59
+ `LegacyInvokeConnector`, whose proxied `read`/`write` emit empty, unverifiable
60
+ receipts. This connector's `read`/`write` produce non-empty receipts that verify
61
+ under a real `Ed25519Verifier`.
62
+
63
+ ## Security properties
64
+
65
+ - **PII redaction** — the raw E.164 recipient never enters a log, audit-bytes
66
+ payload, or ledger record. Persisted identity is a stable salted
67
+ HMAC-SHA256 token (`wa:<hex>`); a redaction failure surfaces the
68
+ `<unredactable wa identity>` sentinel, never the raw number. The
69
+ `WHATSAPP_PII_HMAC_KEY` startup gate (`RedactionConfig.from_env`) makes an
70
+ installation missing the key **refuse to start** — loud, not fail-soft.
71
+ - **Webhook HMAC boundary** — inbound `X-Hub-Signature-256` is verified
72
+ constant-time; a tampered signature is refused and never reaches the buffer
73
+ or the audit path. The `hub.verify_token` handshake echoes `hub.challenge`
74
+ only on an exact token match.
75
+ - **Outbound gating** — free-form sends to a recipient outside the open 24h
76
+ customer-service window raise a typed `OutsideServiceWindowError`; un-approved
77
+ template names raise `TemplateNotApprovedError`. Both are pre-flight
78
+ `Reject`s — NOT silent send failures — and fire NO Cloud API call. Approved
79
+ templates are window-exempt (WA-ADR-4). The window tracker is bounded
80
+ (LRU, default 100 000 entries) so the verified-inbound map cannot grow
81
+ without limit.
82
+ - **Receipt identity-binding** — receipts sign over the FULL identity (signer +
83
+ action/observed timestamps + content), not the bare payload; tampering ANY
84
+ bound field fails `verify_action_envelope` / `verify_read_receipt`.
85
+
86
+ ## Commercial-gateway disposition (stated openly)
87
+
88
+ Apache-2.0, Foundation-owned. The network endpoint is unavoidably commercial
89
+ (Meta Cloud API) — the same shape as the email connector's commercial SMTP host.
90
+ The shipped code path couples to **no intermediary vendor SDK**: the transport is
91
+ a generic `httpx` client against Meta's first-party Graph API, and the endpoint
92
+ URL is config, not code (WA-ADR-1, journal 0002). There is no dependency on any
93
+ proprietary sibling.
94
+
95
+ ## Install
96
+
97
+ ```bash
98
+ pip install -e connectors/whatsapp
99
+ ```
100
+
101
+ ## Configure
102
+
103
+ All credentials come from the environment (see `.env.example`); nothing is
104
+ hardcoded, nothing is logged. `.env` is git-ignored — only `.env.example` is
105
+ committed. The seven keys:
106
+
107
+ | Key | Purpose |
108
+ | ------------------------------- | ----------------------------------------------------- |
109
+ | `WHATSAPP_ACCESS_TOKEN` | Cloud API bearer token (Graph API auth) |
110
+ | `WHATSAPP_PHONE_NUMBER_ID` | the sending phone-number id (Cloud API path) |
111
+ | `WHATSAPP_GRAPH_VERSION` | Graph API version segment (e.g. `v21.0`) |
112
+ | `WHATSAPP_APP_SECRET` | HMAC key for `X-Hub-Signature-256` webhook verify |
113
+ | `WHATSAPP_WEBHOOK_VERIFY_TOKEN` | the `hub.verify_token` handshake secret |
114
+ | `WHATSAPP_PII_HMAC_KEY` | salt for the `wa:`-token PII redactor (startup-gated) |
115
+ | `WHATSAPP_APPROVED_TEMPLATES` | comma-separated approved-template allowlist |
116
+
117
+ ## Test
118
+
119
+ Tier-1 (unit, no I/O, no third-party transport lib required):
120
+
121
+ ```bash
122
+ pip install -e "connectors/whatsapp[test]"
123
+ PYTHONPATH=connectors/whatsapp/src python -m pytest connectors/whatsapp/tests/unit -q
124
+ ```
125
+
126
+ Tier-2 (in-process protocol-faithful Cloud API double — no mocks at the
127
+ boundary, no Docker, no vendor SDK):
128
+
129
+ ```bash
130
+ PYTHONPATH=connectors/whatsapp/src python -m pytest connectors/whatsapp/tests/integration -q
131
+ ```
132
+
133
+ The Tier-2 double is an `httpx.MockTransport`-backed deterministic adapter that
134
+ speaks the Meta `POST /messages` request/response shape — a Protocol-satisfying
135
+ surrogate, NOT a mock of the connector or the Cloud API client. Tier-3 is a
136
+ single opt-in `test_live_meta_sandbox` that runs against the real Meta sandbox
137
+ only when live `WHATSAPP_*` credentials are present; absent them it skips with a
138
+ "cannot execute" reason (never a mock fallback).
139
+
140
+ Conformance (shared canonical vector set) and the permanent security regression
141
+ suite:
142
+
143
+ ```bash
144
+ PYTHONPATH=connectors/whatsapp/src python -m pytest \
145
+ connectors/whatsapp/tests/conformance connectors/whatsapp/tests/regression -q
146
+ ```
147
+
148
+ ## Known limitation — runtime `execute()` audit gate
149
+
150
+ `compose.py` builds a real `DelegateRuntime` (over a `DispatchSurface`) around
151
+ the connector via `build_whatsapp_runtime`, driven with `await runtime.execute(...)`
152
+ (the dispatch entry is async — journal 0001). However the shipped
153
+ `kailash.delegate` runtime/dispatch
154
+ audit-emit path signs the event payload bytes while `AuditChainEngine.emit_event`
155
+ verifies the signature against the full audit-entry signing bytes — so
156
+ `runtime.execute()` fails at the first audit emission under any real verifier.
157
+ This is an SDK bug in `kailash.delegate` (kailash-py#1182), not in this
158
+ connector; the connector's own `read`/`write` receipts verify correctly (proven
159
+ in the Tier-1 suite). The end-to-end `runtime.execute()` assertion is gated on
160
+ the SDK fix (strict-xfail across the unit / integration / conformance suites);
161
+ the connector-level send round-trip and receipt verification are not.
162
+
163
+ ## License
164
+
165
+ Apache 2.0. All open-source IP is owned by the Terrene Foundation.
@@ -0,0 +1,136 @@
1
+ <!--
2
+ Copyright 2026 Terrene Foundation
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
6
+ # delegate-connector-whatsapp
7
+
8
+ An OSS Python connector for the Terrene Delegate substrate. Implements the
9
+ shipped `kailash.delegate.Connector` ABC (kailash 2.26.2) for WhatsApp over the
10
+ first-party Meta Cloud API:
11
+
12
+ - **`write`** — Cloud API outbound send (`httpx POST /messages`), executed under
13
+ audit, returns a real `SignedActionEnvelope`. Every send passes the
14
+ template / service-window pre-flight gate (below).
15
+ - **`read`** — drains verified inbound messages from the webhook ingest buffer,
16
+ executed under audit, returns `(messages, AttestedReadReceipt)`. Inbound is
17
+ webhook-only: the connector ships the ingest protocol + buffer, NOT a running
18
+ HTTP server (owning the public TLS socket is a deploy concern, not a
19
+ connector-contract concern — WA-ADR-2).
20
+ - **`authenticate`** — resolves an E.164 sender to a `Principal` against the
21
+ `PrincipalDirectory` (exact-match in v0; unknown sender → fail-closed
22
+ `Reject` via `ConnectorAuthenticationError`).
23
+ - **`invoke`** — single-method dispatch entry (used by the dispatch hot path);
24
+ dispatches a send and returns a `ConnectorInvocationResult`.
25
+ - Trust properties — `auth_verifier` returns the wired `Ed25519Verifier`;
26
+ `ledger` / `revocation` return shipped concretes (framework-first; no custom
27
+ trust primitives).
28
+
29
+ It subclasses `Connector` **directly** (mirroring email ADR-1) — NOT
30
+ `LegacyInvokeConnector`, whose proxied `read`/`write` emit empty, unverifiable
31
+ receipts. This connector's `read`/`write` produce non-empty receipts that verify
32
+ under a real `Ed25519Verifier`.
33
+
34
+ ## Security properties
35
+
36
+ - **PII redaction** — the raw E.164 recipient never enters a log, audit-bytes
37
+ payload, or ledger record. Persisted identity is a stable salted
38
+ HMAC-SHA256 token (`wa:<hex>`); a redaction failure surfaces the
39
+ `<unredactable wa identity>` sentinel, never the raw number. The
40
+ `WHATSAPP_PII_HMAC_KEY` startup gate (`RedactionConfig.from_env`) makes an
41
+ installation missing the key **refuse to start** — loud, not fail-soft.
42
+ - **Webhook HMAC boundary** — inbound `X-Hub-Signature-256` is verified
43
+ constant-time; a tampered signature is refused and never reaches the buffer
44
+ or the audit path. The `hub.verify_token` handshake echoes `hub.challenge`
45
+ only on an exact token match.
46
+ - **Outbound gating** — free-form sends to a recipient outside the open 24h
47
+ customer-service window raise a typed `OutsideServiceWindowError`; un-approved
48
+ template names raise `TemplateNotApprovedError`. Both are pre-flight
49
+ `Reject`s — NOT silent send failures — and fire NO Cloud API call. Approved
50
+ templates are window-exempt (WA-ADR-4). The window tracker is bounded
51
+ (LRU, default 100 000 entries) so the verified-inbound map cannot grow
52
+ without limit.
53
+ - **Receipt identity-binding** — receipts sign over the FULL identity (signer +
54
+ action/observed timestamps + content), not the bare payload; tampering ANY
55
+ bound field fails `verify_action_envelope` / `verify_read_receipt`.
56
+
57
+ ## Commercial-gateway disposition (stated openly)
58
+
59
+ Apache-2.0, Foundation-owned. The network endpoint is unavoidably commercial
60
+ (Meta Cloud API) — the same shape as the email connector's commercial SMTP host.
61
+ The shipped code path couples to **no intermediary vendor SDK**: the transport is
62
+ a generic `httpx` client against Meta's first-party Graph API, and the endpoint
63
+ URL is config, not code (WA-ADR-1, journal 0002). There is no dependency on any
64
+ proprietary sibling.
65
+
66
+ ## Install
67
+
68
+ ```bash
69
+ pip install -e connectors/whatsapp
70
+ ```
71
+
72
+ ## Configure
73
+
74
+ All credentials come from the environment (see `.env.example`); nothing is
75
+ hardcoded, nothing is logged. `.env` is git-ignored — only `.env.example` is
76
+ committed. The seven keys:
77
+
78
+ | Key | Purpose |
79
+ | ------------------------------- | ----------------------------------------------------- |
80
+ | `WHATSAPP_ACCESS_TOKEN` | Cloud API bearer token (Graph API auth) |
81
+ | `WHATSAPP_PHONE_NUMBER_ID` | the sending phone-number id (Cloud API path) |
82
+ | `WHATSAPP_GRAPH_VERSION` | Graph API version segment (e.g. `v21.0`) |
83
+ | `WHATSAPP_APP_SECRET` | HMAC key for `X-Hub-Signature-256` webhook verify |
84
+ | `WHATSAPP_WEBHOOK_VERIFY_TOKEN` | the `hub.verify_token` handshake secret |
85
+ | `WHATSAPP_PII_HMAC_KEY` | salt for the `wa:`-token PII redactor (startup-gated) |
86
+ | `WHATSAPP_APPROVED_TEMPLATES` | comma-separated approved-template allowlist |
87
+
88
+ ## Test
89
+
90
+ Tier-1 (unit, no I/O, no third-party transport lib required):
91
+
92
+ ```bash
93
+ pip install -e "connectors/whatsapp[test]"
94
+ PYTHONPATH=connectors/whatsapp/src python -m pytest connectors/whatsapp/tests/unit -q
95
+ ```
96
+
97
+ Tier-2 (in-process protocol-faithful Cloud API double — no mocks at the
98
+ boundary, no Docker, no vendor SDK):
99
+
100
+ ```bash
101
+ PYTHONPATH=connectors/whatsapp/src python -m pytest connectors/whatsapp/tests/integration -q
102
+ ```
103
+
104
+ The Tier-2 double is an `httpx.MockTransport`-backed deterministic adapter that
105
+ speaks the Meta `POST /messages` request/response shape — a Protocol-satisfying
106
+ surrogate, NOT a mock of the connector or the Cloud API client. Tier-3 is a
107
+ single opt-in `test_live_meta_sandbox` that runs against the real Meta sandbox
108
+ only when live `WHATSAPP_*` credentials are present; absent them it skips with a
109
+ "cannot execute" reason (never a mock fallback).
110
+
111
+ Conformance (shared canonical vector set) and the permanent security regression
112
+ suite:
113
+
114
+ ```bash
115
+ PYTHONPATH=connectors/whatsapp/src python -m pytest \
116
+ connectors/whatsapp/tests/conformance connectors/whatsapp/tests/regression -q
117
+ ```
118
+
119
+ ## Known limitation — runtime `execute()` audit gate
120
+
121
+ `compose.py` builds a real `DelegateRuntime` (over a `DispatchSurface`) around
122
+ the connector via `build_whatsapp_runtime`, driven with `await runtime.execute(...)`
123
+ (the dispatch entry is async — journal 0001). However the shipped
124
+ `kailash.delegate` runtime/dispatch
125
+ audit-emit path signs the event payload bytes while `AuditChainEngine.emit_event`
126
+ verifies the signature against the full audit-entry signing bytes — so
127
+ `runtime.execute()` fails at the first audit emission under any real verifier.
128
+ This is an SDK bug in `kailash.delegate` (kailash-py#1182), not in this
129
+ connector; the connector's own `read`/`write` receipts verify correctly (proven
130
+ in the Tier-1 suite). The end-to-end `runtime.execute()` assertion is gated on
131
+ the SDK fix (strict-xfail across the unit / integration / conformance suites);
132
+ the connector-level send round-trip and receipt verification are not.
133
+
134
+ ## License
135
+
136
+ Apache 2.0. All open-source IP is owned by the Terrene Foundation.
@@ -0,0 +1,65 @@
1
+ # Copyright 2026 Terrene Foundation
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ [build-system]
4
+ requires = ["hatchling"]
5
+ build-backend = "hatchling.build"
6
+
7
+ [project]
8
+ name = "delegate-connector-whatsapp"
9
+ dynamic = ["version"]
10
+ description = "OSS WhatsApp connector for the Terrene Delegate substrate (kailash.delegate)."
11
+ readme = "README.md"
12
+ requires-python = ">=3.10"
13
+ license = "Apache-2.0"
14
+ license-files = ["LICENSE"]
15
+ authors = [{ name = "Terrene Foundation" }]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: Communications :: Chat",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ ]
27
+ keywords = ["kailash", "delegate", "connector", "whatsapp", "meta", "cloud-api"]
28
+ dependencies = [
29
+ # Connector ABC (write/read/authenticate) + Principal/SignedActionEnvelope
30
+ # landed in kailash 2.26.1; 2.24.0-2.25.2 ImportError on Principal. Floor 2.28.0:
31
+ # kailash-py#1182 (runtime audit-emit signature bug) fixed at <=2.28.1; dev/CI pin 2.28.1.
32
+ "kailash>=2.28.0",
33
+ # Outbound transport is a generic HTTP client against Meta's first-party
34
+ # Graph API — NOT a vendor aggregator SDK (WA-ADR-1, journal 0002).
35
+ "httpx>=0.27",
36
+ # Ed25519Verifier + the salted-HMAC PII redaction path use cryptography.
37
+ "cryptography>=42.0",
38
+ ]
39
+
40
+ [project.optional-dependencies]
41
+ test = [
42
+ "pytest>=8.0",
43
+ "pytest-asyncio>=0.23",
44
+ "python-dotenv>=1.0",
45
+ ]
46
+
47
+ [project.urls]
48
+ Homepage = "https://github.com/terrene-foundation/delegate-connectors"
49
+ Changelog = "https://github.com/terrene-foundation/delegate-connectors/blob/main/CHANGELOG.md"
50
+
51
+ [tool.hatch.version]
52
+ path = "src/delegate_connectors/whatsapp/__init__.py"
53
+
54
+ [tool.hatch.build.targets.wheel]
55
+ packages = ["src/delegate_connectors"]
56
+
57
+ [tool.pytest.ini_options]
58
+ asyncio_mode = "auto"
59
+ asyncio_default_fixture_loop_scope = "function"
60
+ testpaths = ["tests"]
61
+ markers = [
62
+ "integration: real-infra Tier-2/3 tests (require a local Cloud API double, WA-ADR-5)",
63
+ "regression: regression tests guarding a specific fixed bug (NEVER deleted)",
64
+ "conformance: canonical conformance vector tests",
65
+ ]