React native send a message to specific whatsapp Number

穿精又带淫゛_ 提交于 2019-12-03 17:22:47

问题


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 code above opens only whats app , i need to open a chat with a specific number is there a paramter i have to send like text ?!


回答1:


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

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




回答2:


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


来源:https://stackoverflow.com/questions/43518482/react-native-send-a-message-to-specific-whatsapp-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!