nileshvalva / nativephp-otp-autofill
Automatically detects and fills OTP codes from incoming SMS messages on Android and iOS
Package info
github.com/nileshvalva/nativephp-otp-autofill
Type:nativephp-plugin
pkg:composer/nileshvalva/nativephp-otp-autofill
1.0.1
2026-04-19 12:09 UTC
Requires
- php: ^8.2
- nativephp/mobile: ^3.0
Requires (Dev)
- pestphp/pest: ^3.0
README
Automatically detects and fills OTP codes from incoming SMS messages on Android and iOS for NativePHP Mobile apps.
Features
- ✅ Android — reads SMS directly via BroadcastReceiver (silent, no user interaction)
- ✅ iOS — clipboard watcher + system AutoFill support
- ✅ Supports 4–8 digit OTP codes
- ✅ Fires a Laravel event when OTP is detected
- ✅ Works with any frontend (Blade, Livewire, Vue, Alpine)
Requirements
- PHP 8.2+
- Laravel 10+
- NativePHP Mobile v3+
Installation
composer require nileshvalva/nativephp-otp-autofill
Publish and register the plugin:
php artisan vendor:publish --tag=nativephp-plugins-provider php artisan native:plugin:register nileshvalva/nativephp-otp-autofill
Usage
Start / Stop Listening
use Nativephp\OtpAutofill\Facades\OtpAutofill; // Start listening for OTP OtpAutofill::startListening(); // Stop listening OtpAutofill::stopListening(); // Get current status $status = OtpAutofill::getStatus();
Listen for OTP in PHP / Livewire
use Nativephp\OtpAutofill\Events\OtpReceived; // Standard Laravel event listener Event::listen(OtpReceived::class, function ($event) { $otp = $event->otp; $message = $event->message; $sender = $event->sender; }); // Livewire component use Livewire\Attributes\On; #[On('native:Nativephp\OtpAutofill\Events\OtpReceived')] public function handleOtp($otp, $message, $sender) { $this->otpCode = $otp; }
Listen for OTP in JavaScript
document.addEventListener('native-event', (event) => { const detail = event.detail; if (detail?.event === 'Nativephp\\OtpAutofill\\Events\\OtpReceived') { const otp = detail.payload?.otp; const input = document.querySelector('input[autocomplete="one-time-code"]'); if (input) { input.value = otp; input.dispatchEvent(new Event('input', { bubbles: true })); } } });
HTML Input
Add autocomplete="one-time-code" to your input for iOS system AutoFill support:
<input type="tel" name="otp" autocomplete="one-time-code" maxlength="6" placeholder="------" />
Platform Notes
Android
RECEIVE_SMSandREAD_SMSpermissions are declared automatically- OTP is detected silently in the background — no user interaction needed
iOS
- Uses clipboard watcher — checks clipboard every 1 second for OTP codes
- Uses iOS system AutoFill — iOS suggests OTP above keyboard automatically
- iOS 16+ shows a one-time "Allow Paste" dialog — this is standard iOS privacy behavior
Testing
Android Emulator
adb emu sms send 1234567890 "Your OTP is 847291. Valid for 10 minutes."
iOS Simulator
xcrun simctl pbcopy booted "Your OTP is 847291. Valid for 10 minutes."
Changelog
v1.0.1 — Initial Release
- Android SMS detection via BroadcastReceiver
- iOS clipboard watcher support
- iOS system AutoFill support
- OTP extraction with regex (4–8 digits)
- Fires
OtpReceivedevent to Laravel
Author
Nilesh Valva
- GitHub: @nileshvalva
- Packagist: nileshvalva/nativephp-otp-autofill
License
MIT License. See LICENSE for details.