Logo Lanfrica

wilfredeveloper/mpesa-ai-backend

Domain:

natural language processingdigital infrastructure

Record type:

software
Creator:
wil
Host:
# AI M-Pesa Payment Agent An AI-powered FastAPI server with CLI interface that can process M-Pesa payments through natural language commands using Google's ADK and Safaricom's Daraja API. ## Features - **πŸš€ FastAPI Server**: REST API with session management and agent interaction - **πŸ’¬ Beautiful CLI**: Clean command-line interface with filtered logs and token counting - **πŸ’° M-Pesa Integration**: Send payments, check transaction status, validate phone numbers - **πŸ€– AI-Powered**: Uses Google Gemini 2.0 Flash for natural language understanding - **πŸ“± Phone Validation**: Validates and formats Kenyan phone numbers - **πŸ“Š Transaction Tracking**: Real-time payment status and account balance - **πŸ’Ύ SQLite Database**: Simple session persistence without external dependencies ## Quick Start ### 1. Install Dependencies ```bash # Activate virtual environment (if using one) source env/bin/activate # Install dependencies pip install -r requirements.txt ``` ### 2. Run the Application **CLI Mode (Beautiful Interface):** ```bash python app/main.py cli ``` **Server Mode (REST API):** ```bash python app/main.py # Server will start at localhost # API docs at localhost ``` ### 3. Run Unified Webhook Server (M-Pesa + WhatsApp) For webhook integrations (M-Pesa callbacks and WhatsApp messages): ```bash # Start the unified webhook server on port 5455 python callback_server.py # In another terminal, expose with ngrok ngrok http 5455 ``` **Endpoints:** - πŸ“± M-Pesa: `localhost` - πŸ’¬ WhatsApp: `localhost` - πŸ§ͺ Test: `localhost` ### 4. Configure M-Pesa (Optional) For actual M-Pesa payments, configure your credentials: 1. Get credentials from Safaricom Developer Portal 2. Update `.env` file: ```env MPESA_CONSUMER_KEY=your_consumer_key MPESA_CONSUMER_SECRET=your_consumer_secret MPESA_BUSINESS_SHORT_CODE=your_shortcode MPESA_PASSKEY=your_passkey MPESA_CALLBACK_URL=your-dom …

Languages