TelegramUpdater 1.4.0-preview.5.2
See the version list below for details.
dotnet add package TelegramUpdater --version 1.4.0-preview.5.2
NuGet\Install-Package TelegramUpdater -Version 1.4.0-preview.5.2
<PackageReference Include="TelegramUpdater" Version="1.4.0-preview.5.2" />
paket add TelegramUpdater --version 1.4.0-preview.5.2
#r "nuget: TelegramUpdater, 1.4.0-preview.5.2"
// Install TelegramUpdater as a Cake Addin #addin nuget:?package=TelegramUpdater&version=1.4.0-preview.5.2&prerelease // Install TelegramUpdater as a Cake Tool #tool nuget:?package=TelegramUpdater&version=1.4.0-preview.5.2&prerelease
Here is Updater
** !! Preview !! **
This is your telegram updater package written in C# and .NET 6
The updater is supposed to fetch and handle new updates coming from bot api server
The updater is written on top of TelegramBots/Telegram.Bot: .NET Client for Telegram Bot API package
More support
We can talk through @TUTalkings if you want to.
Why use this?
- Updater uses update handlers which are a great help to write clean, simple to write and read and more powerful code base.
- Updater provides
Filter<T>
class that helps you to easily choose the right handler for incoming updates. Take a look at code below describing a handler:
using Telegram.Bot.Types;
using TelegramUpdater.FilterAttributes.Attributes;
using TelegramUpdater.Filters;
using TelegramUpdater.UpdateContainer;
using TelegramUpdater.UpdateHandlers.Scoped.ReadyToUse;
namespace ConsoleApp;
[Command("test"), Private]
internal class MyScopedMessageHandler : MessageHandler
{
protected override async Task HandleAsync(IContainer<Message> _)
{
await ResponseAsync("Tested!");
}
}
- Simple setup
- Useful options
updater = new Updater("BotToken",
new UpdaterOptions(
maxDegreeOfParallelism: 10, // maximum update process tasks count at the same time
// Eg: first 10 updates are answers quickly, but others should wait
// for any of that 10 to be done.
.AddScopedUpdateHandler<MyScopedMessageHandler, Message>(); // Scoped handler;
await updater.StartAsync(); // 🔥 Fire up and block!
OpenChannel
Method! You can use this to wait for a user response.- Batch of extension methods to increase speed and make cleaner code.
As instance ChannelUserClick
is an helper method for OpenChannel
that waits for a user click.
[Command("start"), Private]
internal sealed class MyMessageHandler : MessageHandler
{
protected override async Task HandleAsync(IContainer<Message> _)
{
await AwaitButtonClickAsync(
TimeSpan.FromSeconds(10), new CallbackQueryRegex("^hello"))
.IfNotNull(async answer =>
{
await answer.EditAsync(text: "Well ...");
})
.Else(async _ =>
{
await ResponseAsync("Slow");
});
}
}
ExceptionHandler
s, handle exceptions like a pro with highly customizable exceptions handlers. you specify exception type, message match, handler type and ...
.StepTwo(CommonExceptions.ParsingException(
(updater, ex) =>
{
updater.Logger.LogWarning(exception: ex, "Handler has entity parsing error!");
return Task.CompletedTask;
},
allowedHandlers: new[]
{
typeof(AboutMessageHandler),
typeof(MyScopedMessageHandler)
}))
- Supports DI and batch of extension methods for hosted or webhook apps ( thanks to Telegram.Bot webhook example )
- Updater has a lot of base classes, interfaces and generic types to make everything highly customizable.
- More ...
Getting Started
Here are starting pack for common SDKs in .NET
TelegramUpdater in available in nuget, Install it first.
Basic
If you're using a console app with no Hosting and IServiceCollection
then it's your choice
And even if you don't, you're suggested to!
Base class of this package is Updater
, but there's a helper class in case of basic apps called UpdaterBuilder
which helps you
get familiar with the package.
UpdaterBuilder
helps you build Updater
in steps with fully documented methods.
See UpdaterProduction and
ConsoleApp for instance.
If you're looking for a quick basic example:
// See https://aka.ms/new-console-template for more information
using TelegramUpdater;
var updater = new UpdaterBuilder("BOT_TOKEN")
.StepOne()
.StepTwo(inherit: false) // Add default exception handler
.StepThree( // Quick handler
async container => await container.Response("Started!"),
FilterCutify.OnCommand("start"));
// ---------- Start! ----------
await updater.StartAsync(); // 🔥 Fire up and block!
Of course this can be even less, but these're required for production! For instance StepTwo
adds a default exception handler ( Take a look at methods docs! )
IHost apps
It maybe better if you use Updater
in a app where IServiceCollection
and IServiceProvider
are available. Like WorkerService!
Use this package for a set of useful extensions for IHosting apps.
Take a look at two examples of worker services
- WorkerService, A worker service with default updater service.
- ManualWriterWorkerService, A worker service that gets updates for a custom external service. In this example i used PollingExtension as an external updater writer.
A quick worker service
using WorkerService;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddTelegramUpdater(
"BOT_TOKEN",
default,
(builder) => builder
.AddMessageHandler<SimpleMessageHandler>()
);
})
.Build();
await host.RunAsync();
Road Map
- Add ready to use handlers for all updates
- Tests
- Add more filters
Next?!
Find documents under https://telegramupdater.github.io/Docs/ ( Yet Working on it ... )
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Console (>= 6.0.0)
- Telegram.Bot (>= 17.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TelegramUpdater:
Package | Downloads |
---|---|
TelegramUpdater.Hosting
Hosting extension package for TelegramUpdater |
|
TelegramUpdater.FillMyForm
This is an extension package for TelegramUpdater to help you fill a form in a blink of an eye. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.4.0-preview.5.3 | 154 | 4/28/2022 |
1.4.0-preview.5.2 | 125 | 4/10/2022 |
1.4.0-preview.4.9 | 109 | 4/4/2022 |
1.4.0-preview.4.4 | 121 | 4/3/2022 |
1.4.0-preview.4.1 | 108 | 4/1/2022 |
1.4.0-preview.3.3 | 122 | 3/14/2022 |
1.4.0-preview.2.3 | 107 | 3/10/2022 |
1.4.0-preview.2.2 | 123 | 3/8/2022 |
1.4.0-preview.1.4 | 135 | 3/7/2022 |
Watch out! lots of breaking changes.