React native send a message to specific whatsapp Number

You can use this method to send whatsApp message direct to a number.

Example link: https://wa.me/919234567812?text=%7B0%7D+Balaji+CTest

export const sendWhatsAppMessage = link => {
 if (!isUndefined(link)) {
  Linking.canOpenURL(link)
   .then(supported => {
     if (!supported) {
      Alert.alert(
        'Please install whats app to send direct message to students via whats 
         app'
      );
    } else {
      return Linking.openURL(link);
    }
  })
  .catch(err => console.error('An error occurred', err));
} else {
  console.log('sendWhatsAppMessage -----> ', 'message link is undefined');
 }
};

share message to whatsapp to a specific predefined number independent to platform

sendWhatsApp = () => {
  let msg = "type something";
  let phoneWithCountryCode = "xxxxxxxxxx";

  let mobile =
    Platform.OS == "ios" ? phoneWithCountryCode : "+" + phoneWithCountryCode;
  if (mobile) {
    if (msg) {
      let url = "whatsapp://send?text=" + msg + "&phone=" + mobile;
      Linking.openURL(url)
        .then(data => {
          console.log("WhatsApp Opened");
        })
        .catch(() => {
          alert("Make sure WhatsApp installed on your device");
        });
    } else {
      alert("Please insert message to send");
    }
  } else {
    alert("Please insert mobile no");
  }
};

Please Note: send + in front of phone with country if opening in android


You can use this to send a message to specific number:

Linking.openURL('whatsapp://send?text=hello&phone=xxxxxxxxxxxxx')