React native send an automatic message without opening whatsapp - react-native

I'm trying to send a text message to a WhatsApp contact from a react-native apps , i found that i can do it through Linking
Linking.openURL('whatsapp://send?text=hello');
the above code opens whatsapp. I would like to send message without opening whatsapp

you can do it using Share.shareSingle from react-native-share package
const shareOptions = {
title: 'Share via',
message: 'some message',
url: 'some share url',
social: Share.Social.WHATSAPP,
whatsAppNumber: "9199999999", // country code + phone number
filename: 'test' , // only for base64 file in Android
};
Share.shareSingle(shareOptions)
.then((res) => { console.log(res) })
.catch((err) => { err && console.log(err); });
The shareSingle() method allows a user to share a premade message via
a single prechosen social medium. In other words, code specifies both
the message that will be sent and the social medium through which the
message will be sent. The user chooses only to whom the message is
sent. This shared message may contain text, one or more files, or
both.
Checkout - https://react-native-share.github.io/react-native-share/docs/share-single
also i've given working example to share multiple or single images using react-native-share as answer to a question about how to do it. might be useful.
Checkout Here

Related

expo-mail-composer is working properly on my emulator as well as on my actual device, but not on the client's

This is quite possibly user error, although I cannot really discern how that would be the case here. I have a react native app that has the feature to record and then email videos. It works pretty simply, you press the button to enter the in-app camera, press record to record and stop to stop. Once stopped, the video is saved to the phone, and then two buttons appear; 'cancel' and 'send video'
When send video is pressed, a email composer pops up with some pre-filled information, and you can compose and send an email off of your phone just like you normally would. This works all as expected on my end, but when a client presses the 'send video' button, nothing happens. No error, no email pop up, just nothing.
I've confirmed that she signed up with her email, I've investigated the database and that's true-- so I don't quite understand what could be missing. I tried an emulator for her exact device type and it worked well, so this has to be user error or something with permissions, right?
This is the function that gets run when 'send video' is clicked...
// Sends the Video, triggers the message, opens the modal
function handleSendVid(){
saveVidToLib()
.then(resolved => {
emailVid(resolved)
})
.then(() => {
if (user.role === "GUARDIAN"){
handleSendMessage()
}
})
}
With emailVid() looking like this...
// Emails the now saved video
async function emailVid(video){
MailComposer.composeAsync({
recipients: [therapist.email],
subject: `Video Of Exercise From: ${user.firstName} ${user.lastName}`,
body: "Beta Testing",
attachments: [videoPath]
})
.catch((err) => console.log(err))
.then(() => {
setEmailSent(true)
})
}

Want to share multiple images with separate caption to each image Whatsapp, react native share

I am using React Native Share library, a good one,
I just need little help,
It is sharing multiple images with same caption,
i just want to share multiple images with separate message (caption) to each image,
suppose, if there is 5 images, then caption to 5 images is different not same.
In current situation, it share 5 images with same message (caption)
Here is my code
var imgs=["base64IMAGE1...///","base64IMAGE2..///","base64IMAGE3..///"];
let shareImage = {
title:"title",
message:"this is message need to send separate to each image",
urls:abcc,
subject: "Image"
};
Share.open(shareImage).catch(err => console.log(err));
I have attached current situation screenshots..
image 1 on whatsapp
image 2 on whatsapp
all sent with same caption, i just to send multiple images with separate messages
ThankYou.
I've created working example to share multiple or single images using react-native-share
CheckOut ExpoSnack Here
added comments before every method what it'll do and what needs to be replaced.
// multiple images share example
const shareMultipleImages = async () => {
const shareOptions = {
title: 'Share multiple files example',
// here replace base64 data with your local filepath
// base64 with mimeType or path to local file
urls: [base64ImagesData.image1, base64ImagesData.image2],
failOnCancel: false,
};
// If you want, you can use a try catch, to parse
// the share response. If the user cancels, etc.
try {
const ShareResponse = await Share.open(shareOptions);
setResult(JSON.stringify(ShareResponse, null, 2));
} catch (error) {
console.log('Error =>', error);
setResult('error: '.concat(getErrorString(error)));
}
};
you can add local file path in shareMultipleImage method like this
urls: Array of base64 string you want to share. base64 with mimeType or path to local file (Array[string])
React Native Share Docs
const shareOptions = {
title: 'Share multiple files example',
urls: ["file..///","file..///","file..///"],
failOnCancel: false,
};

Sending Email in React Native

I am working on a React Native application. I need to send an email using an Email service, like an API. Can anyone please guide me through the process?
In your scenario, you can use Linking in react native.
Import this first
import { Linking } from 'react-native'
React Native Open Mail Function :
<Button onPress={() => Linking.openURL('mailto:support#example.com') }
title="support#example.com" />
React Native Open Mail Function With Subject and Body
<Button onPress={() => Linking.openURL('mailto:support#example.com?subject=SendMail&body=Description') }
title="support#example.com" />
React Native Open URL
<Button onPress={() => Linking.openURL('https://www.google.co.in/') }
title="www.google.co.in" />
More Details :
mailto:?subject=&body=&cc=
<receiver_email> Important value. The email address to send email.
<subject> default email subject that will attach to new email (option)
<body> default email text (option)
<emails_to_copy> list of emails to copy (option)
Example Full Code
// send-email.js
// We can use react-native Linking to send email
import qs from 'qs';
import { Linking } from 'react-native';
export async function sendEmail(to, subject, body, options = {}) {
const { cc, bcc } = options;
let url = `mailto:${to}`;
// Create email link query
const query = qs.stringify({
subject: subject,
body: body,
cc: cc,
bcc: bcc
});
if (query.length) {
url += `?${query}`;
}
// check if we can use this link
const canOpen = await Linking.canOpenURL(url);
if (!canOpen) {
throw new Error('Provided URL can not be handled');
}
return Linking.openURL(url);
}
// example.js
import { sendEmail } from './send-email';
sendEmail(
'test#gmail.com',
'Greeting!',
'I think you are fucked up how many letters you get.'
).then(() => {
console.log('Our email successful provided to device mail ');
});
For sending emails as background service :
I think you need a e-mail server or atleast an email service to send an email with your app. I don't think you can send e-mails directly from the client side.
But there are various email services on the Internet that you can use for free (like Mailgun or SendPulse. There you can just use a simple POST method from the code in your app against their APIs.
If you wan to send email using SMTP protocol then you can use the react native smtp module or react-native-smtp-mailer. You can read about it from here.
I am answering this question myself to help others, providing them with an easy email service they might be looking for.
A third-party API provider that provides the email services, sandbox environment is also available for testing purposes. Here's the link for reference.
https://cloudinary.com/visualweb/display/IMMC/React+Native+Image+Upload
Thanks.

How to share file using bluetooth in react-native

I have a requirement in my new project to share files using Bluetooth.
I have searched many share plugins for react native but unable to get a Bluetooth option. So far I am using react-native-share and I am able to achieve share via e-mail and WhatsApp but now I need Bluetooth also.
shareWhatsapp(way){
const shareOptions = {
title: 'Share via',
message: 'some message',
url: self.state.path_share,
type:'pdf',
subject:'Sma Report',
social:way,
showAppsToView:true
};
Share.shareSingle(shareOptions);
}
in way parameter I am passing
for WhatsApp Share.Social.WHATSAPP and Share.Social.EMAIL for email.

Send push notifications to a specific logged user with pinpoint

Im developing a react native app integrated with aws-amplify and aws mobile hub.
We currently logged our user into cognito.
im trying to send a push notification to a specific endpoint Id, but i cannot see how to set that endpointId, in the node js (im using lambda) documentation for pinpoint only exist getEnpoint, but requires EnpointId and i cannot find where is it.
app.post('/asdf/get/endpoint', function (req, res) {
pinpoint.getEndpoint({
ApplicationId: APP_ID_PINPOINT,
EndpointId: req.body.userId
}, (err, data) => {
if (err) {
res.json({ error: err });
} else {
res.json({ data: data });
}
});
});
How can set the enpointId (userId) to an already logged user and then, every time i need to send a push to him i just get that enpoint and send a push to all the devices attached to it?
Or, i have to store all the tokens from the user (DynamoDb), and send messages to all the devices separately? (with pinpoint sendMessage)