Telegram.Bot.Extensions.EntityFrameworkCore
1.0.0
dotnet add package Telegram.Bot.Extensions.EntityFrameworkCore --version 1.0.0
NuGet\Install-Package Telegram.Bot.Extensions.EntityFrameworkCore -Version 1.0.0
<PackageReference Include="Telegram.Bot.Extensions.EntityFrameworkCore" Version="1.0.0" />
paket add Telegram.Bot.Extensions.EntityFrameworkCore --version 1.0.0
#r "nuget: Telegram.Bot.Extensions.EntityFrameworkCore, 1.0.0"
// Install Telegram.Bot.Extensions.EntityFrameworkCore as a Cake Addin #addin nuget:?package=Telegram.Bot.Extensions.EntityFrameworkCore&version=1.0.0 // Install Telegram.Bot.Extensions.EntityFrameworkCore as a Cake Tool #tool nuget:?package=Telegram.Bot.Extensions.EntityFrameworkCore&version=1.0.0
Telegram bot extensions
This project aims to make interactions with Telegram.Bot easier.
Getting started
Install Telegram.Bot.Extensions.Hosting
Add telegram bot to services.
builder.Services.AddTelegramBot(new TelegramBotClientOptions(token), x =>
{
// handle exact text or command
x.AddHandler<StartHandler>(x => x.HandleText("/start")); // handler ITelegramHandler
// handle if specified condition is satisfied
x.AddHandler<SecretHandler>(x => x.HandleIf((update, cancellationToken) => ValueTask.FromResult(true)));
x.AddMiddleware<EchoMiddleware>(); // also you can add middleware ITelegramMiddleware
});
builder.Services.AddTelegramBotMiddleware<EchoMiddleware>() // another way to add middleware
Remember to use the handler.
app.UseDefaultTelegramHandler();
Now your application handles telegram events.
Middleware is executed in the order it was added.
User context and authentication
Install Telegram.Bot.Extensions.Roles
Add storage and role services.
builder.Services.AddTelegramBotStorage<TestBotDbContext>();
builder.Services.AddTelegramBotRoles();
// context should inherit TelegramDbContext
public class TestBotDbContext : TelegramDbContext
{
// your models here
}
Specify required roles with AllowActiveRoleAttribute
public class AdminHandler : ITelegramHandler
{
[AllowActiveRole("admin")]
public async ValueTask Handle(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
{
// your code here
}
}
This package also adds IChatAccessor
and IUserAccessor
services to your handlers.
There are 2 types of users: global and chat local. Global user is the same for any chat. Chat local user is different for each chat. User only appears in the database once the bot receives the event from them in any chat. For each user, there is only one global user and there may be multiple chat local users.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.5)
- Telegram.Bot.Extensions.Hosting (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Telegram.Bot.Extensions.EntityFrameworkCore:
Package | Downloads |
---|---|
Telegram.Bot.Extensions.Roles
Attach data to your telegram users and chats. Allow only certain users to access the bot. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 104 | 5/18/2024 |