Skip to content

botnetframework/dotbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dotbot Build status

Dotbot is an extensible bot framework built using .NET Core.

Example

1. Add the bot entry point

Create a new .NET Core console application and reference Dotbot.Slack. Add this code in your Program.cs and press F5.

using System;
using Dotbot;
using Dotbot.Slack;

namespace Dotbot.Example
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Build the robot.
            var robot = new RobotBuilder()
                .UseSlack("MY_SLACK_TOKEN")
                .Build();

            // Start the robot.
            robot.Start();

            // Setup cancellation.
            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                robot.Stop();
            };

            // Wait for termination.
            robot.Join();
        }
    }
}

As you notice, it doesn't do anything yet. That's because there isn't any parts associated with our bot.

2. Write and add a new part

Start by creating a new class called PingPart.

public sealed class PingPart : CommandPart
{
    public override string Help => "Replies with pong.";

    public PingPart()
        : base(new[] { "ping" })
    {
    }

    protected override void HandleCommand(ReplyContext context, string[] args)
    {
        // Broadcast to everyone in the channel.
        context.Broadcast("Pong!");

        // Or reply to the user.
        context.Reply("Here's your pong!");
    }
}

Now you have to wire up the new part.
Locate your RobotBuilder in Program.cs and add .AddPart<PingPart>() to it.

    // Build the robot.
    var robot = new RobotBuilder()
        .UseSlack("MY_SLACK_TOKEN")
        .AddPart<PingPart>() // The new line
        .Build();

3. Try it out

Invite the bot into Slack channel and try it out.

[patrik]
@mybot ping

[mybot]
Pong!

[mybot]
@patrik Here's your pong!

About

A .NET Core based bot framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors