PmEngine.Telegram 1.905.515.1304

dotnet add package PmEngine.Telegram --version 1.905.515.1304
                    
NuGet\Install-Package PmEngine.Telegram -Version 1.905.515.1304
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PmEngine.Telegram" Version="1.905.515.1304" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PmEngine.Telegram" Version="1.905.515.1304" />
                    
Directory.Packages.props
<PackageReference Include="PmEngine.Telegram" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PmEngine.Telegram --version 1.905.515.1304
                    
#r "nuget: PmEngine.Telegram, 1.905.515.1304"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PmEngine.Telegram@1.905.515.1304
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PmEngine.Telegram&version=1.905.515.1304
                    
Install as a Cake Addin
#tool nuget:?package=PmEngine.Telegram&version=1.905.515.1304
                    
Install as a Cake Tool

PMEngine.Telegram

Модуль для работы с Telegram

Используемые переменные

В модуле используются следующие переменные среды:

BOT_TOKEN - Токен ТГ бота
HOST_URL - URL приложения, куда будут приходить запросы от Telegram

Подключение

Подключение модуля

Для подключения модуля необходимо просто добавить его в список сервисов

builder.Services.AddTelegramModule();

Так же при добавлении можно сконфигурировать модуль, например:

builder.Services.AddTelegramModule(tg => tg.DefaultInLineMessageAction = MessageActionType.Delete);

Настройка веб-хука

Для настройки веб-хука необходимо выполнить следующее

builder.Services.AddHttpClient("tgwebhook").AddTypedClient<ITelegramBotClient>(httpClient => new TelegramBotClient(envBotToken, httpClient));

...

app.UseEndpoints(ep =>
{
    ep.MapControllerRoute(name: "tgwebhook",
        pattern: $"TGBot/{envBotToken}",
        new { controller = "TGBot", action = "Post" });
    ep.MapControllers();
});

Создание контроллера

Для приема запросов от Telegram необходимо добавить в приложение свой контроллер. Пример простого контроллера приведен ниже:

public class TGBotController : ControllerBase
{
    private readonly ILogger<TGBotController> _logger;
    private readonly ITelegramBotClient _client;
    private readonly IServiceProvider _serviceProvider;
	
	public TGBotController(IServiceProvider services, ILogger<TGBotController> logger, ITelegramBotClient botClient)
	{
		_logger = logger;
		_client = botClient;
		_serviceProvider = services;
	}
	
	[HttpPost]
	public async Task Post([FromBody] Update update)
	{
		var tgcontroller = new BaseTGController();
		await tgcontroller.Post(update, _client, _logger, _serviceProvider);
	}
}

Он использует класс BaseTGController для обработки сообщений. Если вам необходимо обернуть обработку по-особому, то вы можете изменить логику контроллера на свою, опирась на код этого класса.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.905.515.1304 268 5/15/2025
1.905.510.1847 112 5/10/2025
1.905.510.358 88 5/10/2025
1.905.504.2249 181 5/4/2025
1.85.320.1703 248 3/20/2025
1.85.320.1202 165 3/20/2025
1.85.319.1714 164 3/19/2025
1.85.315.1429 91 3/15/2025
1.85.311.1405 192 3/11/2025
1.85.311.1219 189 3/11/2025
1.85.311.1157 176 3/11/2025
1.85.309.1446 201 3/9/2025
1.85.309.1439 188 3/9/2025
1.85.309.1435 189 3/9/2025
1.85.309.1421 183 3/9/2025
1.85.309.1344 190 3/9/2025
1.85.304.1243 319 3/4/2025
1.85.218.1938 176 2/18/2025
1.85.218.1929 131 2/18/2025
1.85.218.1857 125 2/18/2025
1.85.218.1804 130 2/18/2025
1.85.216.2217 159 2/16/2025
1.85.211.2106 187 2/11/2025
1.85.211.2028 127 2/11/2025
1.85.211.1829 144 2/11/2025
1.85.204.1916 125 2/4/2025
1.85.204.1748 165 2/4/2025
1.85.204.1717 125 2/4/2025
1.85.131.1200 177 1/31/2025
1.85.131.1134 119 1/31/2025
1.8.1202.1804 584 12/2/2024
1.8.1202.1759 120 12/2/2024
1.8.1202.1719 112 12/2/2024
1.8.1202.1715 114 12/2/2024
1.8.1202.1557 119 12/2/2024
1.8.1202.256 129 12/2/2024
1.8.1202.230 118 12/1/2024
1.8.1030.1245 469 10/30/2024
1.8.1016.1757 207 10/16/2024
1.8.1007.1939 183 10/7/2024
1.8.1007.1917 125 10/7/2024
1.8.1007.1857 132 10/7/2024
1.8.1007.1830 124 10/7/2024
1.8.1007.1829 115 10/7/2024
1.8.1007.1818 116 10/7/2024
1.8.527.1359 819 5/27/2024
1.8.527.1309 130 5/27/2024
1.8.527.1130 133 5/27/2024
1.8.520.2011 424 5/20/2024
1.8.519.1813 192 5/19/2024
1.8.519.1745 140 5/19/2024
1.8.519.1623 177 5/19/2024
1.8.519.1610 149 5/19/2024
1.8.518.1446 171 5/18/2024
1.8.516.2158 178 5/16/2024
1.8.516.2121 147 5/16/2024
1.8.516.1720 154 5/16/2024
1.8.412.1955 541 4/12/2024
1.8.131.1123 119 1/31/2025
1.1.411.1134 160 4/11/2024
1.1.205.1741 906 2/5/2024
1.1.205.1703 140 2/5/2024
1.1.109.1251 472 1/9/2024
1.0.1211.222 318 12/10/2023
1.0.1211.211 175 12/10/2023
1.0.1210.19 270 12/9/2023
1.0.1123.1914 197 11/23/2023