This implementation creates a new USD deposit system that allows users to deposit USD via bank transfer using a two-phase flow approach, separate from the existing mixed-currency deposit system.
-
Phase 1: USD Deposit Flow (
usd_deposit_flow.json)- User enters USD amount
- Flow ends with "Return to Chat" instruction
- Triggers bot messages with bank details
-
Phase 2: Bank Details Flow (
bank_details_flow.json)- User confirms transfer amount and transaction ID
- Completes the deposit process
webhooks/usd_deposit_flow.json- First flow for amount inputwebhooks/bank_details_flow.json- Second flow for confirmation
commands/handlers/usdDepositHandler.ts- Handles "deposit usd"/"USD" commands- Added to
commands/handlers/index.tsexports
webhooks/services/usdDepositFlow.service.ts- Business logic for both flowsgetUsdDepositScreen()- Handles first flowgetBankDetailsScreen()- Handles second flow
webhooks/controllers/usdDepositFlow.controller.ts- HTTP controller for first flowwebhooks/controllers/bankDetailsFlow.controller.ts- HTTP controller for second flow
- Added
sendUsdDepositFlowById()method - Added
sendBankDetailsFlowById()method
- Added
usdDepositcommand with high priority (7) incommands/config.ts - Triggers: "deposit usd", "USD", "usd", "deposit USD", etc.
- Added route handler in
commands/route.ts - Added webhook endpoints in
webhooks/route/route.ts:/flow/usd-deposit- First flow endpoint/flow/bank-details- Second flow endpoint
- User Command: User types "deposit usd" or "deposit USD"
- First Flow: USD deposit flow opens for amount input
- Return to Chat: Flow ends, user returns to chat
- Bot Messages: Bot sends Chase Bank details and transaction ID
- Second Flow: Bot sends bank details flow showing transaction details
- Complete Transfer: User taps "Complete Transfer" button to confirm
- Completion: System processes the deposit and sends confirmation
Bank Name: Chase Bank
Account Name: Connect Word Ink INC
Account Number: 839128227
Routing Number: 021000021
Bank Address: Chase Bank, N.A., 270 Park Avenue, New York, NY 10017
- Uses
walletService.deposit(phone, amount, "USD")to create proper transaction - Returns transaction data with
transactionId,refId, and bank details - Transaction is recorded in database with PENDING status
USD_DEPOSIT_{transactionId}- Stores deposit record (7 days expiry)BANK_DETAILS_FLOW_{phoneNumber}- Stores flow data for second flow (24 hours)
- Uses existing
scheduleProcessDeposit(transactionId)for background processing - Integrates with existing deposit processing infrastructure
Added to .env.example:
# Production
WHATSAPP_USD_DEPOSIT_FLOW_ID=your_usd_deposit_flow_id
WHATSAPP_BANK_DETAILS_FLOW_ID=your_bank_details_flow_id
# Staging
WHATSAPP_STAGING_USD_DEPOSIT_FLOW_ID=your_staging_usd_deposit_flow_id
WHATSAPP_STAGING_BANK_DETAILS_FLOW_ID=your_staging_bank_details_flow_id- Added USD_DEPOSIT and BANK_DETAILS flow IDs for both production and staging
- USD deposit commands have priority 7 (higher than regular deposit priority 3)
- Ensures "USD" triggers USD deposit instead of regular deposit
- Session expiry handling in both flows
- Input validation for amounts and transaction IDs
- Graceful fallback messages for errors
- Redis cleanup on completion
- Transaction Creation: Uses
walletService.deposit()to properly initiate USD deposits - Database Integration: Transactions are recorded in the database with PENDING status
- Processing: Uses existing
scheduleProcessDeposit()for background processing - Infrastructure: Leverages existing deposit processing and job scheduling
- Separate from existing
topup_flow.jsonsystem - Uses existing Redis infrastructure
- Leverages existing WhatsApp service methods
- Follows established flow controller patterns
- Upload Flows: Upload
usd_deposit_flow.jsonandbank_details_flow.jsonto Meta Business Suite - Update Environment: Set actual flow IDs in environment variables
- Testing: Test the complete user journey
- Processing: Implement backend processing for USD deposits (if needed)
webhooks/usd_deposit_flow.jsonwebhooks/bank_details_flow.jsoncommands/handlers/usdDepositHandler.tswebhooks/services/usdDepositFlow.service.tswebhooks/controllers/usdDepositFlow.controller.tswebhooks/controllers/bankDetailsFlow.controller.ts
commands/handlers/index.ts- Added exportcommands/config.ts- Added USD deposit commandcommands/route.ts- Added route handler and importservices/WhatsAppBusinessService.ts- Added new methodsconfig/whatsapp.ts- Added flow IDswebhooks/route/route.ts- Added endpoints.env.example- Added environment variables
The following commands will trigger the USD deposit flow:
- "deposit usd"
- "deposit USD"
- "usd deposit"
- "USD deposit"
- "deposit dollar"
- "deposit dollars"
- And many more variations (see
commands/config.ts)
Note: Standalone "USD" and "usd" triggers were removed to avoid conflicts with currency conversion commands like "usd to ngn".
This implementation provides a complete, separate USD deposit system that follows the existing patterns while meeting the specific requirements for the two-phase flow approach.