sms-retriever
TypeScript icon, indicating that this package has built-in type declarations

0.2.9 • Public • Published

📱 SMS Retriever

Effortlessly retrieve OTPs from SMS in your Capacitor apps.

npm npm license

📦 Install

To install the sms-retriever plugin, run the following commands:

npm install sms-retriever
npx cap sync

📖 API

Defines the interface for the SmsReaderPlugin.

readSMS(...)

readSMS(options: ReadSMSOptions) => Promise<ReadSMSResult>

Reads the OTP from SMS messages based on the provided search string.

Param Type Description
options ReadSMSOptions - An object containing the search string.

Returns: Promise<ReadSMSResult>


startWatching(...)

startWatching(options: ReadSMSOptions) => Promise<ReadSMSResult>

Starts watching for SMS messages to read the OTP based on the provided search string.

Param Type Description
options ReadSMSOptions - An object containing the search string.

Returns: Promise<ReadSMSResult>


stopWatching()

stopWatching() => Promise<void>

Stops watching for SMS messages.


Interfaces

ReadSMSResult

Represents the result of reading SMS.

Prop Type Description
otp string The OTP extracted from the SMS.

ReadSMSOptions

Represents the options for reading SMS.

Prop Type Description
searchString string The search string used to find the OTP in the SMS.

💡 Usage Example

Here's a quick example of how to use the sms-retriever plugin in your Capacitor app:

import { SmsReader } from 'sms-retriever';

async function watchForOTP() {
  try {
    const result = await SmsReader.startWatching({ searchString: "OTP: " });
    console.log('Received OTP:', result.otp);
    
    // Optionally stop watching after receiving OTP
    await stopWatchingForOTP();
  } catch (error) {
    console.error('Error watching for OTP:', error);
  }
}

async function stopWatchingForOTP() {
  try {
    await SmsReader.stopWatching();
    console.log('Stopped watching for OTP');
  } catch (error) {
    console.error('Error stopping SMS watcher:', error);
  }
}

// Start watching for OTP
watchForOTP();

With this setup, the plugin will start watching for SMS messages that contain the specified search string, extract the OTP, and stop watching once the OTP is retrieved.

📝 License

This project is licensed under the MIT License. See the LICENSE file for more details.

Readme

Keywords

Package Sidebar

Install

npm i sms-retriever

Weekly Downloads

29

Version

0.2.9

License

MIT

Unpacked Size

38.9 kB

Total Files

27

Last publish

Collaborators

  • mahakarshan