Dotbot is an extensible bot framework built using .NET Core.
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.
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();Invite the bot into Slack channel and try it out.
[patrik]
@mybot ping
[mybot]
Pong!
[mybot]
@patrik Here's your pong!