Export whatsapp messages to react-native app - react-native

I'm trying to access whatsapp messages from my device with react-native. Accessing them directly seems impossible so I was looking into the possibility of exporting the messages and importing them in my app. The options which are currently provided by whatsapp sharing menu lack any direct download option.
Is there a way to add my app to the whatsapp sharing menu? Or is there an easy way to import these messages?

You can use https://github.com/meedan/react-native-share-menu this library for exporting chat from Whatsapp. When you export chat file from WhatsApp, your app will show on the share dialog. After that, you can open that file from your app like below
ShareMenu.getSharedText((text :string) => {
if (text && text.length) {
if (text.startsWith('content://media/')) {
//this will be a media
} else {
content = this.readFile(text)
}
}
})
Then you can read the content of that file using RNFS library
readFile = async (path) => {
try {
const contents = await RNFS.readFile(path, "utf8");
return("" + contents);
} catch (e) {
alert("" + e);
}
};
After getting the content of the chat, you can parse that chats.

We had the same issue when building a Website to analyze WhatsApp chats, as with android you can not save the exported chat on the device.
Our solution was to use a PWA (Progressive Web App) and listen share Events.
When somebody now installs the PWA, they can share the export with the App directly. (Currently, this is only supported for Android with Chrome, as Apple is heavily against PWAs)
Our implementation:
if (workbox) {
workbox.addEventListener("message", (m) => {
// eslint-disable-next-line no-prototype-builtins
if (_this.$route.query.hasOwnProperty("receiving-file-share")) {
let files = m.data.file;
// currently only the first file, but ultimately we want to pass all files
_this.$refs.filehandler.processFileList(files, true);
}
});
workbox.messageSW("SHARE_READY");
}

Related

How to open URL with scheme intent:// on react native

I have a react native mobile app with a webview. In the webview I added the facebook messenger chat plugin so my users can easily contact us if they need help.
if you ran the website through a mobile browser it works. It redirects you to the official messenger.
But when you ran it through react native webview somehow it says No activity found to handle Intent
here is my code on how i handle the opening of the intent
onShouldStartLoadWithRequest={(request) => {
let url = request.url
if(url.startsWith('intent:')){
Linking.openURL(url).catch(er => {
console.log(er)
alert("Failed to open URL")
});
return false
}else{
return true
}
}}
this will console log
[Error: Could not open URL
'intent://user/107571147455693/?intent_trigger=mme&nav=discover&source=customer_chat_plugin&source_id=1507329&metadata=%7B%22referer_uri%22%3A%22https%3A%5C%2F%5C%2Ffusiontechph.com%5C%2Ff9fe1863270a2%22%7D#Intent;scheme=fb-messenger;package=com.facebook.orca;end':
No Activity found to handle Intent { act=android.intent.action.VIEW
dat=intent://user/107571147455693/?intent_trigger=mme&nav=discover&source=customer_chat_plugin&source_id=1507329&metadata={"referer_uri":"https://fusiontechph.com/f9fe1863270a2"}
flg=0x10000000 }]
I have a workaround that worked for me. Facebook messenger provides a link to your facebook page message. So you can just open that link directly without using the intent scheme of facebook here is the final code
onShouldStartLoadWithRequest={(request) => {
let url = request.url
if(url.startsWith('intent:')){
Linking.openURL('https://m.me/mluc.jsites').catch(e=>{
console.log(e) })
return false
}else{
return true
}
}}

Open Whatsapp from React Native app with Expo

