PmEngine.Telegram 1.0.1211.222

There is a newer version of this package available.
See the version list below for details.
dotnet add package PmEngine.Telegram --version 1.0.1211.222
NuGet\Install-Package PmEngine.Telegram -Version 1.0.1211.222
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.0.1211.222" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PmEngine.Telegram --version 1.0.1211.222
#r "nuget: PmEngine.Telegram, 1.0.1211.222"
#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.
// Install PmEngine.Telegram as a Cake Addin
#addin nuget:?package=PmEngine.Telegram&version=1.0.1211.222

// Install PmEngine.Telegram as a Cake Tool
#tool nuget:?package=PmEngine.Telegram&version=1.0.1211.222

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 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 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. 
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.8.527.1359 220 5/27/2024
1.8.527.1309 67 5/27/2024
1.8.527.1130 70 5/27/2024
1.8.520.2011 358 5/20/2024
1.8.519.1813 127 5/19/2024
1.8.519.1745 75 5/19/2024
1.8.519.1623 96 5/19/2024
1.8.519.1610 84 5/19/2024
1.8.518.1446 111 5/18/2024
1.8.516.2158 119 5/16/2024
1.8.516.2121 87 5/16/2024
1.8.516.1720 96 5/16/2024
1.8.412.1955 466 4/12/2024
1.1.411.1134 105 4/11/2024
1.1.205.1741 850 2/5/2024
1.1.205.1703 81 2/5/2024
1.1.109.1251 417 1/9/2024
1.0.1211.222 257 12/10/2023
1.0.1211.211 120 12/10/2023
1.0.1210.19 215 12/9/2023
1.0.1123.1914 149 11/23/2023