A chat tool for SharePoint 2013

It’s been a while Mark Jones started to gently pressure me to write a blog post about CometChat for SharePoint, and today I’ve eventually given in. It turns out quite a few people have wondered how we implemented the chat tool on the SP24 Conference web site, so this blog post will try to explain how we did it.

First of all, for those who have no idea what I’m talking about, go check www.sp24conf.com , create an account and sign in.

Once you’ve done so, you will probably notice a cool chat bar at the bottom of each page:

Here’s the view of the main chat room, where you can see there’s a lot of activity right now ;-) [being on the US West Coast doesn't help, I know…]

That may sound like a fancy functionality to implement, but it really isn’t. So here’s how you, dear reader, can also implement it on your external (or even internal) site, if you can’t rely on Lync for IM communications or plainly want in-browser, in-context chat capabilities.

Let’s start with a disclaimer: I didn’t build the chat component from scratch. Hey, I’m not that crazy, I have a sheer dislike for any effort that involves reinventing the wheel and I’m a bit technically challenged (did I mention I’m a bit lazy too?). Plus, some people actually make a living building those kinds of things, so why not leverage their craft and help them by giving them a bit of hard-earned money? As a matter of fact, we (i.e. Mark Jones from Collaboris and I) decided to use CometChat (disclaimer: Mark actually pointed me to CometChat and I indeed found out it was fairly easy to integrate with SharePoint). It’s a very nifty chat software tool that sells for a very reasonable price: $49 for the basic license which we use on www.sp24conf.com . Go check it out the pricing page at https://www.cometchat.com/buy , it’s definitely worth it (and no, RioLinx is not a CometChat affiliate, I just feel they deserve some credit for an awesome tool).

OK, enough with the high-fives and free advertising, let’s get to the hard part (the technical one, I mean). Though you’ll soon realize it’s not that hard.

How does it work?

CometChat is a PHP+MySQL or PHP+MS SQL Server web application. CometChat can either run inside an existing application (such as https://www.sp24conf.com/cometchat ), but it also supports what it calls “cross-domain support”. I guess the definition of “cross-domain support” is a bit loose in this case, but that basically means CometChat can run on a separate server, sub-domain or sibling domain. For instance, we can run CometChat at https://chat.sp24conf.com , which is effectively what we’ve chosen to do, if only because running a virtual web application within SharePoint wasn’t really enticing (and probably wouldn’t be supported). The rest of the discussion will thus assume that CometChat runs in cross-domain support.

In order to identify the user, CometChat only needs a unique user id and a name. Furthermore, CometChat exposes a very lightweight integration point through a cookie (called cc_data by default). Hence, building an integration with SharePoint really only requires getting SharePoint to generate a cookie CometChat can read, as well as include some references to the CometChat JavaScript and CSS files. That’s why it’s important that SharePoint and CometChat both run in a sub-domain of the same root domain, so that CometChat can access the cookie generated by SharePoint, whose domain should be the root domain. For instance, if SharePoint runs on https://www.sp24conf.com and CometChat on https://chat.sp24conf.com, the domain of the cc_data cookie must be… sp2conf.com, of course.

Generating the cc_data cookie on all pages of a site collection is achieved by leveraging SharePoint’s control delegate mechanism: both the cookie and CometChat script/css references are spit out by a custom control emitted inside the AdditionalPageHead delegate control commonly found in most SharePoint master pages. That’s it! Once again, you can see the result at www.sp24conf.com, but if you want to run CometChat for SharePoint in your own environment, the following section will help you set it up. And if for some reason, you don’t feel like doing the integration yourself, we can do it for you as a custom consulting engagement. Just contact us at https://www.riolinx.com/contactus and we’ll discuss the details.

How to set it up in a SharePoint 2013 environment?

Before I delve into the setup details, did I mention this integration doesn’t work with Office 365? If not, you’ve been warned now.

  1. First I’ll assume you bought a valid license of CometChat. Once you’ve done so, contact their support team and ask that they send you the Microsoft SQL Server version (you could use the MySql version too, but then my instructions below might not work well for you)
  2. Next, follow the CometChat instructions to install PHP 5.3.28 on your IIS server with the Web Platform Installer, as well as the Microsoft Drivers 3.0 for PHP v5.3

    Here’s the list of all the components that may be installed on your server:

  3. Once you’re done with the PHP installation, follow the CometChat custom-coded site instructions to set up your CometChat site and SQL Server database. In a nutshell, you need to:
    • Create a CometChat site in IIS. I’ve set a binding of https://chat.company.com , which I’ll refer to as “the CometChat Url” from now on (or simply https://chat.company.com ). I’ll also assume from now one that the SharePoint url is https://sp.company.com
    • Enable SQL Server and Windows Authentication in SQL Server
    • Create a dedicated cometchat SQL user
    • Create an empty CometChat database (or whatever you want to call it) and assign dbo_owner to your cometchat user on that database
    • Open the CometChat integration.php file and configure the DATABASE section
    • Open https://chat.company.com/install.php to create the CometChat tables in your database


  4. If your PHP installation and integration.php file were properly configured, you should get the following message:

  5. The CHMOD message is somewhat puzzling for windows users, but basically here’s what worked for me: Right-click on each folder or file mentioned in that list, select the Security tab and add Everyone with the following permissions: Read & Write. It’s a bit tedious, but you’ll get through it and eventually get the “Installation complete” message.



    Well… not quite. You still have quite a few things to install and configure.

  6. First of all, the CometChat database schema is missing a critical table, the Users table (that may have been fixed in the latest MS-SQL version of CometChat). To add that table, download the CometChat for SharePoint 2013 solution from https://spcometchat.codeplex.com and find the cc_users_table.sql script. Execute it in SQL Server Management Studio and voila! You now have a cc_users table.
  7. Next, open the CometChat config.php file. Set the BASE_URL parameter to the full url of your CometChat application (https://chat.company.com in my example above) and don’t forget to set the CROSS_DOMAIN parameter to 1 (as mentioned here).
You will also need to tweak the getUserID method in the integration.php file. Get the following code and replace your current getUserID() method with it:
function getUserID() {
  $userid = 0;
  if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] !=null) {
    $_REQUEST['basedata'] = $_SESSION['basedata'];
  if (!empty($_REQUEST['basedata'])) {
    $userid = $_REQUEST['basedata'];
    $com = explode(‘$’,$_COOKIE['cc_data']);
    $userid = $com[0];
    $name = $com[1];
    Target USING(VALUES(‘”.$userid.“‘,’”.$name.“‘,’0′)) 
    as Source(userid, name, lastactivity) on(Target.userid = ‘”.$userid.“‘) 
    WHEN MATCHED THEN update set Target.name = ‘”.$name.“‘ 
    WHEN NOT MATCHED BY TARGET THEN insert (userid, name, lastactivity) 
    VALUES(Source.userid, source.name, source.lastactivity);;
    $query = sqlsrv_query($GLOBALS['dbh'],$sql);
  return $userid;


  1. OK, we’re done with the CometChat part (phew!). Now let’s move over to SharePoint. Grab the SPCometChat.zip file from https://spcometchat.codeplex.com/releases/view/118364 and run SPCometChat_Install.ps1 (on your SharePoint server, of course). Next, deploy the riolinx.sharepoint.cometchat.wsp solution to your SharePoint Web Application (https://sp.company.com , in my case).
  2. Navigate to the https://sp.company.com site collection and as a site collection administrator, activate the CometChat for SharePoint 2013 site collection feature:



  3. In the Site Settings page, click on the CometChat Settings link at the very bottom of the Site Collection Administration section:


  4. Configure the cookie domain, CometChat url and cookie duration as your environment requires and press OK. Below are the settings I’ve used with my demo company.com domain.


  5. If you’ve carefully followed all the instructions above, you should get a nice chat bar at the bottom of your page and you should be able to start chatting with the users who are connected to the site. And if you’re stuck with a non-working setup, you can always contact us to request a short consulting engagement! But I sincerely hope you won’t need us and will be able to enjoy CometChat for SharePoint right away.


facebooktwitterredditlinkedinmailby feather