React native send a message to specific whatsapp Number

自闭症网瘾萝莉.ら 提交于 2019-12-03 05:56:30
Mahmoud

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

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

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');
 }
};

Here is another way which will open the WhatsApp.

<Text
    style={{marginTop:30}}
    onPress={() => {
        Linking.openURL(
          'http://api.whatsapp.com/send?phone=91' + XXXXXXXXXX
        );
    }}>
    Send WhatsApp Message
</Text>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!