mgp25 edited this page Nov 7, 2015 · 5 revisions


####What is sync?

Detects whether the contacts in your address book has WhatsApp or not, if your contact has WhatsApp, it will be added to your WhatsApp contact list and linked to your number. In other words, tells WhatsApp server which are the phone numbers that we are going to interact with.

You should always sync new phone numbers before sending them messages. The risk, if you don't sync your contacts, is to get your phone number blocked/banned from WhatsApp.

####When should i use sync?

The sync process involves 2 variables: mode and context. These are the most common combinations of the variables:

  • mode = 'full', context = 'registration' used to sync the entire collection of contacts the first time (use a flag to know when it is the first time you do that)
  • mode = 'full', context = 'interactive' full sync when you login, you can do it every time but if you reconnect often, you should pay attention to backoff and move the sync to a periodic task
  • mode = 'delta', context = 'interactive' incremental contacts sync. It will add one or more contacts to the existing contacts list. It should be used when you are interacting with a new contact

First Sync (Registration)

$myContacts = array('123456789', '987654321');
$w->sendSync($myContacts, null, 0);

Delta Sync (Addind contacts)

$newContact = '123456789';

Deleting contacts

$newContact = '123456789';
$deleteContact = '987654321';
$w->sendSync($newContact, $deleteContact);

Other types of sync:

$mode = "full", $context = "interactive"
$mode = "full", $context = "background"
$mode = "delta", $context = "interactive"
$mode = "query", $context = "interactive"
$mode = "chunked", $context = "registration"
$mode = "chunked", $context = "interactive"
$mode = "chunked", $context = "background"

####Can i send a message without syncing?

No. It's a must to sync the contact before interacting with the user (you can't interact with someone you don't have in your WhatsApp contact list).

###Can I sync a number more than once?

####How can i check the sync result?

You can use onGetSyncResult and bind the event to this function:

function onSyncResult($result)
    foreach ($result->existing as $number) {
        echo "$number exists<br />";
    foreach ($result->nonExisting as $number) {
        echo "$number does not exist<br />";
    die();//to break out of the while(true) loop

There is sync example in /examples/contactsync.php

Contacts sync is required, as stated by the WhatsApp FAQ.

Activity that can lead to this temporary ban includes: - Sending too many messages to users who do not list you in their address books. Make sure that you ask all of your WhatsApp contacts to add your current number to their address books.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.