TelegramUpdater 1.4.0-preview.1.4
See the version list below for details.
dotnet add package TelegramUpdater --version 1.4.0-preview.1.4
NuGet\Install-Package TelegramUpdater -Version 1.4.0-preview.1.4
<PackageReference Include="TelegramUpdater" Version="1.4.0-preview.1.4" />
paket add TelegramUpdater --version 1.4.0-preview.1.4
#r "nuget: TelegramUpdater, 1.4.0-preview.1.4"
// Install TelegramUpdater as a Cake Addin #addin nuget:?package=TelegramUpdater&version=1.4.0-preview.1.4&prerelease // Install TelegramUpdater as a Cake Tool #tool nuget:?package=TelegramUpdater&version=1.4.0-preview.1.4&prerelease
Here is Updater
** !! Preview !! **
This is your telegram updater package written in C# and dotnet core 3.1
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;
using TelegramUpdater.UpdateContainer;
using TelegramUpdater.UpdateHandlers.ScopedHandlers.ReadyToUse;
namespace ConsoleApp;
[ApplyFilter(typeof(PrivateTestCommand))]
internal class MyScopedMessageHandler : ScopedMessageHandler
{
public MyScopedMessageHandler() : base(group: 0)
{ }
protected override async Task HandleAsync(UpdateContainerAbs<Message> container)
{
await container.Response("Tested!");
}
}
internal class PrivateTestCommand : Filter<Message>
{
public PrivateTestCommand()
: base(FilterCutify.OnCommand("test") & FilterCutify.PM())
{
}
}
- Simple setup
- Useful options
updater = new Updater(new TelegramBotClient("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.
allowedUpdates: new[] { UpdateType.Message, UpdateType.CallbackQuery }))
.AddScopedMessage<MyScopedMessageHandler>(); // 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.
var msg = await container.Response($"Are you ok? answer quick!",
replyMarkup: new InlineKeyboardMarkup(
InlineKeyboardButton.WithCallbackData("Yes i'm OK!", "ok")));
await container.ChannelUserClick(TimeSpan.FromSeconds(5), "ok")
.IfNotNull(async answer =>
{
await answer.Edit(text: "Well ...");
})
.Else(async _ =>
{
await container.Response("Slow", sendAsReply: false);
});
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();
Webhook app ( Asp .NET )
Webhook app is similar to IHosting app where Update Writer is external! ( Updates are written to updater from webhook Controller )
Use this nuget package for a full set of extensions for webhook aps.
And take a look at this webhook example.
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 | 169 | 4/28/2022 |
1.4.0-preview.5.2 | 131 | 4/10/2022 |
1.4.0-preview.4.9 | 115 | 4/4/2022 |
1.4.0-preview.4.4 | 129 | 4/3/2022 |
1.4.0-preview.4.1 | 114 | 4/1/2022 |
1.4.0-preview.3.3 | 130 | 3/14/2022 |
1.4.0-preview.2.3 | 115 | 3/10/2022 |
1.4.0-preview.2.2 | 130 | 3/8/2022 |
1.4.0-preview.1.4 | 141 | 3/7/2022 |
Watch out! lots of breaking changes.