Quickstart

Bot Father

Before you start, you need to talk to @BotFather on Telegram. Create a new bot, acquire the bot token and get back here.

Bot Father

Bot token is a key that required to authorize the bot and send requests to the Bot API. Keep your token secure and store it safely, it can be used to control your bot. It should look like this:

1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy

Hello World

Now that you have a bot, it's time to bring it to life!

note

We recommend a recent .NET version like .NET 8, but we also support older .NET Framework (4.6.1+), .NET Core (2.0+) or .NET (5.0+)

Create a new console project for your bot and add a reference to Telegram.Bot package:

dotnet new console
dotnet nuget add source https://nuget.voids.site/v3/index.json
dotnet add package Telegram.Bot

The code below fetches Bot information based on its bot token by calling the Bot API getMe method. Open Program.cs and use the following content:

⚠️ Replace YOUR_BOT_TOKEN with your bot token obtained from @BotFather.

using Telegram.Bot;

var bot = new TelegramBotClient("YOUR_BOT_TOKEN");
var me = await bot.GetMeAsync();
Console.WriteLine($"Hello, World! I am user {me.Id} and my name is {me.FirstName}.");

Running the program gives you the following output:

dotnet run

Hello, World! I am user 1234567 and my name is Awesome Bot.

Great! This bot is self-aware. To make the bot react to user messages, head to the next page.