EddyVerbruggen / SocialSharing-PhoneGap-Plugin

👨‍❤️‍💋‍👨 Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 906 forks source link

WhatsApp sharing for a spefic number for android and iOS #488

Closed ssj7 closed 6 years ago

ssj7 commented 8 years ago

Hello, Can that be achieved using this plugin? For iOS there's href="whatsapp://send?text=HelloWorld&abid=9663 abid being the Address book ID, or id in the official cordova contacts plugin I'm hoping for something like

or for the number directly like: cordova.plugins.Whatsapp.send("1112223333"); https://github.com/ranjitpandit/whatsapp-phonegap-plugin (tried this plugin, but it didn't work out for me)

Thanks a lot! your SocialSharing plugin is really, really useful.

EddyVerbruggen commented 8 years ago

Afaik the abid is a whatsapp-specific id, which you can't retrieve with this plugin. If you know it I could add a method to use the abid and send it to whatsapp, but first plz figure out how to get that abid in the first place.

ssj7 commented 8 years ago

Yes, sorry about not mentioning that. I know how to get the abid from the cordova contacts plugin [button onclick="navigator.contacts.pickContact(function(contact){alert('Contact details:'+JSON.stringify(contact));},function(err){alert('Error: ' + err);});">Get contacts info</button] gap:plugin name="org.apache.cordova.contacts" Can you please add the sharing to specific number via abid? that would be very helpful. Thanks in advance.

EddyVerbruggen commented 8 years ago

Ha, interesting!

Please see this doc and give the master repo a spin.

ssj7 commented 8 years ago

Nice! sorry I had a deadline coming in two days and even the UI wasn't fully ready :) Doesn't seem to work on Android. It crashes bluestack and dosen't respond on an actual device. I used the npm source with pg build, does it include this function?

EddyVerbruggen commented 8 years ago

No, not on npm, only when using 'https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin' directly.

But I've now published version 5.0.7-a (or 5.0.7.1) to npm, so grab that and plz try again.

ssj7 commented 8 years ago

Thanks a lot. Sorry for the late reply, I'm getting "Error - Plugin (or a specific plugin version) not found in external repo: cordova-plugin-x-socialsharing "

I'll test it on android, ios and bluestacks.

EddyVerbruggen commented 8 years ago

What did you do to get that error exactly?

ssj7 commented 8 years ago

That's what pg build gives "Error - Plugin (or a specific plugin version) not found in external repo: cordova-plugin-x-socialsharing - You can fix this here" Just a sec, I'll try re-building without using the version number.

ssj7 commented 8 years ago

The building went fine, I'll test it on device and get back to you.

ssj7 commented 8 years ago

Same as before the plugin doesn't seem to be installing corretly when I use gap:plugin name="cordova-plugin-x-socialsharing" source="npm" version="5.0.7.1" or gap:plugin name="cordova-plugin-x-socialsharing" source="npm" version="~5.0.7.1" or gap:plugin name="cordova-plugin-x-socialsharing" source="npm" I'll test it again using the github one this time. I'm using phonegap build btw. I've tested on it on android, ios and bluestacks. Edit: spec="5.0.7.1" must used instead of version="~5.0.7.1" , retrying. Edit2: it is 5.0.7-a according to the npm source. Edit3: Works perfectly on iOS! on android I've used my own whatsapp number so it prompted me to send an invite, but seems to be working fine. I'll change the number and let you know how it plays out. Edit4: on android it prompts to send an invite with any local number, I'll try with the country key added screenshot_2015-12-21-23-12-07 :

ssj7 commented 8 years ago

Finally got it to work on android! :) the country key must be there. 00 will not work, it must be + sign followed by the country key then the number i.e +310433885282. 00310433885282 won't work. The message doesn't appear on WhatsApp's text area though. I've used 'text msg', could it be the space(encode needed?)? Edit: the message issue is an android-only issue, same message works fin on iOS. Thanks a lot! even without the text message it's already very useful enough to me. Well done.

ssj7 commented 8 years ago

Hello, just checking if you've seen my test results and edits :) the (untested at the moment) in the #whatsapp made me wonder. Many Thanks.

techashish12 commented 8 years ago

it open chat window of the reciver but the message does not appear in whatsapp text area.

jicelhay commented 8 years ago

I have the same issue, it finds the receiver but it doesn't show the message.

Dineshrajaa commented 8 years ago

+1

Dineshrajaa commented 8 years ago

similar issues #510 , #525 , #545 ..

SandroGrzicic commented 8 years ago

