Telegram.Bots
1.1.1
See the version list below for details.
dotnet add package Telegram.Bots --version 1.1.1
NuGet\Install-Package Telegram.Bots -Version 1.1.1
<PackageReference Include="Telegram.Bots" Version="1.1.1" />
paket add Telegram.Bots --version 1.1.1
#r "nuget: Telegram.Bots, 1.1.1"
// Install Telegram.Bots as a Cake Addin
#addin nuget:?package=Telegram.Bots&version=1.1.1
// Install Telegram.Bots as a Cake Tool
#tool nuget:?package=Telegram.Bots&version=1.1.1
Telegram.Bots
A .NET Standard wrapper for the Telegram Bot API.
Overview
- Fully supports Bot API 5.0.
- Targets .NET Standard 2.1.
Getting Started
Configure the Bot Client
using Microsoft.Extensions.DependencyInjection;
using Telegram.Bots;
IServiceProvider provider = new ServiceCollection()
.AddBotClient("<bot-token>")
.Services
.BuildServiceProvider();
IBotClient bot = provider.GetRequiredService<IBotClient>();
Send a Text via Chat Id
using Telegram.Bots.Requests;
using Telegram.Bots.Types;
var request = new SendText(chatId: 123456789, text: "Hello, World!");
Response<TextMessage> response = await bot.HandleAsync(request);
if (response.Ok)
{
TextMessage message = response.Result;
...
}
else
{
Failure failure = response.Failure;
...
}
Send a Text via Chat Username
using Telegram.Bots.Requests.Usernames;
using Telegram.Bots.Types;
var request = new SendText(username: "@chat", text: "Hello, World!");
Response<TextMessage> response = await bot.HandleAsync(request);
Send an Audio File via Chat Id
using Telegram.Bots.Requests;
using Telegram.Bots.Types;
using File = System.IO.File;
await using FileStream audioStream = File.OpenRead("/path/to/audio.mp3");
var request = new SendAudioFile(chatId: 123456789, audio: audioStream)
{
Title = "Title",
Performer = "Performer",
Duration = 120
};
Response<AudioMessage> response = await bot.HandleAsync(request);
Send a Cached Video via Chat Username
using Telegram.Bots.Requests.Usernames;
using Telegram.Bots.Types;
var request = new SendCachedVideo(username: "@chat", video: "<file-id>")
{
Caption = "Caption"
};
Response<VideoMessage> response = await bot.HandleAsync(request);
Send a Media Group via Chat Id
using Telegram.Bots.Requests;
using Telegram.Bots.Types;
using File = System.IO.File;
await using var audioStream = File.OpenRead("path/to/audio.mp3");
await using var videoStream = File.OpenRead("path/to/video.mp4");
var request = new SendMediaGroup(chatId: 123456789, new List<IGroupableMedia>
{
new CachedPhoto("<photo-file-id>"),
new CachedVideo("<video-file-id>"),
new PhotoUrl(new Uri("https://example.com/image.png")),
new VideoUrl(new Uri("https://example.com/video.mp4")),
new PhotoFile(audioStream),
new VideoFile(videoStream)
})
{
DisableNotification = true
};
Response<IReadOnlyList<MediaGroupMessage>> response = await bot.HandleAsync(request);
Download a File
using Telegram.Bots.Types;
using File = System.IO.File;
await using var stream = File.OpenWrite("path/to/file.extension");
Response<FileInfo> response = await bot.HandleAsync("<file-id>", stream);
License
Telegram.Bots is a .NET Standard wrapper for the Telegram Bot API.
Copyright © 2020 Aman Agnihotri (amanagnihotri@pm.me)
Telegram.Bots is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Telegram.Bots is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with Telegram.Bots. If not, see GNU Licenses.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Http.Polly (>= 3.1.9)
- Newtonsoft.Json (>= 12.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Telegram.Bots:
Package | Downloads |
---|---|
Telegram.Bots.Extensions.Polling
Integrate Long Polling with Telegram.Bots |
|
Telegram.Bots.Extensions.AspNetCore
Integrate Telegram.Bots Serializer with ASP.NET Core |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.9.0 | 35,999 | 11/5/2022 |
5.8.0 | 1,302 | 11/2/2022 |
5.7.0 | 1,203 | 11/2/2022 |
5.6.0 | 2,061 | 6/12/2022 |
5.5.0 | 1,474 | 6/7/2022 |
5.4.0 | 1,409 | 6/6/2022 |
5.3.0 | 1,433 | 6/6/2022 |
5.2.0 | 1,965 | 11/5/2021 |
5.1.0 | 1,735 | 7/20/2021 |
5.0.0 | 1,626 | 6/27/2021 |
4.0.0 | 1,405 | 6/26/2021 |
3.0.0 | 904 | 3/21/2021 |
2.1.0 | 1,295 | 3/21/2021 |
2.0.0 | 1,395 | 1/23/2021 |
1.1.1 | 1,993 | 11/6/2020 |