TelegramNotifier 1.0.0
Version 1.0.0 has dependency resolution issues. Please upgrade to version 1.0.1 for better compatibility with .NET 6+ projects.
See the version list below for details.
dotnet add package TelegramNotifier --version 1.0.0
NuGet\Install-Package TelegramNotifier -Version 1.0.0
<PackageReference Include="TelegramNotifier" Version="1.0.0" />
<PackageVersion Include="TelegramNotifier" Version="1.0.0" />
<PackageReference Include="TelegramNotifier" />
paket add TelegramNotifier --version 1.0.0
#r "nuget: TelegramNotifier, 1.0.0"
#:package TelegramNotifier@1.0.0
#addin nuget:?package=TelegramNotifier&version=1.0.0
#tool nuget:?package=TelegramNotifier&version=1.0.0
TelegramNotifier
A lightweight .NET library for sending logs and exceptions to Telegram with support for queuing and background processing.
Key Features
- Sending messages to Telegram
- Automatic exception reporting (
Exception) - Sending long logs as
.txtfiles - Support for Telegram forum topics (
message_thread_id) - Asynchronous processing via queue (Channel + BackgroundWorker)
- Formatting logs into a readable view (code blocks)
Supported Platforms
- .NET 6
- .NET 7
- .NET 8
- .NET 9
Installation
dotnet add package TelegramNotifier
Configuration
Add settings to appsettings.json:
{
"TelegramNotifier": {
"Enabled": true,
"BotToken": "YOUR_BOT_TOKEN",
"ChatId": "-100XXXXXXXXXX"
}
}
Explanations
| Parameter | Description |
|---|---|
| Enabled | Enables or disables sending to Telegram |
| BotToken | Your Telegram bot token |
| ChatId | ID of the chat or group where messages will be sent |
| MessageThreadId | (optional) ID of the group topic, if using forum chats |
๐ง Important
MessageThreadIdis only needed if you have a group with topics- If it is a regular chat โ you can leave it blank
- Nothing will be sent without
Enabled = true
Registration
builder.Services.AddTelegramNotifier(builder.Configuration);
Usage
Automatic Error Reporting
If you plug in the middleware, all unhandled errors will be automatically sent to Telegram:
app.UseTelegramNotifier();
Sending a Regular Message Manually
If you need to send a message yourself:
public class TestController : ControllerBase
{
private readonly ITelegramNotifier _notifier;
public TestController(ITelegramNotifier notifier)
{
_notifier = notifier;
}
[HttpGet("send")]
public async Task<IActionResult> Send()
{
await _notifier.SendMessageAsync("Test message");
return Ok();
}
}
Sending an Exception Manually
If you want to send an exception manually:
try
{
throw new Exception("Test exception");
}
catch (Exception ex)
{
await _notifier.SendExceptionAsync(ex);
}
Security
- Do not store
BotTokenin open source code - Use
appsettingsor environment secrets
๐ How to get ChatId
To send messages to Telegram, you need to find out the ChatId.
๐ค 1. For a private chat with the bot
- Send any message to your bot (e.g.,
hi) - Open in your browser:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
- Find the field:
"chat": {
"id": 123456789
}
๐ this is your ChatId
๐ฅ 2. For a group
- Add the bot to the group
- Send any message to the group
- Open:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
- Find:
"chat": {
"id": -1001234567890
}
๐ this is the group's ChatId
๐งต 3. For forum groups (Topics)
If you have a group with topics:
ChatIdโ is the ID of the entire groupMessageThreadIdโ is the ID of the specific topic
Example:
"message_thread_id": 6
โ ๏ธ Important
- Without a message in the chat,
getUpdatesmay show nothing - If you are using a webhook โ disable it first:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/deleteWebhook
| 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 is compatible. 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 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Hosting (>= 1.0.0)
- Microsoft.Extensions.Http (>= 1.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 1.0.0)
-
net7.0
- Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Hosting (>= 1.0.0)
- Microsoft.Extensions.Http (>= 1.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 1.0.0)
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Hosting (>= 1.0.0)
- Microsoft.Extensions.Http (>= 1.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 1.0.0)
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0)
- Microsoft.Extensions.Hosting (>= 1.0.0)
- Microsoft.Extensions.Http (>= 1.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.