feat(whatsapp): make linked-device QR mode first-class and compatible#24
Open
liuxiaopai-ai wants to merge 1 commit intoRightNow-AI:mainfrom
Open
feat(whatsapp): make linked-device QR mode first-class and compatible#24liuxiaopai-ai wants to merge 1 commit intoRightNow-AI:mainfrom
liuxiaopai-ai wants to merge 1 commit intoRightNow-AI:mainfrom
Conversation
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
This PR makes WhatsApp linked-devices QR mode a first-class, reliable path while preserving existing Cloud API behavior and compatibility with older configs.
Closes #23
What changed
1) First-class WhatsApp mode model (with compatibility)
WhatsAppModeenum (auto,web_qr,cloud_api) inopenfang-types.modetoWhatsAppConfig(defaultauto).gateway_urlsupport and explicit gateway URL resolution helper.phone_number_id_env(older generated configs keep working).resolved_gateway_url()/resolved_phone_number_id()helpers used by runtime logic.2) Bridge selection logic made explicit and testable
openfang-api/channel_bridgenow chooses WhatsApp runtime path via explicit mode-aware selection:web_qr=> gateway routecloud_api=> Cloud API route (requires token + phone ID)auto=> prefer gateway, fallback to Cloud API when properly configured3) QR API endpoints now use live config resolution
/api/channels/whatsapp/qr/startand/statusnow resolve gateway URL from live channel config (channels.whatsapp) + env fallback.4) Channel configure defaults for WhatsApp
configure_channelnow defaults WhatsApp to:mode = "web_qr"for QR-first setupsmode = "cloud_api"when cloud fields are provided5) CLI/setup mismatch fixes that blocked adoption
openfang channel setup whatsappnow supports both:WA_*) in setup outputs; now usesWHATSAPP_*defaults consistently.MATRIX_ACCESS_TOKEN; WhatsApp no longer incorrectly hard-fails on a single env var in QR mode).6) Docs updated to match implementation
docs/channel-adapters.md: clear split betweenweb_qrandcloud_apimodes; updated examples.docs/configuration.md: updated WhatsApp config schema, mode semantics, env var table, and validation expectations.Tests / verification
Ran locally in this branch:
~/.cargo/bin/cargo test -p openfang-types --lib~/.cargo/bin/cargo test -p openfang-api channel_bridge::tests -- --nocapture~/.cargo/bin/cargo check -p openfang-cli~/.cargo/bin/cargo clippy -p openfang-types --lib --tests -- -D warnings~/.cargo/bin/cargo clippy -p openfang-api --lib --tests -- -D warnings~/.cargo/bin/cargo clippy -p openfang-cli --bin openfang(existing warning-only clippy findings outside this PR’s scope)All targeted tests/checks pass; clippy hard-fail warnings are clean for touched API/types crates.
Risk notes
automode preserves backwards behavior by preferring gateway when available and falling back to Cloud API if fully configured.phone_number_id_envis still accepted to avoid breaking older generated configs.