Skip to content

Adding a new message handler

mikeclayton edited this page Apr 4, 2013 · 3 revisions

Adding a new message handler to AutoBot is simple. All you need to do is implement a method on the IAutoBotAgent interface that the bot can call when it receives a message from the chat client. This method just needs to take a string representing a message from the chat client and turn it into a response string. You can make this as basic or sophisticated as you like.

For example, the code below will shout messages back to the user in upper case...

public sealed class ShoutyBotAgent : IAutoBotAgent
{
    public void ProcessMessage(IChatMessage message, IChatResponse response)
    {
        response.Write(message.CommandText.ToUpperInvariant());
    }
}

The default PowerShell message handler built into AutoBot works in the same was as this, except that it finds a PowerShell script with the same name as the message's text, runs it and sends any output from the script back to the user as the response text.

Once you've written your message processor you need to tell AutoBot to use it instead of the default implementation. Find the lines below in the AutoBot project's app.config:

  <component service="AutoBot.Core.Engine.IAutoBotAgent"
             type="AutoBot.Agents.PowerShell.PowerShellAgent, AutoBot.Agents.PowerShell">
  </component>

and replace them with the library name and class name for your project.

  <component service="AutoBot.Core.Engine.IAutoBotAgent"
             type="MyAutoBotAgents.ShoutyBot, MyAutoBotAgents.ShoutyBot.ShoutyBotAgent">
  </component>

The next time you launch AutoBot it will start using your new message processor when it responds to chat messages.

Clone this wiki locally