otpless-react-native-autoread
v1.0.0
Published
OTPLESS OTP auto-read (WhatsApp + SMS) SDK for React Native.
Maintainers
Readme
OTPLESS React Native auto-read SDK
A focused SDK for OTP auto-read only: WhatsApp zero-tap and SMS Retriever-based auto-read, with no dependency on the rest of the OTPLESS headless auth flow. If you need full phone-auth (OTP send/verify, one-tap, MFA, SNA, etc.), use otpless-headless-rn-lite instead — that SDK already includes this functionality internally.
Platform support
- Android: minSdk 21 (WhatsApp zero-tap requires Android 7.0 / API 24+). Wraps
io.github.otpless-tech:otpless-autoread-sdkdirectly. No manifest changes needed — the vendor AAR's own manifest merges in the required<queries>entries for WhatsApp/WhatsApp Business and itsBroadcastReceiver. - iOS: not supported. WhatsApp zero-tap and the SMS Retriever API are Android-only concepts; there is no OTPLESS auto-read vendor SDK for iOS. Every method is a safe no-op on iOS —
start*methods immediately emit a result witherror: "UNSUPPORTED_PLATFORM"on the same event channel Android uses (so your callback logic can stay platform-agnostic), andstop*methods do nothing.
Installation
npm i otpless-react-native-autoreadUsage
import { OtplessAutoReadModule } from 'otpless-react-native-autoread';
const autoRead = new OtplessAutoReadModule();
useEffect(() => {
autoRead.setResultCallback(onAutoReadResult);
autoRead.startAutoRead(); // or startWhatsappAutoRead() / startSMSAutoRead()
return () => {
autoRead.stopAutoRead();
autoRead.clearListener();
};
}, []);
const onAutoReadResult = (result) => {
// result: { success, source: 'SMS' | 'WHATSAPP_CONSUMER' | 'WHATSAPP_BUSINESS', otp?, sender?, error? }
if (result.success) {
console.log(`OTP ${result.otp} via ${result.source}`);
}
};API reference
| Method | Platforms | Description |
| --- | --- | --- |
| setResultCallback(callback) | Android, iOS | Subscribes to auto-read results. Call before starting any start* method. |
| clearListener() | Android, iOS | Unsubscribes the result callback. |
| startAutoRead() | Android, iOS (no-op) | Starts both WhatsApp zero-tap and SMS Retriever auto-read. |
| startWhatsappAutoRead() | Android (API 24+), iOS (no-op) | Starts WhatsApp zero-tap auto-read only. |
| startSMSAutoRead() | Android, iOS (no-op) | Starts SMS Retriever-based auto-read only. |
| stopAutoRead() | Android, iOS (no-op) | Stops both — see the WhatsApp limitation below. |
| stopWhatsappAutoRead() | Android (best-effort), iOS (no-op) | See Known limitation below. |
| stopSMSAutoRead() | Android, iOS (no-op) | Fully unregisters the SMS Retriever receiver. |
Result shape
interface AutoReadResult {
success: boolean;
source: 'SMS' | 'WHATSAPP_CONSUMER' | 'WHATSAPP_BUSINESS';
otp?: string;
sender?: string; // SMS originating address, when available
subscriptionId?: number; // SIM subscription ID the SMS was received on, when available
error?: string;
}Known limitation: stopWhatsappAutoRead() is best-effort
The underlying vendor SDK (otpless-autoread-sdk) registers WhatsApp zero-tap as a statically manifest-declared BroadcastReceiver and exposes no public API to unregister it — this was confirmed by decompiling the SDK's own AAR, and matches how OTPLESS's own headless SDK uses it internally (it never unregisters WhatsApp zero-tap either, only SMS).
As a result:
stopSMSAutoRead()genuinely unregisters the SMS Retriever receiver (AutoReadSDK.unregisterSmsOtpReceiver()), matching vendor behavior.stopWhatsappAutoRead()only stops this module from forwarding further WhatsApp results to your JS callback. The nativeBroadcastReceiverkeeps listening for WhatsApp'scom.whatsapp.otp.OTP_RETRIEVEDbroadcast at the OS level for the lifetime of your process — there is currently no way to fully unregister it.
If you need guaranteed full teardown of WhatsApp auto-read, that requires a change in the vendor SDK itself.
Example app
The example/ app is a minimal QA harness with two tabs:
- Controls: buttons for all 6 start/stop functions.
- Log: a color-coded, expandable event feed for every call and result, with copy-to-clipboard support.
