WhatsApp Cloud API ingress: webhook + dispatcher + outbound#5
Merged
Conversation
51a8e0c to
4c857b1
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds WhatsApp as a fourth chat surface alongside the block, the
openclawp/chatability, and the REST endpoint. SameOpenclaWP_Runner::run_turnunderneath; nothing new at the agent / store / loop layers.OpenclaWP_Whatsappclass. Registers two WP REST routes under/openclawp/v1/whatsapp/webhook:GET— Meta's verification challenge (returnshub.challengeonly whenhub.verify_tokenmatches).POST— inbound webhook. VerifiesX-Hub-Signature-256(HMAC-SHA256 of the raw body using the App Secret), parsesentry[].changes[].value.messages[], dispatches each text message to the configured agent, posts the reply back via the Graph API.openclawp_sessionpost via_openclawp_whatsapp_phonemeta. New inbound messages from the same phone resume the same conversation.messages[].idis recorded in a 7-day transient so re-deliveries don't double-process.add_filter( 'openclawp_register_whatsapp', '__return_true' ).Verified end-to-end (without touching real Meta)
Live test against the Studio install with the adapter enabled and bogus credentials:
Result (with outbound POST stubbed to assert what would have been sent to graph.facebook.com):
The full multi-turn loop ran (tool call + tool result + final synthesis), the reply ended up correctly addressed to the inbound phone, signed bodies pass and unsigned/tampered bodies 401.
hub.challengeSmoke tests (now 22 / 22)
Six new assertions in
tests/smoke.php:verify_signatureaccepts a correctly-signed bodyverify_signaturerejects a tampered bodyverify_signaturerejects when secret is emptyextract_messagespulls one text message from a nested envelopeextract_messagesreturns the right phoneextract_messagesreturns the right textTest plan
vendor/bin/phpunit— 6/6studio wp eval 'require "tests/smoke.php";'— 22/22 (6 new for WhatsApp)docs/whatsapp-setup.md"End-to-end smoke without Meta"What's not in this PR
These are tracked as future work; the current shape is the minimum that lets a real WhatsApp number talk to a real agent end-to-end.
Documentation
docs/whatsapp-setup.md— agent runbook for the Meta-side setup (Developer app, system user token, App Secret, Webhook Configuration, ngrok / cloudflared tunneling for localhost), step-by-step with verification commands.Quality gate results
php -l(touched files)vendor/bin/phpunit(6 unit tests)tests/smoke.php(22 integration assertions, 6 new)