Hi, I'm using cordova-plugin-x-socialsharing 5.0.11 "SocialSharing" and trying to directly start a chat with a specific Whatsapp number. On Android it works when putting the number as the id, but on iOS even after inserting a new contact and using it's abid (or the abid of an existing contact), Whatsapp does open but on the "Recent Chats" screen instead of starting a chat with that contact directly (the chat is actually right there in Recent chats, but not opened).

I'm using this:

window.plugins.socialsharing.shareViaWhatsAppToReceiver(abid, 'msg', null, null, function (message) { /* success handler */ }, function (error) { /* error handler */ });

By reading the plugin code, it seems that it calls openURL:whatsapp://send?abid=<myAbid> - I tried that too using another plugin and it resulted in the same behaviour.

I suppose the only thing that can be wrong then is the abid? Is there are chance Whatsapp removed this support from their app? It seems that it still works on the Android version but not on the iOS version.

evliya commented 8 years ago

I am getting the following error while using the shareViaWhatsAppToReceiver function.

$cordovaSocialSharing.shareViaWhatsAppToReceiver is not a function

The method exists in the SocialPlugin.js file, but does not show up in Chrome debugging.

I tried the latest plugin version (5.0.12-dev) which installs as default. I also downgraded to 5.0.11 but still the same. Am I doing something wrong?

ssj7 commented 8 years ago

@SandroGrzicic it should be window.plugins.socialsharing.shareViaWhatsAppToReceiver(contacts[i].id, 'msg', null, null); @evliya you better use window.plugins.socialsharing.shareViaWhatsAppToReceiver not just shareViaWhatsAppToReceiver() or socialsharing.shareViaWhatsAppToReceiver() Edit: My example does not include the success/error handler.

SandroGrzicic commented 8 years ago

@ssj7 yes the abid is the contact ID as created or found by the contacts plugin. Are you saying that it works (directly opens the chat with that contact) for you on iOS with the latest Whatsapp version?

ssj7 commented 8 years ago

Yes, it has always worked for me. Try it.

SandroGrzicic commented 8 years ago

@ssj7 can you do a quick check with the latest version of Whatsapp? I have noticed some change in their API docs, perhaps they removed the feature in the latest version? I just cannot get the correct chat window open. No matter what I do, it always goes opens Whatsapp (on iOS) in Recent Chats. Even when I type directly window.open("whatsapp://send?abid=15", '_system'); (where 15 is the abid of the correct contact), it just opens Recent chats. Thanks.

ssj7 commented 8 years ago

Just tested the latest build I made (on 12/18/2015) on iOS worked fine. Sorry I can't find the source www.zip I used for that build to test it against the latest build of the plugin. The 12/18/2015 build of my app(and the plugin) still works fine with the newest version of WhatsApp though. I'll test it and let you know as soon as I find it. Sorry, it has been a while since I've worked on that one. Worst case scenario I'll just extract the www folder of the ipa or the apk and try to rebuild the xml config.

SandroGrzicic commented 8 years ago

Thanks, no problem. I don't think there's really an issue with the plugin, the code is really straightforward, it looks more like an issue with Whatsapp, as I said above I even tried doing a window.open - just refuses to work. The only options I see are that for some reason the abid I get from the Contacts plugin (really using just contacts[0].id) is not valid, or Whatsapp changed their support for this (or something completely unrelated is the issue).

SandroGrzicic commented 8 years ago

Another thing I found is that since on Android you need to create the contact first before sharing to that contact (otherwise you get the nasty Whatsapp "Contact is not on whatsapp" prompt), it seems that sometimes if I open Whatsapp using window.plugins.socialsharing.shareViaWhatsAppToReceiver(mobile, '', null, null, function (message) { ... });, sometimes it starts fine, but sometimes it shows the nasty prompt instead. I have tried to add a delay after creating the contact but it didn't seem to help much. Any idea what's going on? Perhaps creating a contact using the cordova contacts plugin doesn't make the contact immediately accessible to Whatsapp?

Combined with the above iOS issue of being unable to directly start a chat with a number, it seems that Whatsapp has huge issues with this (I tested on a number of devices).

joaosore commented 7 years ago

good evening

I am experiencing the following problem when using a code. It opens WhatsApp but the message field is not filled. Can someone tell me what to do?

< button onclick="window.plugins.socialsharing.shareViaWhatsAppToReceiver('+55 11 0000-0000', 'Message via WhatsApp', null /* img */, null /* url */, function(message) {console.log('share ok')})">msg via WhatsApp for Addressbook ID 101</ button>

Source: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin#phonegap-build

shineirvin commented 7 years ago

Im experiencing the same issues as @joaosore + if you put the img url, the app will crash. Please help.

