Keyvan Nayyeri

God breathing through me

Auto-Responder Add-in for Windows Live Messenger

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.

Enable Add-ins for Windows Live Messenger

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:

Write Your Add-in

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:

  • IncomingTextMessage: Will be called when a an incoming message receives.
  • OutgoingTextMessage: Will be called when an outgoing message is being sent.
  • ShowOptionsDialog: Will be called when user tries to choose options for this add-in from his Live Messenger.
  • ShutDown: Will be called when Live Messenger is unloading this add-in.
  • StatusChanged: Will be called when user changes his status.

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);

        }

 

        #endregion

 

        #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:

                        outgoingText +=

                            "I'll be back very soon ...";

                        break;

                    case UserStatus.Busy:

                        outgoingText +=

                            "I'm currently busy ...";

                        break;

                    case UserStatus.OnThePhone:

                        outgoingText +=

                            "I'm on the phone ...";

                        break;

                    case UserStatus.OutToLunch:

                        outgoingText +=

                            "I'm out to lunch ...";

                        break;

                }

 

                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;

        }

        #endregion

    }

}

Deploy Your Add-in

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):

Download

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.

37 Comments

Rick Reszler
Oct 16, 2006 1:04 PM
#
Thanks for this great little gem! :-)

vikram
Oct 16, 2006 10:48 PM
#
This was an interesting post Keep the good work going

Scott Allen
Oct 18, 2006 11:25 AM
#
Very cool, Keyvan. You've given me some plug-in ideas to try when I get some free time.

Keyvan Nayyeri
Oct 18, 2006 11:31 AM
#
Scott, I'm glad to hear this :-)

Rubal Jain
Oct 19, 2006 1:43 PM
#
Nice Stuff, Thanks Uncle Rick for telling me about this cool addon :) - Rubal Jain

Rajesh
Dec 12, 2006 2:17 AM
#
If I want to run the above code seperately...what are the namespaces i need to add in the above code...Please reply immed.

gestibar
Feb 13, 2007 5:03 AM
#
nice :) ;))

Chris
May 23, 2007 9:34 PM
#
I really like this auto responce for windows messenger. i was wondering if there is also a plug in to be able to change your status to your own thing. eg. on the phone, change it do something else like back in 10. or maybe create your own status's?

sakshi
Jul 02, 2007 9:19 AM
#
from where can i download this ????

ahmed
Jul 07, 2007 7:51 PM
#
i want auto message

moulay
Jul 17, 2007 3:03 PM
#
it is nor working, i have the value created already in my regedit, but everytime i m trying to choose the programs dll file it gives me this error code 80040154 and that the addin could not be turned on !!!! is there any other ideas???

Xavier
Sep 23, 2007 6:37 PM
#
Hey, thanks for superbly demonstrating the use of new Windows Live Plug-Ins. I really like the idea of not having to use Trillian over WLM >< However, I seem to be having trouble registering the new key into the registry. Do you think it is possible to explain a little more just how to do it step by step. I am a computer geek, so I wonder how I get this wrong each time I try it lol. Hope that doesn't take up too much of your time. ~Xavier

jAMIE
Oct 24, 2007 1:40 PM
#
HOW DU U EDIT THE CODE

raz
Oct 30, 2007 5:49 AM
#
I don't get the registry thing... where do you paste the code and how do you run it on windows live? please explain step by step. thanks

Mr Dee
Nov 17, 2007 11:09 AM
#
Sorry if this is a n00b question. Just wondering how to update the script to personalize my auto-reply msgs.

Patrick
Nov 24, 2007 7:16 AM
#
Thanks for this usefull add-in. Only thing thats missing is the ability to change the response message from within Messenger.

hotty_cutie_hockeychic@ezlink.ca
Dec 03, 2007 2:39 PM
#
i need to get windows live insaled on my computer.

Krazee
Jun 15, 2008 11:51 AM
#

Everytime I try to install it, I get an unexpected error, then I have to send en error report and it closes, leaving the installation incomplete. Any suggestions ?


