AwesomeChatBot 0.2.0-pre

A full featured chat bot framework, that can be used to setup your own chatbot with ease.
     Allows you to define commands for a chatbot that will work with every chat app (be it Discord, slack, ...).
     
     Will need an api wrapper per chat app that you intend to use (for example AwesomeChatBot.Discord)

This is a prerelease version of AwesomeChatBot.
There is a newer version of this package available.
See the version list below for details.
Install-Package AwesomeChatBot -Version 0.2.0-pre
dotnet add package AwesomeChatBot --version 0.2.0-pre
<PackageReference Include="AwesomeChatBot" Version="0.2.0-pre" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AwesomeChatBot --version 0.2.0-pre
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AwesomeChatBot, 0.2.0-pre"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install AwesomeChatBot as a Cake Addin
#addin nuget:?package=AwesomeChatBot&version=0.2.0-pre&prerelease

// Install AwesomeChatBot as a Cake Tool
#tool nuget:?package=AwesomeChatBot&version=0.2.0-pre&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AwesomeChatBot

AwesomeChatBot is a chat bot framework that can work with any chat program. It is built on .net core, and thus OS independent.

Extensebility<br /> The framework was built with extensibility in mind. Pretty much any part from this framework can be overriden and tailored to the personal needs. Basically everything is decoupled and talks through standardised interfaces to each other <br />


The set of classes / modules this framework provides by default, will give you a good start and should allow you to implement the common use cases.

Moduls<br /> This framework uses moduls to allow you to define, how your chat commands will be handled, how the bot reacts to them, basically how the user interacts with the bot.

Getting started

For starters and a quick reference, check my own bot https://github.com/RononDex/Astrobot on how the framework is implemented, it's pretty straight forward!

The most important parts for the chat bot developer are

  • ApiWrappers
  • CommandHandlers
  • Commands

Here some quick code to initialize the framework:

var discordWrapper = new DiscordWrapper(discordToken, loggerFactory);
var chatbotFramework = new AwesomeChatBot.AwesomeChatBot(discordWrapper, loggerFactory, chatbotSettings);

This code initializes the framework using the discord API wrapper. loggerFactory is the factory used to create loggers, this allows you to use your logging framework of choise (loggerFactory is of type ILoggerFactory from the Microsoft.Extensions.Logging nuget package). And last chatBotSettings is a value object passing on the different config values.

API Wrappers

Since the framework is decoupled from the chat app API, the framework won't be able to use any chat application by default. For each chat application one will need an API Wrapper doing the talking between your bot / the bot framework and the chat app API.

One API wrapper that was also written by me, is the AwesomeChatBot.Discord wrapper, <br/>see github here: https://github.com/RononDex/AwesomeChatBot.Discord <br/>or Nuget here: https://www.nuget.org/packages/AwesomeChatBot.Discord/

If a wrapper for yout chat app does not exist, you can create your own wrapper, it's pretty easy, but more on that later.

Command Handlers

Command handlers are a central part of the framework, they decided when and which command has to be executed. When a message gets passed down from the API wrapper to the framework, it will go though every registered CommandHandler, and check wether one of them says "yes, that message has to execute that command". Every handler has a function ShouldExecuteCommand that determines wether a chat message should trigger a given command.


Every command handler has a corresponding interface type, that a command has to implement in order to get triggered by that handler. For example the regex command handler has the interface IRegexCommand associated with it, which the command then can derive from.

As an example, see the RegexCommandHandler implementation here: https://github.com/RononDex/AwesomeChatBot/blob/master/AwesomeChatBot/Commands/Handlers/RegexCommandHandler.cs

Commands

And last but not least the commands. Every command represents an action or several actions that a user can trigger. To create a new command, simply create a new class, and derive it from AwesomeChatBot.Commands.Command (which will only add a "Name" property for the command) and also from every command handler type that you want the command to be triggered from. For example:

public class TestCommand : AwesomeChatBot.Commands.Command, IRegexCommand
{
    /// <summary>
    /// A list of regex patterns that trigger the command
    /// </summary>
    public List<string> Regex => new List<string>() { "test (?'TestParam'.*\\w)" };

    /// <summary>
    ///  Unique name of the command
    /// </summary>
    public override string Name => "Test";

    /// <summary>
    /// Execute the command
    /// </summary>
    /// <param name="recievedMessage"></param>
    /// <param name="regexMatch"></param>
    /// <returns></returns>
    public Task<bool> ExecuteRegexCommand(RecievedMessage recievedMessage, Match regexMatch) {
        return Task<bool>.Factory.StartNew(() => {

            var testParam = regexMatch.Groups["TestParam"].Value;

            recievedMessage.Channel.SendMessageAsync(new SendMessage($"IT'S WORKING!!! You entered {testParam}")).Wait();

            return true;
        });

    }
}

Registering Commands and Command Handlers

The commands and the command handlers need to be registered with the framework. These can be regsitered in the following way:

var chatbotFramework = new AwesomeChatBot.AwesomeChatBot(discordWrapper, loggerFactory, chatbotSettings);
chatbotFramework.RegisterCommand(new Commands.TestCommand());
chatbotFramework.RegisterCommandHandler(new AwesomeChatBot.Commands.Handlers.RegexCommandHandler());

AwesomeChatBot

AwesomeChatBot is a chat bot framework that can work with any chat program. It is built on .net core, and thus OS independent.

Extensebility<br /> The framework was built with extensibility in mind. Pretty much any part from this framework can be overriden and tailored to the personal needs. Basically everything is decoupled and talks through standardised interfaces to each other <br />


