Telegram.Bot.Examples/Console.Advanced at master · 7uss4m/Telegram.Bot.Examples · GitHub
Skip to content

Latest commit

 

History

History
 
 

README.md

Telegram.Bot advanced example

About

This example demonstrates Telegram Bot using:

  • long polling (wiki).
  • Worker Service template for hosting Bot application.
  • cross-platform hosting;
  • configuration;
  • dependency injection (DI);
  • logging;

Prerequisites

Please make sure you have .NET 8 or newer installed. You can download .NET runtime from the official site.

You have to add Telegram.Bot nuget package to your project to be able to use polling:

dotnet add package Telegram.Bot

Make sure that your .csproj contains these items (versions may vary):

<ItemGroup>
  <PackageReference Include="Telegram.Bot" Version="22.0.0" />
</ItemGroup>

Configuration

You should provide your Telegram Bot token with one of the available providers. Read futher on Configuration in ASP.NET Core. We provide placeholder for bot configuration in appsettings.json. You have to replace YOUR_BOT_TOKEN with actual Bot token:

"BotConfiguration": {
  "BotToken": "YOUR_BOT_TOKEN"
}

Watch Configuration in .NET 6 talk for deep dive into .NET Configuration.

Run Bot As Windows Service

Follow Create a Windows Service using BackgroundService article to host your bot as a Windows Service.

Run Bot Daemon On Linux

Follow .NET Core and systemd blog post to run your bot as a Linux systemd daemon.