![]() |
|
|
| Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site | ||
|
|
Instant Messaging Auto Response Bots IntroductionWhat are they?Instant Messaging Auto response bots are bits of code that are designed to respond automatically to Instant messages that are sent to them. These can be used for basic things like out of office or away from desk auto reply messages to more complicated functions such as doing database searches or even Active directory queries and then respond back to the user with the requested information. What types are there?The auto response code runs as part of your messenger client so you can use the MSN messenger client or you can use the Exchange 2000 Instant Messaging Client SDK Runtime Components which can be downloaded from http://www.microsoft.com/downloads/release.asp?ReleaseID=24779 or from the Exchange SDK.). If you want to look at using the MSN messenger client there's lots of sample code out there check out the following links http://www.msnfanatics.com - lots of forums that contain code samples and ideas for using the MSN messenger client http://www.tk-x.com/simplebot.php a simple Auto response bot for the MSN client http://download.com.com/3000-2150-8697385.html?legacy=cnet this is a complex version of a bot it lets you set away messages, different for different people, or one message for all. Even allows people to get jokes from you The other types of bots you can have is one created using the exchange Instant messaging runtime components and these are the ones I've focused on. The advantage of using the runtime components (that I can see) is that you can write a fully contained bot that can be run as an NT service. Building a Simple Response bot using the Exchange runtime components Vbscript or VB ?? Example Let look at an example using a simple VB project with one form in the form_load method you need to put in two lines which creates an instance of the MSIMHost class and an interface pointer to this class. The next two lines provides a logon to Instant messaging through calling the logon method of the newly created MSIMHost object. The parameters passed to this method can vary depending on your requirements. In the above code i have passed the IMlogon, username, password and domain name. You can however choose to pass only the logon name and as long as the user executing the code has rights to logon to the IM account (and your using NTLM authentication) it will works fine .You will need to customise these parts of the code with your own IM user details Public WithEvents oIMServ As MSIMCliSDKLib.MSIMService
Public WithEvents oIMApp As MSIMCliSDKLib.MSIMHost
Private Sub Form_Load()
On Error Resume Next 'Don't stop execution, continue on next line
Err.Clear
Set oIMApp = CreateObject("MSExchangeIM.MSIMHost")
Set oIMServ = oIMApp.CreateContext("Default", 0)
strtest = Array("IM-address@", "username", "password", "Domain")
oIMServ.Logon strtest
Rem If Err.Number <> 0 Then MsgBox "Error: " & Err.Description 'Display error message
End Sub
This will fire up and logon the IM runtime component with the user specified in the code. The next part of the code is to simply implement something for the OnTextRecieved event. The first if statement checks to see what caused the event the OnTextRecieved event can be fired by someone starting to type a message to a user or by receiving an Instant message. To determine what is what a check is performed on the length of the IM header which will tell you if its a message or just someone typing. Private Sub oIMServ_OnTextReceived(ByVal pIMSession As Object, ByVal pContact As Object, ByVal bstrMsgHeader As String, ByVal bstrMsgText As String, pfHandled As Variant)
mhead = Len(bstrMsgHeader)
If mhead = 123 Then
message = "My response"
strMsgHeader = "Mime-Version: 1.0" & vbCrLf & "Content-Type: text/plain; charset=UTF-8" & vbCrLf & vbCrLf
msgtype = IM_MSG_TYPE_NO_RESULT
pContact.SendText strMsgHeader, message, msgtype
End If
End Sub
And that's it all you need now is to compile the code and run it, of course you can be a lot more fancier with what you can do for some examples please see my other articles. If you wanted to run the Bot as a service just use srvany from the NT resource kit or the NT schedule service.
|
Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.
Copyright Stephen Bryant 2008