【问题标题】:React native send a message to specific whatsapp NumberReact native 向特定的 whatsapp 号码发送消息
【发布时间】:2017-09-17 00:37:46
【问题描述】:

我正在尝试从 react-native 应用程序向 WhatsApp 联系人发送短信,我发现我可以通过链接来做到这一点

Linking.openURL('whatsapp://send?text=hello');

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

【问题讨论】:

  • whatsapp://send?abid=(ID)&text=hello
  • 这只会打开屏幕共享,并要求我选择要与哪个帐户共享我的消息!我需要打开与特定用户的直接聊天
  • 你也可以给我看一下 abid 的格式吗?

标签: reactjs react-native whatsapp


【解决方案1】:

您可以使用它向特定号码发送消息:

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

【讨论】:

  • 嗨,linkedIn 怎么样!我和linkedIn个人资料一样
  • 如何将图片与文字一起发送
  • 如何发送到 WhatsApp 业务
  • 嗨,我如何在 facebook、twitter、pinterest、google plus 等其他社交媒体上分享特定的文本或数据。
  • @ShaileshPrajapati 我认为相同的链接会在移动设备上打开可用的链接,或者如果两者都可用则选择一个
【解决方案2】:

您可以使用此方法将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');
 }
};

【讨论】:

  • API url 可以是:https://api.whatsapp.com/send?phone=+31612345678
【解决方案3】:

将消息分享到 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中打开,请在手机前发送+国家/地区

【讨论】:

    猜你喜欢
    • 2013-09-04
    • 2015-07-08
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2021-06-13
    • 2013-09-24
    • 1970-01-01
    相关资源
    最近更新 更多