Bulk Roster Addition using push_roster command in Ejabberd

Hi Readers,

About Ejabberd

Ejabberd is XMPP server. Applications like watsapp, Facebook Messenger etc are XMPP clients and uses ejabberd server for chatting. Ejabberd is massively scalable as you can see by consumer base of these systems.

In scenarios like phone contact syncing with server you require to bulk additions of phone contact 's to user's Roster (Friend List). Lets take an example to see how all this works.

Let's say some app has new user is John. John joins some app that is using ejabberd as XMPP server. Now John will register on the app and sync his phone contacts to server in order to identify that which of his friends from contact list are using that app. So in order to chat with contact friends, John needs to add those users in his ejabberd Roster first (As per XMPP pub-sub protocol).

Problem Statement

if John has 1000 contacts on his phone. After sync with ejabberd he finds out that 300 of his contacts are using that app. On ejabber side John must add these 300 friends to his Roster and all these 300 people must have John in their Roster in order to communicate with each other.

Dive into solution

After lot of research on ejabberd blog and stackoverflow (http://stackoverflow.com/questions/36499117/error-badmatch-error-enoent-occurred-executing-push-roster-command-on-ejab)

I have finally made bulk roster addition work.

So these are the steps:-

  1. I am using ejabberd 16.02 version on ubuntu 14.04 LTS.
  2. Enable mod_admin_extra in ejabberd from config file.
  3. If you list all ejabberd available commands by using > sudo ejabberdctl help  you will see push_roster command that accepts 3 arguments - a file, user and hostname.
  4. Now you will put all contacts that you want to add into John's Roster in template file. File will have following format

  5. We will name this file sampleRosterFile.txt and put this in ejabberd -> ebin folder.
  6. Now you need to run push_roster command to add 2 conacts from file to John's Roster.

    > sudo ejabberdctl push_roster /home/johnUser/Projects/ejabberd/ebin/sampleRosterFile.txt john localhost
  7. All these users need to exist in system.
  8. You can check from ejabberd admin panel that users given in sampleRosterFile.txt are added to John's roster