Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ssj7 opened this issue Dec 17, 2015 · 46 comments
Closed

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

ssj7 opened this issue Dec 17, 2015 · 46 comments

Comments

@ssj7
Copy link

ssj7 commented Dec 17, 2015

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
msg via WhatsApp (with errcallback)

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
Copy link
Owner

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
Copy link
Author

ssj7 commented Dec 17, 2015

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
Copy link
Owner

Ha, interesting!

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

@ssj7
Copy link
Author

ssj7 commented Dec 20, 2015

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
Copy link
Owner

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
Copy link
Author

ssj7 commented Dec 21, 2015

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 "
<gap:plugin name="cordova-plugin-x-socialsharing" source="npm" version="5.0.7.1"/>
I'll test it on android, ios and bluestacks.

@EddyVerbruggen
Copy link
Owner

What did you do to get that error exactly?

@ssj7
Copy link
Author

ssj7 commented Dec 21, 2015

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
Copy link
Author

ssj7 commented Dec 21, 2015

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

@ssj7
Copy link
Author

ssj7 commented Dec 21, 2015

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
Copy link
Author

ssj7 commented Dec 21, 2015

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
Copy link
Author

ssj7 commented Jan 3, 2016

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
Copy link

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

@jicelhay
Copy link

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

@Dineshrajaa
Copy link

+1

@Dineshrajaa
Copy link

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

@SandroGrzicic
Copy link

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
Copy link

evliya commented Mar 22, 2016

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
Copy link
Author

ssj7 commented Mar 23, 2016

@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
Copy link

@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
Copy link
Author

ssj7 commented Mar 23, 2016

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

@SandroGrzicic
Copy link

@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
Copy link
Author

ssj7 commented Mar 23, 2016

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
Copy link

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
Copy link

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
Copy link

joaosore commented Dec 18, 2016

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
Copy link

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

@AbraXus
Copy link

AbraXus commented Jan 30, 2017

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
Copy link

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

@webvanced
Copy link

webvanced commented Mar 15, 2017

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
Copy link

TechSnake commented Mar 20, 2017

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
Copy link

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
Copy link
Owner

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

@eduardolopesUFJF
Copy link

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
Copy link

sksk008 commented Feb 21, 2018

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
Copy link
Owner

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
Copy link

eduardolopesUFJF commented Feb 21, 2018

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
Copy link

eduardolopesUFJF commented Feb 22, 2018

@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
Copy link
Owner

@eduardolopesUFJF Did you try the new shareViaWhatsAppToPhone?

@eduardolopesUFJF
Copy link

@EddyVerbruggen this works to iOS too?

@EddyVerbruggen
Copy link
Owner

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

@eduardolopesUFJF
Copy link

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

@eduardolopesUFJF
Copy link

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

@EddyVerbruggen
Copy link
Owner

Awesome, thanks for the feedback!

@osmanc777
Copy link

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
Copy link

vousys commented Jul 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests