nileshvalva/nativephp-otp-autofill

Automatically detects and fills OTP codes from incoming SMS messages on Android and iOS

Maintainers

Package info

github.com/nileshvalva/nativephp-otp-autofill

Type:nativephp-plugin

pkg:composer/nileshvalva/nativephp-otp-autofill

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-04-19 12:09 UTC

This package is auto-updated.

Last update: 2026-04-20 09:41:22 UTC


README

Latest Version on Packagist License

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_SMS and READ_SMS permissions 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 OtpReceived event to Laravel

Author

Nilesh Valva

License

MIT License. See LICENSE for details.