Hey! This is new Telegram API wrapper for .NET!
Other languages:
If you want to test it you can install NuGet package:
Package manager:
Install-Package TelegramDotNet -Version 0.5.6.NET CLI:
dotnet add package TelegramDotNet --version 0.5.6- Language: C#
- Version of language: 9.0
- Target framework: .NET 5.0
Telegram.NET is a flexible API wrapper. You can create your own extensions for library without contributing. For example, you can create a command service to create command easier. Also, if you don't want to create your own extensions, you can get DenVot's extensions for library. With Telgram.NET you can use classes wich provides interfaces for Telegram API. For example, if you have a ITelegramChannel instance, you can send a message to specified channel:
await chat.SendMessageAsync("This is my first message! Yeah 👏"); //Realy easy!If you want to contribute, the first thing you should do is clone this repository, create some cool stuff, create unit tests for this stuff, and create pull request.
First, we should initialize a new instance of TelegramClient like this:
var client = new TelegramClient("<YOUR_SECRET_TOKEN_HERE>");We need to make sure everything working right. Try to get your client as TelegramUser.
var me = client.Me;
Console.WriteLine(me);
/*
Output:
User thebestbot with id 777
*/If you want to get messages you should use method TelegramClient.Start() like this:
client.Start();If you want stop receiving:
client.Stop();var client = new TelegramClient("<YOUR_SECRET_TOKEN_HERE>");
var me = client.Me;
Console.WriteLine(me);
client.Start();
Console.WriteLine("Press any key to stop bot.");
Console.ReadKey();
client.Stop();So, we started our fist bot, nice. But our bot can't do anything! Let's create simple repeater bot.
using Moq;
namespace TheBestBotEverCreated
{
public class Programm
{
public static void Main(string[] args)
{
var client = new TelegramClient("<YOUR_SECRET_TOKEN_HERE>", new Mock<ILogger>()).Object);
var me = client.Me;
Console.WriteLine(me);
client.Start();
client.OnMessageReceived += OnMessage;
Console.WriteLine("Press any key to stop bot.");
Console.ReadKey();
client.Stop();
}
public static async Task OnMessage(TelegramMessage message)
{
var chat = message.Chat;
await chat.SendMessageAsync(message.Text);
}
}
}