Categories

Meta

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.

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.

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)

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:

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

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.

Hooray!!

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

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.

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:

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.