Whatsapp channel - DB Auth state#162
Conversation
…g, and setup process - Added message formatting functions for WhatsApp, including markdown conversion and message splitting. - Implemented JID normalization and validation functions to handle WhatsApp user and group identifiers. - Created a manifest for the WhatsApp channel plugin, defining configuration fields and startup logic. - Developed a setup process for linking WhatsApp accounts, including QR code handling and session management. - Introduced a WhatsApp API class for sending messages and managing socket connections. - Added tests for bot functionality, bridge message acceptance, JID utilities, manifest validation, and setup processes. - Configured TypeScript build and type-checking settings for the WhatsApp channel.
- Introduced `ChannelCredentialStore` interface for managing channel-owned credentials. - Added `DbChannelCredentialStore` implementation for persistent storage of channel credentials in PostgreSQL. - Updated WhatsApp API to utilize the new credential store instead of the legacy `auth_dir`. - Created tests for the new credential store functionality and updated existing tests to reflect changes. - Modified documentation to describe the new storage model for channel credentials. - Removed references to `auth_dir` in favor of `auth_profile` for WhatsApp integration.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an encrypted, scoped channel credential store (protocol + schema + migration), a Postgres-backed encrypted implementation, WhatsApp auth-state and setup refactor to use credential profiles instead of filesystem auth_dir, gateway wiring to expose scoped credential stores, tests, and documentation updates. ChangesDatabase-Backed Channel Credentials
Sequence DiagramsequenceDiagram
participant User
participant Setup as Setup Flow
participant Store as ChannelCredentialStore
participant API as WhatsApp API
participant Baileys
User->>Setup: Begin QR linking
Setup->>Store: Create temp auth profile
Setup->>Baileys: Initialize with useDbAuthState
Baileys->>Store: Load/init credentials
Baileys->>User: Display QR code
User->>User: Scan with WhatsApp
Setup->>Setup: Poll for completion
Baileys->>Store: Save linked creds
Setup->>Store: Promote to DEFAULT_AUTH_PROFILE
Setup->>User: Linking complete
Note over API: Runtime Boot
API->>Store: Load credentials for auth_profile
Store->>API: Decrypt & return creds
API->>Baileys: Initialize auth state
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/store/src/impl/channel-credential-store.ts`:
- Around line 23-31: The open method may leak the pg.Pool if initialization
fails; wrap creation/initialization (the new pg.Pool, await pool.query('SELECT
1'), drizzle(...), and new DbChannelCredentialStore(...)) in a try/catch and
call pool.end() (or pool.close) in the catch before rethrowing the error; only
set store.pool after all initialization succeeds (i.e., after drizzle and
DbChannelCredentialStore are created) so failures trigger pool cleanup,
referencing the open function, the pool variable, drizzle(...), and
DbChannelCredentialStore/ secretsKeyFromEnv() in your changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 85ec97c8-ec52-4818-9814-0294c9622140
📒 Files selected for processing (25)
README.mdapps/agent/test/channel-credential-store.test.tsapps/channels/whatsapp/README.mdapps/channels/whatsapp/src/db-auth-state.tsapps/channels/whatsapp/src/index.tsapps/channels/whatsapp/src/manifest.tsapps/channels/whatsapp/src/setup.tsapps/channels/whatsapp/src/whatsapp-api.tsapps/channels/whatsapp/test/db-auth-state.test.tsapps/channels/whatsapp/test/manifest.test.tsapps/channels/whatsapp/test/setup.test.tsapps/gateway/src/app.tsapps/gateway/src/channel-pool.tsapps/gateway/src/index.tsdocs/architecture.mddocs/channel-adapter.mddocs/manual/17-channels.mddocs/storage-model.mdpackages/protocol/src/index.tspackages/store/drizzle/0032_channel_credentials.sqlpackages/store/drizzle/meta/_journal.jsonpackages/store/src/impl/channel-credential-store.tspackages/store/src/impl/index.tspackages/store/src/index.tspackages/store/src/schema.ts
This change moves WhatsApp Web auth state out of the local ~/.openhermit/credentials/whatsapp/... folder and into encrypted PostgreSQL-backed channel credentials.
What changed:
Why:
I also updated the WhatsApp docs and storage docs to reflect the new model.
Summary by CodeRabbit
New Features
Documentation
Tests