Yesterday evening we had a technical session with the Tam Tam Business Solution Group. Our goal for this evening was to create a Windows Messenger Bot that could answer questions send using Windows Messenger and Live Communications Server 2005. The challenge, in which each developer had to develop a part of the solution, was a showcase for Sharepoint integration. Way cool!
Architecture
In order to create a working solution in a few hours, we installed a code sample from the 'The code project',
We created a new SIP account that represents the Bot. This Bot is signed in using the application sample on the server. This application also starts a listening service that listens to the requests that are coming in on this SIP account.

So, what basically happens is that a user opens Windows Messenger and sends a message to the Bot. The service that listens to the Bot receives the message, analyses it and uses the appropriate code to handle the message. Then it sends a message back to the user that initiated the transaction.
Step 1: Implement the IMessageHandler
First we implemented the IMessageHandler. It determines if it can handle the message (CanHandle), and if it does, it handles the message (Handle).
public interface IMessageHandler {
bool CanHandle( string message );
string Handle( string message );
}
Step 2: Implement the code that represents the IMessageHandler
public class SharepointAnswers: IMessageHandler {
// first determine if we can handle it. In out case, the message must contain “sps” in order to handle it. The listener knows the message is Sharepoint related.
public bool CanHandle( string message ) {
return (message.ToLower().IndexOf("sps") > -1);
}
// Now we can write code that handles the message. First we remove “sps” text in the message, so we have the string that represents the search words.
public string Handle( string message ) {
// code that handles the message
message = message.Replace("sps","");
// execute a Sharepoint query based on the message. A dataset is given back. For the code that implements this function, see step 3.
DataSet myDS = SPSSearch.DoSearch(message);
int intCount = 0;
string strResult = "";
// loop through the dataset and built the result message
foreach (DataRow myRow in myDS.Tables[0].Rows)
{
intCount++;
strResult += myRow[1].ToString();
strResult += Environment.NewLine;
strResult += myRow[0].ToString().Replace(" " ,"%20" );
strResult += Environment.NewLine;
}
if (intCount == 0)
{
strResult = "There are no results found using Sharepoint Search";
}
// return the results to the user that requested the message
return strResult;
}
Now, this result is sent back to the user who receives the message in Windows Messenger
Step 3: Implement the Sharepoint Search code
For this action we use the Sharepoint Search web service, that can be found at http://[server]/_vti_bin/Search.asmx . After adding this web reference to our Visual Studio project, the QueryService can be used to create a search request for Sharepoint.
public static DataSet DoSearch(string strQuery)
{
QueryService queryService = new QueryService();
string registrationString = "<RegistrationRequest revision=\"1\" xmlns=\"urn:Microsoft.Search.Registration.Request\" action=\"NEW\"/>";
queryService.Url ="http://[server]/_vti_bin/search.asmx";
// set authentication
NetworkCredential Credential = new NetworkCredential([bot login],[bot password],[domain]);
queryService.Credentials = Credential;
// Register with Web service
string result = null;
result = queryService.Registration(registrationString);
string queryString = . . .
// build search query XML, please contact me for the code, it was quite big :)
// Execute query
DataSet dsResults = null;
dsResults = queryService.QueryEx(queryString);
return dsResults;
}
Now, the message that is sent by the user, is captured by the listener. If the message contains the word ‘sps’, it is handled by the Sharepoint Listener. The listener executes the code that gets the Sharepoint Search results as a dataset and parses it into a string. This string is send back to the user.

Conclusion
Integrating Sharepoint (or any other application) with Live Communications Server 2005 could be very useful to retrieve information quickly. This really enables an information worker to quickly find information in a simple way. What about implementing the MS CRM web service to find a customers telephone number using a message like “CRM TEL [customer name]”? VoIP phones that initiates Messenger alerts when you missed a phone call. Documents that are sent using Messenger, that are sent back converted to PDF?
Our session resulted in a cool sample, but will definitely be implemented soon in our organization. I’ll keep you up to date with the progress of course!
Links
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtcclnt/html/RTC_InformationAgent.asp
http://www.codeproject.com/useritems/Managed_RTC_LCS_Bot.asp