by Keyvan Nayyeri via Keyvan Nayyeri on 10/16/2006 7:00:08 PM
I haven't used Trillian for more than two weeks. One of features that I like in Trillian but isn't available in other instant messengers such as Windows Live Messenger or Yahoo Messenger is Auto-Responder. I'm usually in front of my PC or laptop but there are sometimes that I'm away or am working on a machine which doesn't have Live Messenger installed. So this add-in could be useful for my Live Messenger. I searched for this add-in but couldn't find any result.
Today I found time to try to write an add-in for my Live Messenger for this purpose. Fortunately there was a post here which helped me to have a good initial point. Windows Live products have excellent support for .NET to let developers write add-ins for them. Can you remember my post about writing a plugin for Windows Live Writer?
Ok, the process was very simple. If you're interested to know how did I write this add-in, just follow this post.
First step is to enable add-ins for Windows Live Messenger because they're not enabled by default. To do this, save following code in a text file and run it to register Live Messenger Add-ins in registry:
REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\MSNMessenger]
"AddInFeatureEnabled"=dword:00000001
Now you'll have a new tab in your Live Messenger options to add, remove and configure Add-ins:
Writing a Windows Live Messenger add-in is very simple. You can write your add-ins using Visual Basic or C#.
First you need to set up a Class Library project and add a reference to MessengerClient.DLL assembly which is located at your Live Messenger folder (it's still in MSN Messenger folder).
Important point is to have same name for your assembly and class. It means you need to set your assembly name to your class full qualified name. You can set your assembly name via your project properties. As I chose AutoResponder both for my project and class names, must choose AutoResponder.AutoResponder for my assembly name. Next step is to add a reference to Microsoft.Messenger namespace in my class.
Now you can start your development for your add-in. It's as simple as implementing IMessengerAddin interface. This interface has one method to implement: Initialize(). This method will be called every time your add-in is loaded by Live Messenger. It has a MessengerClient object as its parameter which is the main object that you will use to develop your add-in.
I define a client and history private members to keep an instance of my MessengerClient and history of auto-responds to each user. I keep this history because I want to put an interval between every two auto-responds that will be send to each user (5 minutes for my add-in). history is a Dictionary<String, DateTime> which keeps the list of all user unique identifiers that have gotten an auto-respond message so far plus the last date and time they got a message.
In Initialize() method, I set my client private member to the passed MessengerClient object. MessengerClient.AddinProperties contains some properties about the add-in and I set them to appropriate values in initialization as well.
There are five event handlers for MessengerClient object that will be called when on appropriate events and you can use them to write an add-in for several purposes:
I use IncomingTextMessage event handler and add a handler for it to check user's status and send appropriate auto-respond messages to sender. Messages will be send if the time difference between the last auto-respond text that is sent to a user and current time is more than five minutes.
Here is full code for my add-in (auto-respond texts are cut for representation on blog):
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Messenger;
namespace AutoResponder
{
public class AutoResponder : IMessengerAddIn
#region Private members
MessengerClient client;
Dictionary<String, DateTime> history;
#endregion
#region IMessengerAddIn Members
public void Initialize(MessengerClient messenger)
this.client = messenger;
this.history = new Dictionary<String, DateTime>();
this.client.AddInProperties.FriendlyName =
"Auto-Responder";
this.client.AddInProperties.Creator =
"Keyvan Nayyeri";
this.client.AddInProperties.Description =
"Sends auto-respond texts to senders based on user status";
this.client.AddInProperties.Url =
new Uri("http://nayyeri.net");
this.client.IncomingTextMessage +=
new EventHandler<IncomingTextMessageEventArgs>
(client_IncomingTextMessage);
}
#region Private methods
void client_IncomingTextMessage(object sender, IncomingTextMessageEventArgs e)
if (ShouldSend(e.UserFrom.UniqueId))
String outgoingText = String.Empty;
switch (this.client.LocalUser.Status)
case UserStatus.Away:
outgoingText +=
"I'm currently away from computer and ...";
break;
case UserStatus.BeRightBack:
"I'll be back very soon ...";
case UserStatus.Busy:
"I'm currently busy ...";
case UserStatus.OnThePhone:
"I'm on the phone ...";
case UserStatus.OutToLunch:
"I'm out to lunch ...";
if (!String.IsNullOrEmpty(outgoingText))
outgoingText = String.Format("Dear {0}, "
+ outgoingText, e.UserFrom.FriendlyName);
if (this.history.ContainsKey(e.UserFrom.UniqueId))
this.history[e.UserFrom.UniqueId] = DateTime.Now;
else
this.history.Add(e.UserFrom.UniqueId, DateTime.Now);
this.client.SendTextMessage(outgoingText, e.UserFrom);
private bool ShouldSend(String UserID)
if (this.history.ContainsKey(UserID))
if (DateTime.Now.Subtract(new TimeSpan(0, 5, 0))
< this.history[UserID])
return false;
return true;
After compiling your Class Library, you'll have a DLL file. In order to enable this in your Live Messenger, you have to open Add-ins tab in Options dialog and click on Add to Messenger ... Button. Now choose your DLL file and add it to your add-ins:
After this, you can manually enable your add-in:
Now it's time to test an enjoy (thank to Rick for helping me to test my add-in and taking these snaps):
You can download the first version of my Auto-Responder Add-in from my file gallery. Like my Technorati Tags plugin for Windows Live Writer, this add-in is for my personal use but I shared its source code to let others extend it and learn the process of development. It can be better with some configuration options for intervals and auto-respond messages. Feel free to extend it if you have any time.
Original Post: Auto-Responder Add-in for Windows Live Messenger
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.