问题
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