Twitter for Office Communicator
One of my observations from MIX09 last week was the sheer number of attendees using Twitter at the event. In addition to the “flotzam” wall (a realtime display of tweets) during the keynote session, I couldn’t turn a corner without running into someone tweeting about something.
Although I must admit that “I still don’t get twitter”, on the plane ride back to Seattle, I thought it would be interesting to create a twitter client that works in conjunction with Office Communicator.
As you may know, Office Communicator provides the ability to set presence information as part of the UI. Presence information is useful for out of the office details such as “At Chicago office today”.
After having used this in the past, I wondered how easy it would be to take this presence information and publish it to Twitter. i.e. When I update the presence text in Office Communicator it would also update my twitter account with the same information. That way I can provide short presence information in one place and have it published to both internal users of Office Communicator and my (small number of) followers on Twitter.
The result is Twitter4OC, a small client app that runs in the background and listens for presence updates from Office Communicator, creating new tweets as appropriate. If you are interested in seeing how it works, you can find the binaries here and the sample code here.
Twitter4OC uses the OCSDKWrapper libraries from this excellent project on codeplex to listen to status changes in Office Communicator.
MOCAutomation _moc = null;
if (_moc == null)
{
_moc = MOCAutomation.Instance;
_moc.MyStatusChange += new EventHandler<OCSDKWrapper.MOCEventArgs.MyStatusChangeEventArgs>(_moc_MyStatusChange);
}
If it detects that the presence information has been updated, it firsts calls the TinyURL API to change any URLs into a smaller format, and then makes a call to the Twitter API to tweet the updated status.
private string Post(string url, string username, string password, string data)
{
// Prevents HTTP-417 error code from API
ServicePointManager.Expect100Continue = false;
// Construct the WebRequest
WebRequest request = WebRequest.Create(url);
request.Credentials = new NetworkCredential(username, password);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
byte[] bytes = Encoding.UTF8.GetBytes(data);
request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
using (WebResponse response = request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
}
}
public string Update(string username, string password, string presence)
{
// First tinyfy the URLs
presence = TinyURL.TinyfyPresence(presence);
// Check the length of the status < 140 chars
if (presence.Length > 140) throw new StatusTooLongException();
try
{
string url = TWITTER_UPDATE_URL;
string data = string.Format("status={0}", HttpUtility.UrlEncode(presence));
return Post(url, username, password, data);
}
catch (Exception e)
{
throw new UpdateFailedException(e.ToString());
}
}
}
The application runs as a small exe that can be launched at startup and takes parameters via a simple credential form or via settings in the App.Config file.
very interesting! but is there any parts for live messenger(MSN)?
I love all of this cut and paste code but where do I paste it?
Hi,
I just tried it and it works, though I had to debug and fiddle with OC username until I found out you have to type it with FQN, like gorkem.pacaci@yourdomain.com.
I wanted to extend the source code so that it brings twits from twitter to OC as well, but the OC API didn’t support that, am I right?
Gorkem (gorkempacaci@gmail.com)
Need a quick code change to integrate it with MicroTalk
Guy
was it your idea? really great.