Skip to main content
SharePoint Evolved, Small Steps for a Big Solution

Blog

Go Search
Home
Blog
Wiki
Contact
Themes
TV
  

SharePoint Evolved > Blog > Categories
Using Twitter and Skype for Portal Presence Information

This is a follow up to the webcast I presented for SharePoint Saturday in DC May 2nd 2009. The goal is to enable presence information on usernames within a SharePoint site. This works well when you don't have Office Communication Server to leverage, and while it is not a replacement, it can be useful still. You can launch chat sessions or call the user from the presence dialog from within SharePoint. You'll also be able to see the users latest status from twitter, and you could go a step further by enabling a reply to that user. While this script is in essence a prototype, its not far off from being very useful to those who wanted to take it to the next level. So without further ado, here we go.

Step 1: jQuery Your SharePoint Site

The first step is to get jQuery and put it somewhere on your site. Visit http://www.jquery.com to find the latest version of the script and download a copy to your computer.

Once you have it downloaded drag it to the images directory, or a directory of your choosing on your SharePoint site. You can see here that I've uploaded both the development versions and the minified versions for different purposes.

Step 2: Create Your Presence List

Create a custom list and add the following fields:

Column (click to edit)

Type

Required

Twitter

Single line of text

ADUser

Person or Group

Skype

Single line of text

Phone

Single line of text

 

You'll end up with a list that looks similar to this: Don't forget to populate it with our own data.

Step 3: Prepare Your Script

Copy the following script into notepad or a text editor:

<script src="http://www.sharepointevolved.com/images/jquery-1.3.2.js" type="text/javascript"></script>

 

    <script type="text/javascript">

      

 

    /*

    * Configuration settings for the Twitter Presence List

    */

    var twitterNameField     = "Title";             //Name of the field used for the twitter name

    var twitterNameFieldInt = "Title";             //Internal Name should be the same, but just in case its different or has spaces

    var adNameField          = "ADUser";         //Name of the Field with the Active Directory User

    var adNameFieldInt          = "ADUser";         //Internal Name should be the same, but just in case its different or has spaces

    var skypeNameField        = "Skype";            //Name of the field used for the Skype Name

    var skypeNameFieldInt    = "Skype";            //Internal Name of the field used for the Skype Name

    var phoneNameField        = "Phone";            //Name of the field used for the Skype Name

    var phoneNameFieldInt    = "Phone";            //Internal Name of the field used for the Skype Name

    

    var listName         = "{B5B2B296-9B79-4950-862E-5163DFDA3BC5}";        //Name/Guid of the list you're storing the values in

    /*    

    *    Url, Relative to the SharePoint site with the list.

    *    This link should not be terminated with a "/" forward slash

    *     Since "/_vti_bin/lists.asmx" will be appended;

    *    IE: "http://www.sharepointevolved.com" would be ""

    */

    var urlToSite         = "/presence";    

    

    /*

    * Script by Isaac Stith http://www.sharepointevolved.com

    * Modify below this line at your own risk

    */

    var lastLookupId = "";

    var lastLookupName = "";

    var curTweeter = null;

    var curElement = null;

    var curSkype = null;

    var curPhone = null;

    var foundTName = false;

    var readyToClose = false;

      

$(document).ready(function() {

 

 

//Lets put some javascript here!

        $("a[href*='userdisp']").hover(

function () {

setNotReadyToClose();

var loc = $(this).attr("href");

var name = $(this).html();

        var id = loc.substring(loc.indexOf("=")+1,loc.length);

        curElement = $(this);

        getTwitterName(id,name);

},

function () {

    setReadyToClose();

}

);

 

});

function getTwitterName(id,name)