AbraXus commented 7 years ago

I'm also experiencing the same as @joasore. shareViaWhatsAppToReceiver() on android leaves the message field empty. Does anyone have an idea on how to fix this?

FittinRoom commented 7 years ago

Observed the same behavior. would be great to be able to automatically fill the message for a specific contact on android devices please :) !

webvanced commented 7 years ago

We had the same problem with this in ionic. We could not get the intent system to work from within ioninc/cordova. It seems it's possible to send a message to a specific phone number like this:

<a href="whatsapp://send?text=Hello&phone=+316********">Message</a>

On iOS it seems to work with the abid parameter. So putting both in the url should do it.

<a href="whatsapp://send?text=Hello&phone=+31611111111&abid=+31611111111">Message</a>

I don't know why this is not documented anywhere but for now it seems to work.

You need this in config.xml:

<allow-intent href="whatsapp:*"/>

TechSnake commented 7 years ago

First ,how to use this code,below? is there any proper example ? Second,is there any way to send a message to multiple receivers at Whatsapp ? Thank you in Advance

We had the same problem with this in ionic. We could not get the intent system to work from within ioninc/cordova. It seems it's possible to send a message to a specific phone number like this:

<a href="whatsapp://send?text=Hello&phone=+316********">Message</a>

On iOS it seems to work with the abid parameter. So putting both in the url should do it.

<a href="whatsapp://send?text=Hello&phone=+31611111111&abid=+31611111111">Message</a>

I don't know why this is not documented anywhere but for now it seems to work.

You need this in config.xml:

<allow-intent href="whatsapp:*"/>

ahoebeke commented 6 years ago

Works for Android, however for iOS the abid parameter value needs to be something different apparently.. Doesn't work for me on iOS in any case.

Thanks for the great find however! :)

EddyVerbruggen commented 6 years ago

Hi! If you want this fixed please reopen with a suggested solution.

eduardolopesUFJF commented 6 years ago

Hi @SandroGrzicic! Did you find some fix to issue? I want to open a chat with specif abid contact, but just work on Android. Thanks!

sksk008 commented 6 years ago

if u want to chat with specific person in whatsapp then here is the solution.

//in my html or template openURL('whatsapp://send?text=Hello&phone=+919904880561')

//in my controller $scope.openURL = function(num){ window.open(url,"_system","location=yes"); };

EddyVerbruggen commented 6 years ago

Thanks for sharing. The latest version of this plugin also supports this feature. See https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin#by-phone-number-since-530

eduardolopesUFJF commented 6 years ago

Hi @krunalsk007 and @EddyVerbruggen. For this works fine, I have to add some preference on config.xml? I'm with 5.3.0 version and the problem persists.

Remember that for Android works perfectly, but for ios the whatsapp is opened in recent chats.

eduardolopesUFJF commented 6 years ago

@EddyVerbruggen I'm making the following called: window.plugins.socialsharing.shareViaWhatsAppToReceiver('2','test',null,null); I get the abid 2 using the contacts plugin and I already check, the code is correct.

The WhatsApp is called, but in recent chats, never in chat with the contact passed by abid code.

Did you can see anything wrong?

I'm testing in iOS 9, but on iOS 11 happens too. I'm using the socialsharing plugin version 5.3.0 and iOS platform 4.5.4, remember that I'm trying make the call using an Ionic app.

I'm trying solved this for weeks, help me please.

Thanks.

EddyVerbruggen commented 6 years ago

@eduardolopesUFJF Did you try the new shareViaWhatsAppToPhone?

eduardolopesUFJF commented 6 years ago

@EddyVerbruggen this works to iOS too?

EddyVerbruggen commented 6 years ago

Yes, but not for images. It's in the readme I linked to..

eduardolopesUFJF commented 6 years ago

Wonderfull, I will need just for send text. I will test and let you know. Thank you so much.

eduardolopesUFJF commented 6 years ago

Works perfectly well! Really really really THANK'S @EddyVerbruggen! Did you save my life!

EddyVerbruggen commented 6 years ago

Awesome, thanks for the feedback!

osmanc777 commented 4 years ago

Hi @eduardolopesUFJF

One question, did this work for ionic 3?

if that's how you implemented it,

since using the plugin: https://ionicframework.com/docs/v3/native/social-sharing/

I can't access the shareViaWhatsAppToPhone function

Captura de Pantalla 2019-11-11 a la(s) 16 15 18

thanks for your help.

vousys commented 3 years ago

In ios13.5 we couldn't use it, it says "can't open the link". We have to switch to the tipical href https://wa.me/+number?text=Contact