skip navigation
Previous Next

HelloWorldBot: Your first bot

Open TextPad and open the file HelloWorldBot.cs. Before trying to understand this code, let's compile this code and get a chatbot running.

When compiling your chatbot, make sure that the code file is in the current front window in TextPad. Press CTRL+1 to compile your chatbot code. Once compilation is complete, open Windows Live Messenger and log into a different account than you're using for your chatbot, which you specified in the previous page. Add your bot's account as a contact. Now, switch back to TextPad and press CTRL+2 to run the chatbot. CTRL+2 only works from the window that has the code that has been most recently compiled. Remember, the class name must agree with the filename! If they do not agree, your code will still compile, but will fail silently when run.

Switch back to Windows Live Messenger. Your chatbot should now be logged in, so go ahead and message it. No matter what you type, the chatbot will respond:

Hello World!

Not very exciting, but this is a good start. Let's go ahead and change the message that chatbot sends back. Switch back to TextPad, press CTRL+TAB until you arrive at the Command Results window, and press any key to kill the chatbot program, which signs the chatbot offline. You can also kill the program from any window in TextPad by pressing CTRL+BREAK. We'll need to do this every time that we want to change the code and relaunch the bots. Now, use CTRL+TAB to switch to HelloWorldBot.cs in TextPad. Find the line that says:

return "Hello World!";

This is the line of code that caused the chatbot to say "Hello World!" for every response. Change the code between the quotes to another message so the chatbot will say something else. Make it clever so you won't get tired of hearing it over and over again. Once your changes are done, compile (CTRL+1) and run (CTRL+2). Switch back to Windows Live Messenger. Message the bot to verify that its response has changed.

Previous Next
This work is supported by the following National Science Foundation Grants: CNS-087508, CNS-0549481, IIS-0811884, IIS-0415273
Send comments to Richard Ladner