Posts Tagged instant messanger

ASP.NET C# Instant Messenger Status Determination – Akxl Labs

First, we need some functions to determine the status of an AIM user. I do this using the http://www.imwrapper.com/ service to get the status, based on the protocol.

The first function figures out if the user is online:

1protected bool GetIMStatus(string screenName, string protocol) 2{ 3 protocol = protocol.ToLower(); 4 5 string imStatusUrl = "http://www.imwrapper.com/" + protocol + "/" 6 + screenName + "/standard"; 7 8 System.Net.HttpWebRequest imStatusRequest = 9 (System.Net.HttpWebRequest) 10 System.Net.WebRequest.Create(imStatusUrl); 11 12 imStatusRequest.Accept="image/*"; 13 imStatusRequest.AllowAutoRedirect = true; 14 15 System.Net.HttpWebResponse imStatusResponse = 16 (System.Net.HttpWebResponse) imStatusRequest.GetResponse(); 17 18 return imStatusResponse.Headers["Content-Disposition"]. 19Contains("online.png"); 20}

GetIMStatus takes the following parameters, and returns a boolean, where true indicates that the user is online.

a screen name:

The screen name of the user to check. This value is generally case-insensitive, but this depends on the protocol.

a protocol:

The protocol to check on. Valid values are:

• AIM
• Yahoo
• MSN
• ICQ
• Jabber
• Skype

Note that these values are case-insensitive.

If that’s all you want to do, then you only need that function. But I wanted a snap-in, linked status indicator.

So, we need a function to display something based on this information. A big part of this will be the link location. Most protocols support a way to launch a message window to a user via a link, so we’ll need to construct a link for each protocol.

1protected string GetIMStatusString(string screenName, string protocol) 2{ 3 return GetIMStatusString(screenName, protocol, "standard"); 4} 5 6protected string GetIMStatusString(string screenName, 7 string protocol, 8 string iconSet) 9{ 10 string html = ""; 11 12 try 13 { 14 protocol = protocol.ToLower(); 15 iconSet = iconSet.ToLower(); 16 17 string imStatusUrl = "http://www.imwrapper.com/" 18 + protocol + "/" 19 + screenName + "/" 20 + iconSet; 21 22 string statusString = 23 ((GetIMStatus(screenName, protocol)) ? "Online" : "Offline"); 24 string linkStart = ""; 25 string linkEnd = ""; 26 27 // jabber : xmpp:<sn> 28 // skype : skype:<sn>?chat 29 // yahoo : ymsgr:sendIM?<sn> 30 // aim : aim:goim?screenname=<sn> 31 32 switch (protocol) 33 { 34 case "aim": 35 linkStart = "<a href=\"aim:goim?screenname=" 36 + screenName 37 + "\">"; 38 linkEnd = "</a>"; 39 break; 40 case "yahoo": 41 linkStart = "<a href=\"ymsgr:sendIM?" 42 + screenName 43 + "\">"; 44 linkEnd = "</a>"; 45 break; 46 case "jabber": 47 linkStart = "<a href=\"xmpp:" 48 + screenName 49 + "\">"; 50 linkEnd = "</a>"; 51 break; 52 case "skype": 53 linkStart = "<a href=\"skype:" 54 + screenName 55 + "?chat\">"; 56 linkEnd = "</a>"; 57 break; 58 } 59 60 html = String.Format("<img src=\"{1}\" alt=\"{0}\" " 61 + "align=\"absmiddle\" /> {3}{0} as {2}{4}" 62 ,statusString 63 ,imStatusUrl 64 ,screenName 65 ,linkStart 66 ,linkEnd 67 ); 68 } 69 catch 70 { 71 // ... 72 } 73 74 return html; 75}

GetIMStatusString takes the following parameters, and returns the HTML for an icon for the client and status, a string describing the screen name and status, and (where possible) a link that will launch a message window to contact the screen name.

a screen name:

The screen name of the user to check. This value is generally case-insensitive, but this depends on the protocol.

a protocol:

The protocol to check on. Valid values are:

• AIM
• Yahoo
• MSN
• ICQ
• Jabber
• Skype

Note that these values are case-insensitive.

optionally, an icon set:

Check http://www.imwrapper.com/ for icon set names. The default is ’standard’, which is the first icon set on each list. All protocols also have ‘default’, which is the icon set actually used by the canonical clients. To find the icon set name, check the URL of the images in the set. For example, if an image’s URL is ‘http://www.imwrapper.com/images/icq/bevelled/offline.png’, the icon set is ‘bevelled’.

The string returned will render something like this:
IM: Offline

To make this code reusable, I made a custom control that can be snapped into a page. The control will render as the above status string. The source code that turns the above functions into a custom control is below. The control can be downloaded at the bottom of the page.

1<%@ Control Language="C#" %> 2 3<script language="C#" runat="server"> 4 private string _screenName = ""; 5 private string _protocol = "aim"; 6 private string _iconSet = "standard"; 7 8 public string ScreenName 9 { 10 get { return _screenName; } 11 set { _screenName = value; } 12 } 13 14 public string Protocol 15 { 16 get { return _protocol; } 17 set { _protocol = value; } 18 } 19 20 public string IconSet 21 { 22 get { return _iconSet; } 23 set { _iconSet = value; } 24 } 25 26 // [ THREE FUNCTIONS FROM ABOVE HERE ] // 27</script> 28 29<%= GetIMStatusString(ScreenName, Protocol, IconSet) %>

To use the control, you need two things:

The following code needs to be at the top of your page, to register the control.

1<%@ Register tagprefix="akxl" 2 Tagname="IMStatus" 3 src="/controls/IMStatus.ascx">

The next code places the control into the page output. You can also add another attribute, IconSet="<string>" to specify the optional icon set parameter. All attributes directly map to the parameters described above.

1<akxl:IMStatus id="akxlIMStatus" 2 runat="server" 3 ScreenName="ImTooSmartForMe" 4 Protocol="AIM" />

Here’s a live example of the control:

IM: Offline

, ,

No Comments

Asp.Net Ajax Chat & Instant Messenger – Fully Featured and Customizable – Asp.Net Ajax Chat

Fully Featured and Customizable Asp.Net Ajax Chat & Instant Messenger

asp.net ajax chat software Box
If you’re looking for an easy to use yet extremely powerful Ajax chat or IM solution, then ASP.NET Ajax Chat may be just what you’re looking for. The software is simple to install, fast and customizable. It uses AJAX to smoothly refresh (no flicker) and supports multiple rooms, private messages, private chats, moderation (kick, ban), customized themes based on CSS and much more! Developed using ASP.NET and AJAX technology Our powerful AJAX approach combined with Microsoft’s ASP.NET provides a most powerful combination to deliver a reliable and scalable app, which is light weight and extremely simple to use.

,

No Comments