React native send a message to specific whatsapp Number

前端 未结 3 2125
野的像风
野的像风 2021-02-02 11:13

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?t         


        
相关标签:
3条回答
  • 2021-02-02 11:17

    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');
     }
    };
    
    0 讨论(0)
  • 2021-02-02 11:21

    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

    0 讨论(0)
  • 2021-02-02 11:23

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

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

    0 讨论(0)
提交回复
热议问题