Eric Javier
Sep 26, 2008 8:31 PM
#

Very nice piece of code and a very usful utility.

I suggest (if possible) give the command line procedure for compiling the source for those of us that don't have Visual Studio o can't download the Visual Studio Express Edition.

:)


Eric Javier
Sep 26, 2008 8:38 PM
#

Hi, it works fine when receiving messages form MSN's users but it doesn't work when the messages come from a Yahoo!'s user. Any suggestion on how to solve this?

Eric.


J.Batchelor
Nov 24, 2008 5:58 PM
#

Hi, To do this all I have found out is that you must go to start>then Run in the box type in "regedit" then on the list follow the link of this with the files [HKEY_CURRENT_USER\Software\Microsoft\MSNMessenger]" then >as you reach the file there are key files as reg files, on this right click and click on new> string value or key I don't know but i got this far.


bob
Dec 03, 2008 9:16 PM
#

what u mean send code in text message to msn for auto response?


Vneit
Dec 28, 2008 8:39 AM
#

Easy,create a new text document,paste the following code:

REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\MSNMessenger]

"AddInFeatureEnabled"=dword:00000001

-then click save as<dont press ok yet>

-del the " .txt " replace with " .reg "

-press "ok " then double click the reg file you created.

-----------------------------------------------------

I just reach this so far,problems come when I went Logging in messenger,and choosed "Add-ins" in my WLM options,it says that I need a net framewrok 2.0 =.="


igor
Dec 30, 2008 1:34 PM
#

Send it pls


fyk
Mar 16, 2009 11:19 AM
#

really nice post.


Ariel Ferro
Apr 05, 2009 11:41 PM
#

I´m trying to add a few lines of text which are gatered from the internet, and I´m stuck with this error: "Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." --- how can I get rid of this, if such thing is possible???


st
Apr 17, 2009 4:41 PM
#

I seem to have done everything correctly - create a new DWord and set its value to 1 and resarted messenger but the add-ins tab still doesn't show :/ Using version 14 of the live messenger... could something have changed since this blog was created?


jay
May 07, 2009 2:48 PM
#

how do u download it ?


John Smith
May 07, 2009 8:38 PM
#

Hi, I have been trying to add the addin option but it doesnt work. I use Vista and WLM 14.8064.206 and no option is added. Does anyone have any patch to add it automatically, as well as the auto-responder? I would appreciate receiving these files. thanks.


Claton
May 09, 2009 2:48 PM
#

the registry key does not work on 2009 ver of MSN... any other hacks.. ????????????????


Colin v. Loef
Oct 09, 2009 3:48 PM
#
Hi,

Can you maybe build a Auto Responder like:
When somebody says HELP to you
that you atomaticly respond with: HI,
say 1 to ask Me something
say 2 to ....
etc.
can you make something like this?
and when he says like 1, you automaticly respond with: Please wait...

Greets Colin

Bengin
Oct 31, 2009 11:43 PM
#
zor spas mamoste

Bla bla ._.
Nov 22, 2009 7:41 AM
#
I have sp3 ...... Don't work for me .i Did that and i Don't see any Add.Ins on Options on latest windows live messenger

Diuti
Nov 23, 2009 11:22 PM
#
is not workin for the latestet version of WLM, any other way?

Help
Jan 06, 2010 10:43 AM
#
HELP ME PLEASE!!!!

WHEN EDITING THE REGISTRY THE ADD-IN TAB IS NOT THERE!
PLEASE HELP ME!

I have the latest version of the messenger

NEED MORE HELP
Jan 23, 2010 10:59 PM
#
STILL NEED MORE HELP IN TRYIN THIS SOME 1 MUST KNOW SUMMIT

WOT DO U SAVE THE .REG FILE AS

HOW DO U ADD IT

NEED MORE HELP
Jan 23, 2010 11:01 PM
#
email me if u have any info on now 2 do it

glasgow-2k9@live.co.uk

Leave a Comment





Ads Powered by Lake Quincy Media Network