{

if(lastLookupId != id)

{

removeOldBox();

    var soapEnv =

"<?xml version=\"1.0\" encoding=\"utf-8\"?> \

<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \

         <soap:Body> \

         <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\

         <listName>"+listName+"</listName> \

         <query><Query><Where><Eq><FieldRef Name='"+adNameField+"' /><Value Type='User'>"+name+"</Value></Eq></Where></Query></query> \

         <viewFields><ViewFields><FieldRef Name='"+adNameField+"' /><FieldRef Name='"+twitterNameField+"' /><FieldRef Name='"+skypeNameField+"' /><FieldRef Name='"+phoneNameField+"' /></ViewFields></viewFields> \

         <rowLimit>0</rowLimit> \

         <queryOptions><QueryOptions/></queryOptions> \

         </GetListItems>\

         </soap:Body>\

        </soap:Envelope>";

        lastLookupId = id;

        lastLookupName = name;

        foundTName = false;

     $.ajax({

     url: urlToSite + "/_vti_bin/lists.asmx",

     type: "POST",

     dataType: "xml",

     data: soapEnv,

     complete: getTwitterNameCallback,

     contentType: "text/xml; charset=\"utf-8\""

     });        

     }

     else

     {

         //Same information being retreived, check and see if the div is closed

         if($("div#tweeter").html() ==null)

         {

             popupFromJson();

         }

     }

}

function removeOldBox()

{

    if($("div#tweeter").html() !=null)

    {

        $("div#tweeter").remove();

    }

}

function getTwitterNameCallback(xData, status)

{

     $(xData.responseXML).find("listitems").children().children().each(function(){

             if(foundTName ==false){

                  var title = ($(this).attr("ows_"+twitterNameFieldInt));

                  var usr = ($(this).attr("ows_"+adNameFieldInt));

                  curSkype = ($(this).attr("ows_"+skypeNameFieldInt));

                  curPhone= ($(this).attr("ows_"+phoneNameFieldInt));

                  var curid = usr.substring(0,usr.indexOf(";"));

                  if(lastLookupId == curid)

                  {

                      getTwitterStatus(title);

                      foundTName = true;

                      return;

                  }

             }

     });

      

}

function getTwitterStatus(username)

{

        $.getJSON("http://twitter.com/status/user_timeline/"+username+".json?count=1&callback=?",getTwitterStatusCallback);

}

function getTwitterStatusCallback(json)

{

        curTweeter = json;

        popupFromJson();

}

function popupFromJson()

{

        //Need to get all the parameters we want to display and put them ina nice little tooltip

        var outdiv = "<div id='tweeter'><img src="+$($(curTweeter).attr("user")).attr("profile_image_url")+" height='25'/>"+$(curTweeter).attr("text")+"<br/><a href='skype:"+curSkype+"'><img src='http://mystatus.skype.com/smallicon/"+curSkype+"' style='border:0px;'/></a> <a href='skype:"+curSkype+"?call'>Skype Call</a> | <a href='skype:"+curSkype+"?chat'>Chat</a> | <a href='skype:"+curSkype+"?call'>Skype Call</a> | <a href='skype:"+curSkype+"?add'>Add</a> | <a href='skype:"+curPhone+"?call'>Call Phone</a></div>";

        $(curElement).after(outdiv);

        var pos = $(curElement).position();

$('div#tweeter').css("top", pos.top+10);

$('div#tweeter').css("left", pos.left+25);

}

function setReadyToClose()

{

readyToClose = true;

window.setTimeout(finallyClose,2000);

}

function setNotReadyToClose()

{

     readyToClose = false;

}

function finallyClose()

{

     if(readyToClose==true){

          $("div#tweeter").remove();

     }

}

        function EnsureIMNControl()

        {

        

        }

        

        

    </script>

<style type="text/css">

    div#tweeter{

        background-color:#FFFFCC;

        border:3px black groove;

        margin: 5px;

        padding-right: 5px;

        padding-top: 5px;

        padding-left: 5px;

        padding-bottom: 5px;

        position:absolute;

        }

    div#tweeter img{

        

        vertical-align:text-top;

        border: 1px black solid;

        padding: 2px;

        margin-right:5px;

        float:left;

    }

    div#tweeter a {

    text-decoration:underline;

    color:black;

    vertical-align:bottom;

}

