Logo Lanfrica

wilfredeveloper/mpesa-ai-backend

Domaine:

natural language processingdigital infrastructure

Type de record:

software
Créateur:
wil
Hôte:
# 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