ASP.NET Core 5.0 Telegram bot wrapper.
- This project is in early stage!
-
Add package to your project
-
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);
}
}
- 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")
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.