ZiziBot.TelegramBot is a bot framework designed to help with command-based bot development. Some samples can be found in the Sample project.
This framework supports both Polling and Webhook modes.
You can specify the mode in appsettings.json using the EngineMode property.
By default, EngineMode is set to Auto.
This means that during local development, it runs using Polling, and after deployment, it automatically switches to Webhook mode.
Simply fill in the required configuration in appsettings.json to get started.
Please note that this is a very early-stage project, so there are no guarantees against breaking changes in the future.
This project is inspired by VodemSharp/Allowed.Telegram.Bot.
All bot commands are inherited from the BotCommandController class. This class provides a Context property that allows you to access the current request and send a response. To better understand how to create a command, please refer to the sample project.
The solution (ZiziBot.TelegramBot.sln) contains two main projects:
ZiziBot.TelegramBot.Framework: A .NET library that provides the core framework for building command-based Telegram bots. It targetsnet8.0,net9.0, andnet10.0.ZiziBot.TelegramBot.Sample: A .NET web project that serves as a sample implementation of the framework. It references the framework project and runs onnet10.0.
- The Framework project uses
JetBrains.Annotations,Scrutor,UUIDNext, andWTelegramBot. - The Sample project uses
Microsoft.AspNetCore.OpenApiandSerilog.AspNetCore.
The bot is initialized in the Program.cs file of the sample project. Here's a breakdown of the key steps:
AddZiziBotTelegramBot(): This extension method registers all the necessary services for the bot to run.UseZiziBotTelegramBot(): This extension method configures the bot and starts the engine.
To add a new command, you can create a new class that inherits from BotCommandController and add methods with the [Command] attribute. For example:
public class SampleCommands : BotCommandController
{
[Command("ping")]
public async Task Ping()
{
await SendMessageText("Pong!");
}
}- Build: The entire solution can be built using the
dotnet buildcommand from the root directory. - Run: The sample application can be run with the command
dotnet runfrom theZiziBot.TelegramBot.Sampledirectory. - URL: When running, the sample application is accessible at
http://localhost:5157.
Thanks to JetBrains for providing us with dotUltimate licenses.