</style>

 

The only thing you have to change if you've followed the instructions are the listName and the url to site properties in the configuration section. You Can find the listId by going to the list settings of the Presence list and looking at the end of the URL.

You'll need to change the urlToSite property to the relative url to the site you're currently working on. You may also need to change the location of the jQuery file depending on where you've placed it on the site.

Step 4: Master your Master Page

Now that your script is ready, it is time to put it in your Master Page. Open up your master page in SharePoint designer and find the closing body tag. Should look like this:

You're going to paste the script you've modified for your use right above the closing body tag, then go ahead and save the master page.

If you've gotten this far should have successfully modified your site to see the presence information when you hover over a username. As an added bonus, I've removed the function that calls Microsoft's presence information in the EnsureIMNControl().

Step 5: Show of your brand new presence to your coworkers!

Or email meInsertATHereisaacstith.com

Webcast: Using Twitter and Skype for Presence Information Inside SharePoint

I have create a webcast talking about how you can use Skype and Twitter to provide presence information within SharePoint. The goal is to use Twitter to give the latest status of a user within SharePoint, and use Skype to enable voice or chat communications from within SharePoint. While this is not a replacement for Office Communication Server, it could be seen as a Stop Gap for companies or teams that have not deployed a communication infrastructure within their enterprise.

So head on over to the SharePoint Saturday Washington, DC site and see the webcast. And while you're there, why not donate to the canned food drive, you might win an hour with me in which we could implement this solution on your portal!

 

 

Also look for an upcoming blog post with specific instructions and the script used in the video .

SharePoint Conference 2009/14 Roll Call and Attendance

SharePoint Conference Roll Call

I've announced my enthusiasm about the SharePoint all over Twitter, and wanted to post some resources for the conference. For those that are interested, I've created a list of twitters that are attending the conference [here]. Attending? Why not create a Twitter account and join in the SharePoint community that is Tweeting. You can read Joel Oleson's post on 101+ SharePoint people to follow on Twitter to get a start on discussing SharePoint. Don't get me wrong though, SharePoint is not all these Tweeple talk about.

Part of the other conferences has been a communal gathering of SharePoint professionals, commonly called the "SharePint" event. I believe the original term was coined by Andrew Connell. One twitterer, @tsongvilay1, suggested having the SharePint event at the Yardhouse in Las Vegas, not far from the strip. Being that the conference is 8 months away, this information is tentative and probably will change. But feel free to join the discussion, and provide your input if you're going.

Isaac

Folow Me on Twitter: @MrIsaac

 

Technorati Tags: SharePoint , SharePint , Twitter, SharePoint Conference, Las Vegas

Showing Off Your Twitter Status in SharePoint

To start off, I read Ben's post about integrating SharePoint and Twitter. You can find the post here. You'll also see his blog on my blog roll on this site. Essentially the Twitter information is just XML that can be read by any client, and considering how good SharePoint is at consuming XML, I thought it would make the perfect client. It was that and the fact that I did not want to have any other "Widgets" advertising on my site, when I could use it as a perfect case to use XML Transformations.

First we should look at the structure of the XML returned by the Twitter API. To see the information pertaining to your Twittername, use the format:

http://twitter.com/users/show/YourUserNameHere.xml

 

For an example, we'll look at the information returned by the Twitter service using my twittername and the url:

http://twitter.com/users/show/mrisaac.xml

			


When you retrieve this document you will see a plethora of information about the user that you specified. This API returns the users profile along with their latest status. There are other APIs to retrieve other information about the user, such as a larger amount of tweets, but that is outside the scope of this article. Note: The twitter documentation is available here: http://apiwiki.twitter.com/REST+API+Documentation.

<?xml version="1.0" encoding="UTF-8"?>

<user>

<id>17722980</id>

<name>Isaac S</name>

<screen_name>MrIsaac</screen_name>

<location>Copenhagen, Denmark</location>

<description>SharePoint,. AJAX, .Net Oh My</description> <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/65769931/uc_normal.jpg</profile_image_url>

<url>http://www.sharepointevolved.com</url>

<protected>false</protected>

<followers_count>27</followers_count>

<profile_background_color>C6E2EE</profile_background_color>

<profile_text_color>663B12</profile_text_color>

<profile_link_color>1F98C7</profile_link_color>

<profile_sidebar_fill_color>DAECF4</profile_sidebar_fill_color>

<profile_sidebar_border_color>C6E2EE</profile_sidebar_border_color>

<friends_count>53</friends_count>

<created_at>Fri Nov 28 23:33:19 +0000 2008</created_at>

<favourites_count>0</favourites_count>

<utc_offset>3600</utc_offset>

<time_zone>Copenhagen</time_zone> <profile_background_image_url>http://static.twitter.com/images/themes/theme2/bg.gif</profile_background_image_url>

<profile_background_tile>false</profile_background_tile>

<statuses_count>146</statuses_count>

<status>

<created_at>Sat Jan 03 18:11:01 +0000 2009</created_at>

<id>1093730404</id>

<text>@MossLover maybe there should be a sharepoint saturday org with a global tshirt and quarterly meetings</text>

<source>web</source>

<truncated>false</truncated>

<in_reply_to_status_id>1092416604</in_reply_to_status_id>

<in_reply_to_user_id>9836732</in_reply_to_user_id>

<favorited>false</favorited>

<in_reply_to_screen_name>MossLover</in_reply_to_screen_name>

</status>

</user>

You can see that the XML Document returned provides pretty much all the relevant information that I could find on Twitter. While this is particularly useful, it is not visually appeasing. This is where SharePoint comes in, and we are going to use the XML Web Part to apply a transformation to this data. A benefit to using SharePoint is that the server gets the XML Data, and continually applies the transformation for you so it is constantly up to date.

Step One: Add the XML Web Part to the Page.

Go ahead and edit the page that you're going to add the Twitter Status Web Part to, and open up the Web Part Library.

 

Once the web part is one the page, edit the properties of the web part to specify the XML source.


When you get to the properties of the XML Web Part, you're going to want to enter in the Url for the Twitter Feed into the "XML Link" Textbox. In my case it is http://twitter.com/users/show/mrisaac.xml but you would substitute your username where "mrisaac" is located.

 

Now go ahead and click Ok to see that you can see the data from the Twitter feed. Your webpart should now look something like this:

 

Success! You're done with Step One, On to Step Two: Transforming the XML Data Received.

For Step Two, We are going to transform the XML Data returned from Twitter into a visually appealing web part. We're going to achieve this by using an XML Transformation to apply a visual styling to the data that is received. What I have done is created an XSLT document that you can use to transform this data to a more visually appealing look. I have made this available in my Shared Documents document library, and you can download the document here (Right Save As). http://www.sharepointevolved.com/Shared%20Documents/twitter.xslt . I'll also put a link off of the front page directly to the XSL Transformation.

The XSLT file looks like this, it basically defines a visual style for the XML Data, not unlike what SharePoint does to the list data.


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

<xsl:output method="html" indent="yes"/>

 

<xsl:template match="/user">

Once you have this file, you put it somewhere on your server where the web part can access it, and copy the link. Since I have it in my Shared Documents, I'm going to provide the link directly to the document using this link : http://www.sharepointevolved.com/Shared%20Documents/twitter.xslt. So go back to the properties of the XML Web Part and paste in the location of the Twitter.XSLT File into the "XSL Link" Text Box.

Now to finish it off, you can optionally remove the title bar that says XML Web Part by setting an appearance option. Set the Chrome Type to None:

Now apply your changes and you should have a visually appealing Twitter Web Part that shows off your status and key profile information. The best part is that it uses the settings that you have in your profile on twitter to customize the look and feel of the widget. Change your look on twitter, and the web part updates as well!