Currently trying to open whatsapp from my React Native app with Expo. I have the code below:
let url = 'whatsapp://app';
Linking.openURL(url).then((data) => {
console.log('WhatsApp Opened');
}).catch((err) => {
console.log(err);
alert('Make sure Whatsapp installed on your device');
});
The error I get is this:
Error: Could not open URL 'whatsapp://app': No Activity found to handle Intent { act=android.intent.action.VIEW dat=whatsapp://app flg=0x10000000 }
However when I change the url to send, it opens whatsapp fine?
whatsapp://send?phone=3464478983
I am trying to only open whatsapp without a send param

How to force users to update the app using react native

I have updated my app on app and play store and I want to force my app users to update the new version of app in App store and playstore.
You can check for the App Store / Play Store version of your app by using this library
react-native-appstore-version-checker.
In expo app you can get the current bundle version using Constants.nativeAppVersion. docs.
Now in your root react native component, you can add an event listener to detect app state change. Every time the app transitions from background to foreground, you can run your logic to determine the current version and the latest version and prompt the user to update the app.
import { AppState } from 'react-native';
class Root extends Component {
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextState) => {
if (nextState === 'active') {
/**
Add code to check for the remote app version.
Compare it with the local version. If they differ, i.e.,
(remote version) !== (local version), then you can show a screen,
with some UI asking for the user to update. (You can probably show
a button, which on press takes the user directly to the store)
*/
}
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
}
import VersionCheck from 'react-native-version-check';
i have used version check lib for this purpose and approach i used is below. if version is lower i'm opening a modal on which an update button appears, and that button redirects to app store/google play
componentDidMount() {
this.checkAppUpdate();
}
checkAppUpdate() {
VersionCheck.needUpdate().then(res => {
if (res.isNeeded) {
setTimeout(() => {
this.setState({openModal: true});
});
}
});
}
updateApp = () => {
VersionCheck.getStoreUrl({
appID: 'com.showassist.showassist',
appName,
})
.then(url => {
Linking.canOpenURL(url)
.then(supported => {
if (!supported) {
} else {
return Linking.openURL(url);
}
})
.catch(err => console.error('An error occurred', err));
})
.catch(err => {
console.log(`error is: ${err}`);
});
};
For future readers.
If you are using Expo managed workflow, install this package react-native-version-check-expo using yarn add react-native-version-check-expo or npm install react-native-version-check-expo.
Consult the package documentation on Github for usage guidelines.
I'm using react-native-version-check-expo library to achieve this. Working fine for me.
if you are looking for an easy to integrate built in solution. You can use App Upgrade https://appupgrade.dev/ service to force update your mobile apps.
Create new version entry for your app version that you want to update in the app upgrade service and select whether you want to force it or just want to let users know that new version is available.
Integrate your app with App Upgrade using available SDK. Official SDK are available for React Native, Flutter, Expo, Android and iOS(Swift).
The SDK will take care of the rest.
Whenever you want to force upgrade a version just create a version entry in app upgrade dashboard.
You can also integrate using API. Just call the appupgrade api from your app with the required details such as your app version, platform, environment and app name.
The API will return you the details.. that this app needs to be updated or not.
Based on the response you can show popup in your app.You can call this API when app starts or periodically to check for the update. You can even provide a custom message.
API response:
See the response has force update true. So handle in the app by showing popup.
You can find the complete user documentation here. https://appupgrade.dev/docs
Thanks.

React Native: How to open a Bitcoin URL?

How do you open a Bitcoin URL in a react native app? I am using React Native Linking to detect if there are any apps on the phone that can open a Bitcoin URL formatted according to BIP21. I have 3 apps installed that should handle it:
1) Coinbase
2) Breadwallet
3) Blockchain.info wallet
But it's not opening. Here's the code:
async _openWallet() {
const coinURL = 'bitcoin:15bMc6sQTiQ5jSqoRX3JzatAbQqJaffqup';
try {
const supported = await Linking.canOpenURL(coinURL);
if (supported) {
Linking.openURL(coinURL);
} else {
console.log('Could not find a compatible wallet on this device.');
}
} catch (error) {
console.log(error);
}
}
supported keeps returning false, which causes "Could not find a compatible wallet..." to execute. The weird thing is if I click on a Bitcoin URL on any random website via the Chrome / Safari browser, I get a popup that asks me if I want to open the URL in one of the above apps. So only URLs on websites are opening, but not URLs from inside react native code.
Any ideas?
Looks like every URI scheme you want to use at runtime must be defined up-front in Info.plist. Found the answer here: React Native: Linking API not discovering Uber app

Share json file to dropbox / one drive / google drive on an ios react-native app

I am writing an react-native ios application which generates text file. The file is stored at /var/mobile/Containers/Data/Application/76C594FD-282D-41B2-9BE6-B6B1C785BDE6/Documents/backup.json using react-native-fs.
I want to share this file to google drive/dropbox/microsoft one drive so I use the ActionSheetIOS.showShareActionSheetWithOptions API to share the file:
ActionSheetIOS.showShareActionSheetWithOptions({
url: '/var/mobile/Containers/Data/Application/76C594FD-282D-41B2-9BE6-B6B1C785BDE6/Documents/backup.json'
},
(error) => console.warn(error.message),
(success, method) => {
var text;
if (success) {
text = 'Shared';
} else {
text = 'Not shared';
}
console.warn(text)
})
but the share actions do not include either of google drive/onedrive/dropbox when I test on the device (screenshot available here).
Am I doing something wrong?
Looks like the device doesn't actually have google drive or dropbox installed. If those apps aren't installed, they won't be options for you to share to.