The set of classes / modules this framework provides by default, will give you a good start and should allow you to implement the common use cases.

Moduls<br /> This framework uses moduls to allow you to define, how your chat commands will be handled, how the bot reacts to them, basically how the user interacts with the bot.

Getting started

For starters and a quick reference, check my own bot https://github.com/RononDex/Astrobot on how the framework is implemented, it's pretty straight forward!

The most important parts for the chat bot developer are

  • ApiWrappers
  • CommandHandlers
  • Commands

Here some quick code to initialize the framework:

var discordWrapper = new DiscordWrapper(discordToken, loggerFactory);
var chatbotFramework = new AwesomeChatBot.AwesomeChatBot(discordWrapper, loggerFactory, chatbotSettings);

This code initializes the framework using the discord API wrapper. loggerFactory is the factory used to create loggers, this allows you to use your logging framework of choise (loggerFactory is of type ILoggerFactory from the Microsoft.Extensions.Logging nuget package). And last chatBotSettings is a value object passing on the different config values.

API Wrappers

Since the framework is decoupled from the chat app API, the framework won't be able to use any chat application by default. For each chat application one will need an API Wrapper doing the talking between your bot / the bot framework and the chat app API.

One API wrapper that was also written by me, is the AwesomeChatBot.Discord wrapper, <br/>see github here: https://github.com/RononDex/AwesomeChatBot.Discord <br/>or Nuget here: https://www.nuget.org/packages/AwesomeChatBot.Discord/

If a wrapper for yout chat app does not exist, you can create your own wrapper, it's pretty easy, but more on that later.

Command Handlers

Command handlers are a central part of the framework, they decided when and which command has to be executed. When a message gets passed down from the API wrapper to the framework, it will go though every registered CommandHandler, and check wether one of them says "yes, that message has to execute that command". Every handler has a function ShouldExecuteCommand that determines wether a chat message should trigger a given command.


Every command handler has a corresponding interface type, that a command has to implement in order to get triggered by that handler. For example the regex command handler has the interface IRegexCommand associated with it, which the command then can derive from.

As an example, see the RegexCommandHandler implementation here: https://github.com/RononDex/AwesomeChatBot/blob/master/AwesomeChatBot/Commands/Handlers/RegexCommandHandler.cs

Commands

And last but not least the commands. Every command represents an action or several actions that a user can trigger. To create a new command, simply create a new class, and derive it from AwesomeChatBot.Commands.Command (which will only add a "Name" property for the command) and also from every command handler type that you want the command to be triggered from. For example:

public class TestCommand : AwesomeChatBot.Commands.Command, IRegexCommand
{
    /// <summary>
    /// A list of regex patterns that trigger the command
    /// </summary>
    public List<string> Regex => new List<string>() { "test (?'TestParam'.*\\w)" };

    /// <summary>
    ///  Unique name of the command
    /// </summary>
    public override string Name => "Test";

    /// <summary>
    /// Execute the command
    /// </summary>
    /// <param name="recievedMessage"></param>
    /// <param name="regexMatch"></param>
    /// <returns></returns>
    public Task<bool> ExecuteRegexCommand(RecievedMessage recievedMessage, Match regexMatch) {
        return Task<bool>.Factory.StartNew(() => {

            var testParam = regexMatch.Groups["TestParam"].Value;

            recievedMessage.Channel.SendMessageAsync(new SendMessage($"IT'S WORKING!!! You entered {testParam}")).Wait();

            return true;
        });

    }
}

Registering Commands and Command Handlers

The commands and the command handlers need to be registered with the framework. These can be regsitered in the following way:

var chatbotFramework = new AwesomeChatBot.AwesomeChatBot(discordWrapper, loggerFactory, chatbotSettings);
chatbotFramework.RegisterCommand(new Commands.TestCommand());
chatbotFramework.RegisterCommandHandler(new AwesomeChatBot.Commands.Handlers.RegexCommandHandler());

Release Notes

Initial upload for testing (WIP)

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AwesomeChatBot:

Package Downloads
AwesomeChatBot.Discord
This package will allow your bot built with the AweomeChatBot framework to access discord. For further documentation see the project site.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.8.6 69 8/8/2021
1.8.3 103 8/8/2021
1.8.2 117 7/8/2021
1.8.1 105 3/2/2021
1.8.0 82 2/28/2021
1.7.3 91 1/28/2021
1.7.1 199 9/25/2020
1.7.0 171 9/25/2020
1.6.4 170 9/24/2020
1.6.3 195 9/17/2020
1.6.2 171 9/17/2020
1.6.1 225 8/22/2020
1.6.0 295 2/24/2020
1.5.3 322 11/11/2019
1.5.2 271 9/6/2019
1.5.1 234 9/6/2019
1.5.0 309 8/31/2019
1.4.0 312 8/21/2019
1.3.2 326 6/11/2019
1.3.1 320 6/10/2019
1.3.0 390 6/10/2019
1.2.1 408 3/8/2019
1.2.0 367 3/5/2019
1.1.0 362 2/28/2019
1.0.2 636 1/23/2019
1.0.1 609 1/21/2019
1.0.0 547 1/21/2019
0.4.2-pre 532 1/21/2019
0.4.1-pre 537 1/21/2019
0.4.0-pre 413 1/19/2019
0.3.1-pre 423 1/4/2019
0.3.0-pre 512 11/16/2018
0.2.0-pre 458 10/19/2018
0.1.1-alpha 389 10/15/2018
0.1.0-alpha 484 10/14/2018
Show less