React native将消息发送到特定的whatsapp Number

时间:2017-04-20 11:38:04

标签: reactjs react-native whatsapp

我试图通过反应原生应用向WhatsApp联系人发送短信,我发现我可以通过链接

DataView dv = yourTable.DefaultView;
dv.Sort = "column_1,column_2";
DataTable dtNew = dv.ToTable(true, "column_1", "column_2",...,"column_n"); // please mention all columns here
dtNew.Rows.RemoveAt(0);

上面的代码只打开什么应用程序,我需要打开一个特定号码的聊天是否有一个参数我必须像文字一样发送?

4 个答案:

答案 0 :(得分:21)

您可以使用此功能将消息发送到特定号码:

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

答案 1 :(得分:2)

将消息共享给whatsapp,并与平台无关的特定预定义号码

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

请注意:如果在android中打开,请在带有国家/地区的电话前发送+

答案 2 :(得分:0)

您可以使用此方法将whatsApp消息直接发送给号码。

示例链接: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');
 }
};

答案 3 :(得分:0)

这是打开WhatsApp的另一种方法。

<Text
    style={{marginTop:30}}
    onPress={() => {
        Linking.openURL(
          'http://api.whatsapp.com/send?phone=91' + XXXXXXXXXX
        );
    }}>
    Send WhatsApp Message
</Text>