Giter VIP home page Giter VIP logo

react-native-expo-read-sms's Introduction



react-native-expo-read-sms

Reading SMS made simple in React Native on Android

DocumentationInstallationUsageExampleMethodsLicense

Installation

Install this in your managed Expo project by running this command:

$ npm install @maniac-tech/react-native-expo-read-sms --save

Usage

  1. Import the startReadSMS function after installation

    import { startReadSMS } from "@maniac-tech/react-native-expo-read-sms";

  2. Pass Success and Error callbacks startReadSMS(successCallbackFn, errorCallbackFn)

  3. Everytime an SMS has been received successCallbackFn will be called with the sms

Example

You may refer to this sample application for how to use the library: GitHub Repo

Methods

Method name Description Params Returns
checkIfHasSMSPermission Function which checks if the application has READ_SMS and RECEIVE_SMS permissions - { hasReceiveSmsPermission: true/false, hasReadSmsPermission: true/false }
requestReadSMSPermission Requests READ_SMS and RECEIVE_SMS permission, if missing - Returns true if granted, and false otherwise
startReadSMS Starts listening for incoming messages. Note: SMS Permissions should be present. callback fn Return a string with message orginating address, and message body. Example: [+919999999999, this is a sample message body]

Important Note:

Ensure your app has READ_SMS, and RECEIVE_SMS, failing which you'll receive error on calling the function

Support

Tested on Expo SDK v44, v45 & v47, v48, v49, v50 and Node JS v18

License

MIT

Maintainers

maniac-tech Active maintainer

Buy Me A Coffee

Credits

  • Docusaurus: For helping spin up and manitain the documentation with ease.

react-native-expo-read-sms's People

Contributors

maniac-tech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-expo-read-sms's Issues

Typescript Support

Could not find a declaration file for module '@maniac-tech/react-native-expo-read-sms'. 

Can we find a way of adding typescript support on this librarry

Can see warnings around NativeEventEmitter in console

Description:

Can see the following errors when the startReadSMS function is called:


WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.

Add SMS related permissions to AndroidManifest

Description:

At the moment, we need to manually set READ_SMS and RECEIVE_SMS permissions in the app after installing the package, can we instead get them added to the library itself ?

Support the library on expo v46

Is your feature request related to a problem? Please describe.
Support the library on expo v46.

Describe the solution you'd like
No new features, the existing features should work out of the box

Describe alternatives you've considered
N/A

Additional context
N/A

Bug at installation

Describe the bug
when i try to install package


Installing 1 other package using npm.
> npm install --save @maniac-tech/react-native-expo-read-sms
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react-native
npm ERR!   react-native@"0.70.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native@"^0.41.2" from @maniac-tech/[email protected]
npm ERR! node_modules/@maniac-tech/react-native-expo-read-sms
npm ERR!   @maniac-tech/react-native-expo-read-sms@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\kotsh\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\kotsh\AppData\Local\npm-cache\_logs\2022-11-20T12_45_23_492Z-debug.log

expo version
"expo": "~47.0.6",
"react": "18.1.0",
"react-native": "0.70.5"

Add originator information to callback

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Currently, the startReadSMS callback only receives the message body and not the sender's number. Having the sender information would make this library a lot more valuable because it can then be used to fully handle inbound text messages.

Describe alternatives you've considered
None available, this library seems to be one of a kind in the Expo ecosystem :)

Additional context
The getMessageFromMessageIntent function only takes the getDisplayMessageBody():

Using a structure for the message and returning the getDisplayOriginatingAddress could solve this, but I'm by no means enough of an Android developer to test this… unfortunately.

Develop a dedicated documentation for the library

Is your feature request related to a problem? Please describe.
N/A

Describe the solution you'd like
Build a dedicated documentation for the library

Describe alternatives you've considered
N/A

Additional context
N/A

Bug while init

Describe the bug
i'm using expo 45
built dev apk by eas build -p android --profile development
installed on real device

App.js

import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import {
  startReadSMS,
  checkIfHasSMSPermission,
  requestReadSMSPermission,
} from "@maniac-tech/react-native-expo-read-sms";
import { useEffect } from "react";

