Download the PHP package moffhub/ussd without Composer
On this page you can find all versions of the php package moffhub/ussd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ussd
Short Description Enterprise USSD framework for Laravel. Multi-provider support (Safaricom, Airtel, MTN), session management, menu builders, form collection, pagination, security, analytics, and i18n for African mobile networks.
License MIT
Homepage https://github.com/moffhub/ussd
Informations about the package ussd
Moffhub USSD Framework
A powerful, enterprise-grade Laravel package for building scalable USSD applications with support for multiple African mobile network providers.
Features
- Multi-Provider Support: Built-in adapters for Safaricom/Africa's Talking, Airtel, MTN, and a generic fallback
- Menu System: Simple menus, forms, paginated lists, conditional menus, and multi-step wizards
- Session Management: Intelligent session recovery, grace periods, and context preservation
- Security: Rate limiting, input sanitization, audit logging, and blacklist/whitelist support
- Analytics: Track user journeys, menu interactions, and performance metrics
- Caching: Efficient caching layer for menus and data providers
- Data Providers: Pluggable data sources (Array, Database, API)
Requirements
- PHP 8.4+
- Laravel 12.0+
Installation
Publish the configuration file:
Run migrations (optional, for session persistence and analytics):
Quick Start
1. Create a USSD Controller
2. Register the Route
Menu Types
SimpleMenu
Basic menu with numbered options:
FormMenu
Collect multi-step form data:
PaginatedMenu
Display large lists with pagination:
ConditionalMenu
Show different menus based on conditions:
WizardMenu
Multi-step guided processes:
Using the MenuBuilder
Fluent interface for building menus:
Type-Safe Menu Names with Enums
For better type safety and IDE autocomplete, use enums for menu names:
Creating Your Menu Enum
Using Your Enum
Provider Adapters
The framework automatically detects the USSD provider from the request, or you can specify one:
Supported Providers
| Provider | Aliases | Field Mapping |
|---|---|---|
| Safaricom | safaricom, africas_talking, at |
phoneNumber, text, sessionId |
| Airtel | airtel |
msisdn, input/text, transactionId |
| MTN | mtn |
msisdn, UserAnswer, sessionId |
| Generic | generic |
Auto-detect multiple field names |
Register Custom Provider
Data Providers
ArrayDataProvider
DatabaseDataProvider
ApiDataProvider
Session Management
Accessing Session Data
Session Recovery
The framework automatically handles session recovery:
Security Features
Rate Limiting
Database-Backed Whitelist/Blacklist
For production applications, use database-backed access lists that can be managed via a UI:
Using the UssdAccessList Model Directly
Build your own admin UI using the Eloquent model:
Custom Access List Provider
Implement your own storage backend:
Input Sanitization
Validators
Built-in validators for form fields:
Response Types
Configuration
Full configuration options:
Facade
Use the Ussd facade for convenient access:
Internationalization (i18n)
Built-in multi-language support:
Publish and customize language files:
Configure in config/ussd.php:
Signature Verification
Verify incoming provider requests using HMAC signatures:
Circuit Breaker
Protect external API calls from cascading failures:
The circuit breaker is automatically integrated into ApiDataProvider. It supports three states:
- Closed: All requests pass through normally
- Open: Requests return fallback data (after threshold failures)
- Half-open: One test request allowed after cooldown period
Session Encryption
Encrypt sensitive session data at rest:
Configure which fields to encrypt in config/ussd.php:
Events
The framework dispatches Laravel events at key lifecycle points:
| Event | Payload |
|---|---|
SessionStarted |
sessionId, phone, provider |
SessionResumed |
sessionId, phone, wasRecovered |
SessionEnded |
sessionId, phone, duration, menusVisited |
SessionExpired |
sessionId, phone, lastMenu |
MenuEntered |
sessionId, menuName, fromMenu |
MenuExited |
sessionId, menuName, toMenu, selection |
FormSubmitted |
sessionId, menuName, formData |
InputReceived |
sessionId, menuName, rawInput |
NavigationPerformed |
sessionId, action |
Listen to events:
Artisan Commands
Middleware
Two middleware are registered automatically:
Production Deployment
See docs/PRODUCTION.md for a detailed production deployment guide including:
- Deployment checklist
- Cache driver selection (Redis recommended)
- Database migration verification
- Provider credential setup
- Rate limit tuning
- Session timeout configuration
- Analytics retention policy
- Performance tuning guide
- Troubleshooting guide
Quick Checklist
- [ ] Set cache driver to Redis:
CACHE_DRIVER=redis - [ ] Run migrations:
php artisan migrate - [ ] Configure provider secrets in
.env - [ ] Enable signature verification:
USSD_VERIFY_SIGNATURES=true - [ ] Enable session encryption if handling PINs:
USSD_ENCRYPT_SESSION_DATA=true - [ ] Schedule session cleanup:
ussd:cleanup-sessions - [ ] Start queue worker for async analytics:
USSD_ANALYTICS_FLUSH_STRATEGY=async - [ ] Configure gateway IPs:
USSD_GATEWAY_AUTH_ENABLED=true - [ ] Verify health:
php artisan ussd:health
Local Development
USSD Simulator
Test your USSD flows interactively from the command line without needing a real gateway:
This starts an interactive CLI session that simulates a USSD flow. It sends requests to your registered menus, displays responses, and prompts for input just like a real USSD session.
Options
How It Works
- The simulator generates a unique session ID and sends an initial request to
UssdFramework::handle() - The response is displayed in the terminal with
[CON](continue) or[END](end) indicators - If the response is
CON, you are prompted to enter input - The simulator sends a follow-up request with your input
- This loop continues until the response is
ENDor you typeexit - A session summary is displayed at the end with total steps and duration
Testing
Run the test suite:
Or with PHPUnit directly:
Contributing
- Fork the repository
- Create a feature branch
- Write tests for your changes
- Submit a pull request
License
This package is open-sourced software licensed under the MIT license.
Credits
All versions of ussd with dependencies
laravel/framework Version ^12.0 || ^13.0
sourcetoad/enhanced-resources Version ^7.3
sourcetoad/rule-helper-for-laravel Version ^6.3