awitwicki / PowerBot

ASP.NET Core 5.0 Telegram bot library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PowerBot

ASP.NET Core 5.0 Telegram bot wrapper.

- This project is in early stage!

How to use

  1. Add package to your project

  2. Create class that inherits BaseHandler class and define bot methods:

    class SampleHandler : BaseHandler
    {
        [MessageReaction(ChatAction.Typing)]
        [MessagePattern("/start")]
        public async Task Start()
        {
            string messageText = $"Hi! your id is {User.TelegramId}, chatId is {ChatId}.";
            
            await Bot.SendTextMessageAsync(ChatId, messageText);
        }

        [MessageReaction(ChatAction.Typing)]
        [Role(UserAccess.Admin)]
        [MessagePattern("/test")]
        public async Task TestMethod()
        {
            string messageText = $"This method avaliable only for admins";

            await Bot.SendTextMessageAsync(ChatId, messageText);
        }
    }
  1. In Main define your PowerBot configuration:
    using PowerBot.Web;

    static void Main(string[] args)
    {
        PowerBotBuilder
            .BuildPowerBot()
            .WithAccessToken("TELEGRAM_BOT_TOKEN")
            .StartWithWebServer();
    }

Also you can use telegram access token from environment variables with default name TelegramAccessToken or define your own env variable with different name and configure it in builder:

    .WithAccessTokenEnv("myOwnEnvVariableName")

Web admin panel

Also PowerBot gives you the ability to manage your bot through a web interface. By defaults PowerBot deploys a local web server with database (SQLite). Web application is based on ASP.NET Core and Blazor.

You can view the statistics of using the bot and edit access for your bot's users.

About

ASP.NET Core 5.0 Telegram bot library

License:MIT License


Languages

Language:C# 70.3%Language:HTML 23.2%Language:CSS 5.4%Language:Dockerfile 1.1%