export default function App() {
  useEffect(() => {
    if (checkIfHasSMSPermission) read();
    // requestReadSMSPermission();
    return () => {};
  }, []);

  async function read() {
    await startReadSMS(successCallbackFn);
  }
  async function successCallbackFn(status, sms, error) {
    console.log("successCallbackFn", status, sms, error);
  }

  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

error i get

`new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
at node_modules\expo\build\environment\react-native-logs.fx.js:18:22 in warn
at node_modules\react-native\Libraries\EventEmitter\NativeEventEmitter.js:67:20 in constructor
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:463:12 in __invokeCallback
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:125:27 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:368:10 in __guard   
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:124:16 in invokeCallbackAndReturnFlushedQueue

Update `requestReadSMSPermission` return value in Readme

Describe the bug
The documentation states that requestReadSMSPermission returns a boolean which is not the case

To Reproduce
Steps to reproduce the behavior:

  1. call requestReadSMSPermission without passing explicit SMS permission in any app

Expected behavior
It should return boolean

Screenshots
N/A

Desktop (please complete the following information):

  • Platform agnostic

Smartphone (please complete the following information):

  • Platform agnostic

Additional context
N/A

Support the library on expo v48

Is your feature request related to a problem? Please describe.
Support the library on expo v47.

Describe the solution you'd like
No new features, the existing features should work out of the box

Describe alternatives you've considered
N/A

Additional context
N/A

Read old SMS messages

Describe the solution you'd like
I'd like to be able to access old SMS messages (e.g. the last x messages from a given contact) as opposed to listening for present/incoming messages.

Additional context
Is this functionality already supported? It didn't seem to be the case based on the README.

Fluent interface for using the core library

Is your feature request related to a problem? Please describe.
Not really a problem. Considering developer experience, the library API can be improved.

Describe the solution you'd like

With the fluent interface, the usage will look like this:

import smsReader from "react-native-expo-read-sms";

smsReader
  .withPermission()
  .onRead(sms => { 
    /* do something with SMS string */ 
    smsReader.stop()
  })
  .onFail(error => { 
    /* do something with error; maybe stop reading */ 
  })

Describe alternatives you've considered

Support for Config

See notes in context about supporting config that goes with auto stop mechanism. In that case, the signature of the interface changes:

smsReader() // without config
  .withPermission()
  .onRead(...)
  .onFail(...)

smsReader( { maxOnReads: 5, stopOnFail: false } )
  .withPermission()
  .onRead(...)
  .onFail(...)

Stop on failure

We can have implicit stop in case of failure so that the library user doesn't have to call stop inside onFail.

Additional context

  • In the fluent interface, the function withPermission() will ask for permission if not given already. If the user denies the permission, onRead will not be called.
  • As onRead and onFailure may be called multiple times, it's the user's responsibility to call stop whenever done. We can have an implicit limit on how many times onRead can be called. So that way even if the user forgets to call stop; we can stop listening whenever the counter completes. This counter mechanism can also allow (optional) configuration. Ideally that we can take as a param in the reader function: smsReader({ maxOnReads: 10 }). If the optional config is not provided, then the user will be smsReader()

Update Readme with desc

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Add a simple Description in the read me

Describe alternatives you've considered
N/A

Additional context
N/A

Upgrade eas-cli to 2.2.0

Is your feature request related to a problem? Please describe.
N/A

Describe the solution you'd like
Upgrade the eas-cli package to 2.2.0

Describe alternatives you've considered
N/A

Additional context
N/A

Gradle build is failing for lib v5.1.0

Describe the bug
Gradle builds fail on expo clouds

To Reproduce
Steps to reproduce the behavior:

  1. Import the latest version of 5.1.0
  2. Build the application

Expected behavior
The build should successfully complete

Gradle log

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':app:processDebugMainManifest'.

> Manifest merger failed : uses-sdk:minSdkVersion 21 cannot be smaller than version 33 declared in library [:maniac-tech_react-native-expo-read-sms] /home/expo/workingdir/build/node_modules/@maniac-tech/react-native-expo-read-sms/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 21

  	Suggestion: use a compatible library with a minSdk of at most 21,

  		or increase this project's minSdk version to at least 33,

  		or use tools:overrideLibrary="com.reactlibrary" to force usage (may lead to runtime failures)

* Try:

> Run with --stacktrace option to get the stack trace.

> Run with --info or --debug option to get more log output.

> Run with --scan to get full insights.

* Get more help at https://help.gradle.org/

BUILD FAILED in 4m 31s

Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

Expose `hasPermissions` function

Description:

We have hasPermissions which checks if we have the required SMS permissions in place.

Currently it is being used internally, but we wan it to be available outside the lib too.

Unable to install the library

Describe the bug
I created a brand new app for expo using this command
npx create-expo-app my-app
and tried to install the package
npm install @maniac-tech/react-native-expo-read-sms --save

To Reproduce
You can follow above steps

Expected behavior
No error should be there

Screenshots
image

Additional context
The temporary fix would be use npm i --force, but then I won't be able to build an app with it, as expo build uses npm i, which would result in an error

Support the library on expo v47

Is your feature request related to a problem? Please describe.
Support the library on expo v47.

Describe the solution you'd like
No new features, the existing features should work out of the box

Describe alternatives you've considered
N/A

Additional context
N/A

Add npm version in engines in package.json

          The error log shared in the original description mentions that there is a conflict of dependencies.

A simple way to resolve this temporarily is to use the attribute --forceor --legacy-peer-depsalong with npm install
The final command will look like: npm install --force/ npm install --legacy-peer-deps

Engineers are expected to install peer dependencies manually, this change was introduced in v3.x, and has been updated in v7.x of npm.

You may use the temporary solution for now, till I raise a PR to start using v7.x and above.

Originally posted by @maniac-tech in #19 (comment)

npm install error

error in installation

React-native version - 0.72.6

It is log :
'Log files:
C:\Users\BTC\AppData\Local\npm-cache_logs\2024-01-03T13_31_41_622Z-debug-0.log

npm resolution error report

While resolving: [email protected]
Found: [email protected]
node_modules/react-native
react-native@"0.72.6" from the root project

Could not resolve dependency:
peer react-native@"^0.69.9" from @maniac-tech/[email protected]
node_modules/@maniac-tech/react-native-expo-read-sms
@maniac-tech/react-native-expo-read-sms@"*" from the root project

Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

startReadSMS seems to be inactive

Describe the bug
Attached is the code snippet, where I tried to run, I have enable the permissions through the Popup, but startReadSms isn't getting called similar to Issue #18 .

import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View, Button } from "react-native";

import {
  checkIfHasSMSPermission,
  requestReadSMSPermission,
  startReadSMS,
} from "@maniac-tech/react-native-expo-read-sms";

export default function App() {
  const successHandler = (status, sms, error) => {
    console.log(status);
  };
  const errorHandler = (status, sms, error) => {
    console.log("error");
  };
  const btnHandler = async () => {
    try {
      const permissionState = await checkIfHasSMSPermission();

      if (permissionState.hasReadSmsPermission)
        await startReadSMS(successHandler, errorHandler);
    } catch (error) {
      console.log("error");
      console.log(error.message);
    }
  };

  return (
    <View style={styles.container}>
      {/* <Text>Open up App.js to start working on your app!</Text> */}
      <Button title="set sms" onPress={btnHandler} />
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

To Reproduce
Steps to reproduce the behavior:
You can copy and paste above code in the latest expo app

Expected behavior
It should return me the latest sms received

Screenshots
image
Although the function initiates warning but doesn't return the sms as stated.

Additional context
I have enabled all the permissions, Do let me know If I am missing something.

Possible Unhandled Promise Rejection (id: 1)

This is the error that i'm receiving from my android virtual device
WARN Possible Unhandled Promise Rejection (id: 1):
TypeError: Cannot read property 'startReadSMS' of null
TypeError: Cannot read property 'startReadSMS' of null

and this is the error i'm getting from my iphone
"PermissionsAndroid" module works only for Android platform.
LOG READ_SMS_PERMISSION_STATUS, RECEIVE_SMS_PERMISSION_STATUS: null false

Upgrade to expo v47

Is your feature request related to a problem? Please describe.
N/A

Describe the solution you'd like
N/A

Describe alternatives you've considered
N/A

Additional context
N/A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.