4

Yesterday Whatsapp updated their iOS application and released official URL scheme (api hooks).

I wanted to play a little with it and I'm now facing the problem that I don't understand this whole "abid" thing?! Where do I get the contact ID from? And how do I have to use it then?

Thanks in advance :)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Constantin Jacob
  • 488
  • 1
  • 8
  • 21
  • 1
    What are you trying to do? What is your goal, your product, your purpose? – CaptJak Jul 17 '13 at 22:27
  • Okay so first of all I'm just trying to understand how it works. But thought about having something and then share it directly via Whatsapp ? Right now I'm just entering the url schemes in Safari on my iPhone... – Constantin Jacob Jul 17 '13 at 22:30

6 Answers6

10

ABID stands for the Address book Record ID,the code below works to get the AB Record ID. It is sensitive to the use of delimeters in the URL itself. So the initial trials were not working. To send a note to a specific user use this - urlstring format: whatsapp://send?abid=123&text=What%20a%20nice%20day - note the use of & to mark the second parameter.

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController    *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{   
    QR_whatsappABID  = (ABRecordID)ABRecordGetRecordID(person);
    ....
    QR_whatsapp_string = [NSString stringWithFormat:@"whatsapp://send?abid=%d&text=%@;",QR_whatsappABID, outmessage];
    ....
}

this can be coded without using the people picker simply open the address book:

go through the records one by one comparing the name or name and number -

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions (NULL, error);
int len = (int)ABAddressBookGetPersonCount(addressBook);
for(int i = 1; i < (len + 1); i++) {
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, (ABRecordID)i);
    NSString *first, *last;
    if (!person) {
        continue;
    }
    CFStringRef firstc = (CFStringRef)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    if (firstc) {
        CFStringRef lastc =(CFStringRef) ABRecordCopyValue(person, kABPersonLastNameProperty);
        if (lastc) {
            first = [NSString stringWithFormat:@"%@",firstc];
            last =[NSString stringWithFormat:@"%@",lastc];
            CFRelease(lastc);
        }
        CFRelease(firstc);
    }
    if ([[first lowercaseString] isEqualToString:[firstname lowercaseString]] && [[last lowercaseString] isEqualToString:[surname lowercaseString]]) {
        alreadyExists = YES;
        ABID = ABRecordGetRecordID(person);
        break;
    }
}
jamesh
  • 19,863
  • 14
  • 56
  • 96
Paulo
  • 1,245
  • 10
  • 8
  • ABID stands for the ABRecordID - and the example above works - turned out I was sruggling with the delimeters in the URL itself: ... It works as follows: QR_whatsapp_string = [NSString stringWithFormat:@"whatsapp://send?abid=%d;?text=%@;",QR_whatsappABID, outmessage]; – Paulo Jul 23 '13 at 12:06
  • Constantin, the AB Record ID is assigned to each record in the address book. It is unique within an address book source but it will change across devices.There are a few ways to get to the address book but the most common way is through peoplepicker controllers where your viewcontroller acts as a delegate (example above). there is also a way to use one of the addressbook functions to populate an NSArray object with the addressbook contents. It's interesting but with a certain difficulty compared to regular UIKit programming. – Paulo Jul 23 '13 at 12:38
4

Please note that Whatsapp has removed (during March '16) the URL Schema to open a conversation with a specific contact.

As you can see on their Custom URL Scheme page there is no more the ABID parameter.

andreacipriani
  • 2,519
  • 26
  • 23
2

I've written up one way to get the ABIDs in bulk here: http://n8henrie.com/2014/02/how-to-get-the-abid-for-whatsapp-url-schemes/

The basic idea is to use iFunBox to access an sqlite database on your phone, then run a script that extracts all of the ABIDs and names.

n8henrie
  • 2,737
  • 3
  • 29
  • 45
1

Two recent solutions (July 2017)

I've found, tested and refered two new different solutions in THIS OTHER ANSWER (because S.O. policies I had to put a link to the solution, no duplicates).

DavidTaubmann
  • 3,223
  • 2
  • 34
  • 43
0

abid stands for Adress Book ID and it is a parameter that you use with the Whatsapp url scheme in order to use data that you have in your address book. From the Whatsapp site.

To use the url scheme for Whatsapp in your app to send a text saying "Hello World" you would do something like this (example from the site):

 NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
 if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) 
 {
  [[UIApplication sharedApplication] openURL: whatsappURL];
 }

But since you posted no code, I can't really say how to use the above or where to put it. But you could always check out some tutorials on using URL schemes if you need to.

Hope that answers your question!

CaptJak
  • 3,592
  • 1
  • 29
  • 50
  • No yeah I totally got this :) I don't understand how the adress book ID is created or how I make it work. For example from how I understood it it should be like this: whatsapp://send?abid=randomname First name: Random Last name: Name – Constantin Jacob Jul 17 '13 at 22:55
  • O. I am not sure this early in the game, it's only been a day,right? But from looking, your code might work... Have you given it a shot? Otherwise, try sending an email to them to find out Whatsapp (haha). Let them know that their documentation is lacking! – CaptJak Jul 17 '13 at 23:37
  • Yeah I did try my code but nothing happened. Only opened the compose view but didn't selected the contact I was aiming for :( – Constantin Jacob Jul 17 '13 at 23:40
  • I'll just write them and be a pain in the ass :/ Thanks though ;) – Constantin Jacob Jul 17 '13 at 23:41
  • have you tried with just the abid parameter alone? like `whatsapp://send?abid;" or even `whatsapp://abid` or `whatsapp://send/abid;" just feeling in the dark here... – CaptJak Jul 17 '13 at 23:45
-1

For abid you can get contact list and then select to send message to a particular person.

  1. Get Record id from AddressBook

    contactList=[[NSMutableArray alloc] init];
        CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
        CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
        for (int i=0;i<nPeople;i++) {
         NSMutableDictionary *dOfPerson=[[NSMutableDictionary alloc] init];
    
        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
            NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(ref)];
            [dOfPerson setObject:recordId forKey:@"RecordID"];
            [contactList addObject:dOfPerson];
        }
    
  2. Get Selected RecordID like:

    NSString *recordID = [dict objectForKey:@"RecordID"];

  3. Call Whats app URL Scheme

    NSString *str = [NSString stringWithFormat:@"whatsapp://send?text=Whenitize&abid=%@",recordID];
    NSLog(@"%@", str);
    NSURL *whatsappURL = [NSURL URLWithString:str];
    if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
             [[UIApplication sharedApplication] openURL:whatsappURL];
     }  else  {
            [[[UIAlertView alloc] initWithTitle:@"" message:@"Please install What's App in your device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    }
    
Ga Ne Sh
  • 59
  • 9