├── .gitignore ├── package-icon.gif ├── package-icon.png ├── NetTelegramBotApi.Demo ├── t_logo.png ├── t_logo_180.png ├── Properties │ └── launchSettings.json ├── Пример_UTF8_filename.txt ├── appsettings.json ├── DemoBot.cs ├── Program.cs ├── NetTelegramBotApi.Demo.csproj ├── BotServiceHost.cs └── Telegram_Bot_API.htm ├── NetTelegramBotApi ├── Usings.cs ├── Util │ ├── JsonStringEnumConverterCamelCase.cs │ ├── JsonStringEnumConverterSnakeCaseLower.cs │ ├── IntegerOrStringConverter.cs │ ├── InputFileOrStringConverter.cs │ ├── UnixdateTimeConverter.cs │ ├── MessageOriginConverter.cs │ └── ChatMemberConverter.cs ├── Types │ ├── ParseMode.cs │ ├── ReactionTypeType.cs │ ├── MessageOriginType.cs │ ├── Story.cs │ ├── Venue.cs │ ├── ChatMemberStatus.cs │ ├── Sticker.cs │ ├── Poll.cs │ ├── Contact.cs │ ├── Location.cs │ ├── ReplyMarkupBase.cs │ ├── WebAppInfo.cs │ ├── Dice.cs │ ├── PaidMediaInfo.cs │ ├── ChatJoinRequest.cs │ ├── ChatBoostRemoved.cs │ ├── PollAnswer.cs │ ├── CallbackGame.cs │ ├── ChatBoostUpdated.cs │ ├── ShippingQuery.cs │ ├── BusinessConnection.cs │ ├── ChatMemberUpdated.cs │ ├── PaidMediaPurchased.cs │ ├── PreCheckoutQuery.cs │ ├── CallbackQuery.cs │ ├── Game.cs │ ├── MessageId.cs │ ├── InputMedia.cs │ ├── TextQuote.cs │ ├── ChatMemberLeft.cs │ ├── MessageOriginUser.cs │ ├── MessageReactionUpdated.cs │ ├── BusinessMessagesDeleted.cs │ ├── ChosenInlineResult.cs │ ├── MessageReactionCountUpdated.cs │ ├── MessageOrigin.cs │ ├── Birthdate.cs │ ├── ExternalReplyInfo.cs │ ├── InlineQuery.cs │ ├── MessageOriginHiddenUser.cs │ ├── ChatAction.cs │ ├── ChatMember.cs │ ├── ResponseParameters.cs │ ├── ChatLocation.cs │ ├── ChatType.cs │ ├── ChatMemberBanned.cs │ ├── ChatMemberOwner.cs │ ├── BusinessLocation.cs │ ├── BusinessOpeningHoursInterval.cs │ ├── ChatMemberMember.cs │ ├── InlineKeyboardMarkup.cs │ ├── BusinessOpeningHours.cs │ ├── MessageOriginChat.cs │ ├── ReactionType.cs │ ├── BusinessIntro.cs │ ├── MessageOriginChannel.cs │ ├── Voice.cs │ ├── ChatPhoto.cs │ ├── MessageEntityType.cs │ ├── PhotoSize.cs │ ├── LinkPreviewOptions.cs │ ├── Chat.cs │ ├── VideoNote.cs │ ├── Document.cs │ ├── SwitchInlineQueryChosenChat.cs │ ├── InputMediaPhoto.cs │ ├── ReplyParameters.cs │ ├── MessageEntity.cs │ ├── ForceReply.cs │ ├── InputMediaDocument.cs │ ├── LoginUrl.cs │ ├── Video.cs │ ├── Audio.cs │ ├── Animation.cs │ ├── WebhookInfo.cs │ ├── KeyboardButtonRequestUsers.cs │ ├── ReplyKeyboardMarkup.cs │ ├── InputMediaAudio.cs │ ├── ReplyKeyboardRemove.cs │ ├── KeyboardButton.cs │ ├── InlineKeyboardButton.cs │ ├── InputMediaAnimation.cs │ ├── User.cs │ ├── InputMediaVideo.cs │ ├── ChatPermissions.cs │ ├── ChatMemberRestricted.cs │ ├── ChatMemberAdministrator.cs │ ├── Update.cs │ ├── ChatFullInfo.cs │ └── Message.cs ├── ITelegramBot.cs ├── Requests │ ├── GetWebhookInfo.cs │ ├── GetChat.cs │ ├── GetChatMemberCount.cs │ ├── UnpinAllChatMessages.cs │ ├── GetMe.cs │ ├── DeleteWebhook.cs │ ├── GetChatAdministrators.cs │ ├── DeleteMessage.cs │ ├── UnpinChatMessage.cs │ ├── DeleteMessages.cs │ ├── GetChatMember.cs │ ├── PinChatMessage.cs │ ├── GetUpdates.cs │ ├── SetWebhook.cs │ ├── SendChatAction.cs │ ├── ForwardMessage.cs │ ├── ForwardMessages.cs │ ├── EditMessageMedia.cs │ ├── EditMessageReplyMarkup.cs │ ├── SendMessage.cs │ ├── SendVideoNote.cs │ ├── SendVoice.cs │ ├── EditMessageText.cs │ ├── EditMessageCaption.cs │ ├── SendDocument.cs │ ├── SendPhoto.cs │ ├── SendAudio.cs │ ├── SendAnimation.cs │ └── SendVideo.cs ├── ResponseBase.cs ├── IntegerOrString.cs ├── InputFile.cs ├── RequestFailedException.cs ├── InputFileOrString.cs ├── Extensions │ ├── StringExtensions.cs │ └── TelegramBotExtensions.cs ├── NetTelegramBotApi.csproj ├── TelegramBot.cs └── RequestBase.cs ├── appveyor.yml ├── Settings.StyleCop ├── LICENSE ├── NetTelegramBotApi.Tests └── NetTelegramBotApi.Tests.csproj ├── GlobalSuppressions.cs ├── README.md └── NetTelegramBotApi.sln /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | *.user 4 | /.vs 5 | appsettings.*.json -------------------------------------------------------------------------------- /package-icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justdmitry/NetTelegramBotApi/HEAD/package-icon.gif -------------------------------------------------------------------------------- /package-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justdmitry/NetTelegramBotApi/HEAD/package-icon.png -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/t_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justdmitry/NetTelegramBotApi/HEAD/NetTelegramBotApi.Demo/t_logo.png -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/t_logo_180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justdmitry/NetTelegramBotApi/HEAD/NetTelegramBotApi.Demo/t_logo_180.png -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Default": { 4 | "commandName": "Project" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/Пример_UTF8_filename.txt: -------------------------------------------------------------------------------- 1 | Eng: 2 | This is sample file with non-latin name (validating issue #5) 3 | 4 | Rus: 5 | Это пример файла с кириллицей в названии (проверяем issue #5) -------------------------------------------------------------------------------- /NetTelegramBotApi/Usings.cs: -------------------------------------------------------------------------------- 1 | global using System.Text.Json; 2 | global using System.Text.Json.Serialization; 3 | global using NetTelegramBotApi.Types; 4 | global using NetTelegramBotApi.Util; 5 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: N{build} 2 | image: Visual Studio 2022 3 | before_build: 4 | - cmd: dotnet restore 5 | build: 6 | verbosity: minimal 7 | test_script: 8 | - cmd: dotnet test NetTelegramBotApi.Tests/NetTelegramBotApi.Tests.csproj 9 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "Microsoft": "Information", 6 | "System": "Warning" 7 | } 8 | }, 9 | "BotToken": "12345:aaabbbccc" 10 | } 11 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/JsonStringEnumConverterCamelCase.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Util 2 | { 3 | public class JsonStringEnumConverterCamelCase() 4 | : JsonStringEnumConverter(JsonNamingPolicy.CamelCase) 5 | { 6 | // Nothing 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ParseMode.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonConverter(typeof(JsonStringEnumConverterCamelCase))] 4 | public enum ParseMode 5 | { 6 | Markdown, 7 | MarkdownV2, 8 | HTML, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/JsonStringEnumConverterSnakeCaseLower.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Util 2 | { 3 | public class JsonStringEnumConverterSnakeCaseLower() 4 | : JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower) 5 | { 6 | // Nothing 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ReactionTypeType.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonConverter(typeof(JsonStringEnumConverterSnakeCaseLower))] 4 | public enum ReactionTypeType 5 | { 6 | Emoji, 7 | CustomEmoji, 8 | Paid, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /NetTelegramBotApi/ITelegramBot.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | public interface ITelegramBot 4 | { 5 | Task Execute(RequestBase request, CancellationToken cancellationToken = default); 6 | 7 | Update? DeserializeUpdate(string json); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageOriginType.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonConverter(typeof(JsonStringEnumConverterSnakeCaseLower))] 4 | public enum MessageOriginType 5 | { 6 | Unknown, 7 | User, 8 | HiddenUser, 9 | Chat, 10 | Channel, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/DemoBot.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Demo 2 | { 3 | using System.Net.Http; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | public class DemoBot(IConfiguration configuration, HttpClient httpClient) 7 | : TelegramBot(configuration["BotToken"], httpClient) 8 | { 9 | // Nothing 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Story.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a story. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Story 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Venue.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a venue. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Venue 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberStatus.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonConverter(typeof(JsonStringEnumConverterSnakeCaseLower))] 4 | public enum ChatMemberStatus 5 | { 6 | Unknown, 7 | Creator, 8 | Administrator, 9 | Member, 10 | Restricted, 11 | Left, 12 | Kicked, 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Sticker.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a sticker. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Sticker 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Poll.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about a poll. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Poll 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Contact.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a phone contact. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Contact 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Location.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a point on the map. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Location 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ReplyMarkupBase.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonDerivedType(typeof(InlineKeyboardMarkup))] 4 | [JsonDerivedType(typeof(ReplyKeyboardMarkup))] 5 | [JsonDerivedType(typeof(ReplyKeyboardRemove))] 6 | [JsonDerivedType(typeof(ForceReply))] 7 | public abstract class ReplyMarkupBase 8 | { 9 | // Nothing 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/WebAppInfo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes a Web App. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class WebAppInfo 10 | { 11 | public required string Url { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Dice.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an animated emoji that displays a random value. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Dice 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/PaidMediaInfo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes the paid media added to a message. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class PaidMediaInfo 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatJoinRequest.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a join request sent to a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatJoinRequest 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatBoostRemoved.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a boost removed from a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatBoostRemoved 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/PollAnswer.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an answer of a user in a non-anonymous poll. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class PollAnswer 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.Hosting; 3 | using NetTelegramBotApi; 4 | using NetTelegramBotApi.Demo; 5 | 6 | var builder = Host.CreateApplicationBuilder(args); 7 | builder.Services.AddHttpClient(); 8 | builder.Services.AddHostedService(); 9 | 10 | var app = builder.Build(); 11 | await app.RunAsync(); 12 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/CallbackGame.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// A placeholder, currently holds no information. Use BotFather to set up your game. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class CallbackGame 10 | { 11 | // Nothing 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatBoostUpdated.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a boost added to a chat or changed. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatBoostUpdated 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ShippingQuery.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about an incoming shipping query. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ShippingQuery 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/BusinessConnection.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes the connection of the bot with a business account. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class BusinessConnection 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberUpdated.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents changes in the status of a chat member. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberUpdated 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/PaidMediaPurchased.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about a paid media purchase. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class PaidMediaPurchased 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/PreCheckoutQuery.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about an incoming pre-checkout query. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class PreCheckoutQuery 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetWebhookInfo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to get current webhook status. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class GetWebhookInfo() : RequestBase("getWebhookInfo") 10 | { 11 | // Nothing. 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/CallbackQuery.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an incoming callback query from a callback button in an inline keyboard. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class CallbackQuery 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Game.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Game 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageId.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a unique message identifier. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageId 10 | { 11 | [JsonPropertyName("message_id")] 12 | public long Id { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InputMedia.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonDerivedType(typeof(InputMediaPhoto))] 4 | [JsonDerivedType(typeof(InputMediaVideo))] 5 | [JsonDerivedType(typeof(InputMediaAnimation))] 6 | [JsonDerivedType(typeof(InputMediaAudio))] 7 | [JsonDerivedType(typeof(InputMediaDocument))] 8 | public abstract class InputMedia 9 | { 10 | public abstract string Type { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/TextQuote.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about the quoted part of a message that is replied to by the given message. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class TextQuote 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberLeft.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a chat member that isn't currently a member of the chat, but may join it themselves. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberLeft : ChatMember 10 | { 11 | // Nothing. 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageOriginUser.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// The message was originally sent by a known user. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageOriginUser : MessageOrigin 10 | { 11 | public User SenderUser { get; set; } = default!; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageReactionUpdated.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a change of a reaction on a message performed by a user. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageReactionUpdated 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/BusinessMessagesDeleted.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object is received when messages are deleted from a connected business account. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class BusinessMessagesDeleted 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChosenInlineResult.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a result of an inline query that was chosen by the user and sent to their chat partner. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChosenInlineResult 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageReactionCountUpdated.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents reaction changes on a message with anonymous reactions. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageReactionCountUpdated 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetChat.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to get up-to-date information about the chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class GetChat() : RequestBase("getChat") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageOrigin.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object describes the origin of a message. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageOrigin 10 | { 11 | public MessageOriginType Type { get; set; } 12 | 13 | public DateTimeOffset Date { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Birthdate.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes the birthdate of a user. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Birthdate 10 | { 11 | public int Day { get; set; } 12 | 13 | public int Month { get; set; } 14 | 15 | public int? Year { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ExternalReplyInfo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about a message that is being replied to, which may come from another chat or forum topic. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ExternalReplyInfo 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InlineQuery.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InlineQuery 10 | { 11 | // TODO: Add fields 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageOriginHiddenUser.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// The message was originally sent by an unknown user. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageOriginHiddenUser : MessageOrigin 10 | { 11 | public string SenderUserName { get; set; } = default!; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatAction.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonConverter(typeof(JsonStringEnumConverterSnakeCaseLower))] 4 | public enum ChatAction 5 | { 6 | Typing, 7 | UploadPhoto, 8 | RecordVideo, 9 | UploadVideo, 10 | RecordVoice, 11 | UploadVoice, 12 | UploadDocument, 13 | ChooseSticker, 14 | FindLocation, 15 | RecordVideoNote, 16 | UploadVideoNote, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMember.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains information about one member of a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMember 10 | { 11 | public ChatMemberStatus Status { get; set; } 12 | 13 | public User User { get; set; } = default!; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ResponseParameters.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes why a request was unsuccessful. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ResponseParameters 10 | { 11 | public long? MigrateToChatId { get; set; } 12 | 13 | public long? RetryAfter { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatLocation.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a location to which a chat is connected. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatLocation 10 | { 11 | public Location Location { get; set; } = default!; 12 | 13 | public string Address { get; set; } = string.Empty; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatType.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Type of the chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | [JsonConverter(typeof(JsonStringEnumConverterSnakeCaseLower))] 10 | public enum ChatType 11 | { 12 | Unknown, 13 | Private, 14 | Group, 15 | Supergroup, 16 | Channel, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetChatMemberCount.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to get the number of members in a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class GetChatMemberCount() : RequestBase("getChatMemberCount") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberBanned.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a chat member that was banned in the chat and can't return to the chat or view chat messages. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberBanned : ChatMember 10 | { 11 | public DateTimeOffset UntilDate { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/UnpinAllChatMessages.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to clear the list of pinned messages in a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class UnpinAllChatMessages() : RequestBase("unpinAllChatMessages") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetMe.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// A simple method for testing your bot's auth token. Requires no parameters. 5 | /// Returns basic information about the bot in form of a object. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class GetMe() : RequestBase("getMe") 11 | { 12 | // Nothing. 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberOwner.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a chat member that owns the chat and has all administrator privileges. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberOwner : ChatMember 10 | { 11 | public bool IsAnonymous { get; set; } 12 | 13 | public string? CustomTitle { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/DeleteWebhook.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class DeleteWebhook() : RequestBase("deleteWebhook") 10 | { 11 | public bool? DropPendingUpdates { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/BusinessLocation.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Contains information about the location of a Telegram Business account. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class BusinessLocation 10 | { 11 | public string Address { get; set; } = string.Empty; 12 | 13 | public Location Location { get; set; } = default!; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/BusinessOpeningHoursInterval.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes an interval of time during which a business is open. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class BusinessOpeningHoursInterval 10 | { 11 | public int OpeningMinute { get; set; } 12 | 13 | public int ClosingMinute { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberMember.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a chat member that has no additional privileges or restrictions. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberMember : ChatMember 10 | { 11 | public bool IsAnonymous { get; set; } 12 | 13 | public DateTimeOffset? UntilDate { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InlineKeyboardMarkup.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an inline keyboard that appears right next to the message it belongs to. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InlineKeyboardMarkup : ReplyMarkupBase 10 | { 11 | public required InlineKeyboardButton[][] InlineKeyboard { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/BusinessOpeningHours.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes the opening hours of a business. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class BusinessOpeningHours 10 | { 11 | public string TimeZoneName { get; set; } = string.Empty; 12 | 13 | public BusinessOpeningHoursInterval[] OpeningHours { get; set; } = []; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageOriginChat.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// The message was originally sent on behalf of a chat to a group chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageOriginChat : MessageOrigin 10 | { 11 | public Chat SenderChat { get; set; } = default!; 12 | 13 | public string? AuthorSignature { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ReactionType.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains full information about a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ReactionType 10 | { 11 | public ReactionTypeType Type { get; set; } 12 | 13 | public string? Emoji { get; set; } 14 | 15 | public string? CustomEmojiId { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetChatAdministrators.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to get a list of administrators in a chat, which aren't bots. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class GetChatAdministrators() : RequestBase("getChatAdministrators") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/BusinessIntro.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Contains information about the start page settings of a Telegram Business account. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class BusinessIntro 10 | { 11 | public string? Title { get; set; } 12 | 13 | public string? Message { get; set; } 14 | 15 | public Sticker? Sticker{ get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageOriginChannel.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// The message was originally sent to a channel chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageOriginChannel : MessageOrigin 10 | { 11 | public Chat Chat { get; set; } = default!; 12 | 13 | public long MessageId { get; set; } 14 | 15 | public string? AuthorSignature { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/DeleteMessage.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to delete a message, including service messages. 5 | /// 6 | /// 7 | /// There are some limitations, see . 8 | /// 9 | public class DeleteMessage() : RequestBase("deleteMessage") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | 13 | public required long MessageId { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Voice.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a voice note. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Voice 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public int Duration { get; set; } 16 | 17 | public string? MimeType { get; set; } 18 | 19 | public long? FileSize { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/UnpinChatMessage.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to remove a message from the list of pinned messages in a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class UnpinChatMessage() : RequestBase("unpinChatMessage") 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageId { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatPhoto.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a chat photo. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatPhoto 10 | { 11 | public string SmallFileId { get; set; } = string.Empty; 12 | 13 | public string SmallFileUniqueId { get; set; } = string.Empty; 14 | 15 | public string BigFileId { get; set; } = string.Empty; 16 | 17 | public string BigFileUniqueId { get; set; } = string.Empty; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | False 8 | 9 | 10 | 11 | 12 | False 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/DeleteMessages.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to delete multiple messages simultaneously. 5 | /// If some of the specified messages can't be found, they are skipped. 6 | /// 7 | /// 8 | /// There are some limitations, see . 9 | /// 10 | public class DeleteMessages() : RequestBase("deleteMessages") 11 | { 12 | public required IntegerOrString ChatId { get; set; } 13 | 14 | public required long[] MessageIds { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetChatMember.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to get information about a member of a chat. 5 | /// The method is only guaranteed to work for other users if the bot is an administrator in the chat. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class GetChatMember() : RequestBase("getChatMember") 11 | { 12 | public required IntegerOrString ChatId { get; set; } 13 | 14 | public required long UserId { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageEntityType.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | [JsonConverter(typeof(JsonStringEnumConverterSnakeCaseLower))] 4 | public enum MessageEntityType 5 | { 6 | Unknown, 7 | Mention, 8 | Hashtag, 9 | Cashtag, 10 | BotCommand, 11 | Url, 12 | Email, 13 | PhoneNumber, 14 | Bold, 15 | Italic, 16 | Underline, 17 | Strikethrough, 18 | Spoiler, 19 | Blockquote, 20 | ExpandableBlockquote, 21 | Code, 22 | Pre, 23 | TextLink, 24 | TextMention, 25 | CustomEmoji, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/PhotoSize.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents one size of a photo or a file / sticker thumbnail. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class PhotoSize 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public int Width { get; set; } 16 | 17 | public int Height { get; set; } 18 | 19 | public int? FileSize { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/LinkPreviewOptions.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes the options used for link preview generation. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class LinkPreviewOptions 10 | { 11 | public bool? IsDisabled { get; set; } 12 | 13 | public string? Url { get; set; } 14 | 15 | public bool? PreferSmallMedia { get; set; } 16 | 17 | public bool? PreferLargeMedia { get; set; } 18 | 19 | public bool? ShowAboveText { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Chat.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Chat 10 | { 11 | public long Id { get; set; } 12 | 13 | public ChatType Type { get; set; } 14 | 15 | public string? Title { get; set; } 16 | 17 | public string? Username { get; set; } 18 | 19 | public string? FirstName { get; set; } 20 | 21 | public string? LastName { get; set; } 22 | 23 | public bool? IsForum { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/PinChatMessage.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to add a message to the list of pinned messages in a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class PinChatMessage() : RequestBase("pinChatMessage") 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public required long MessageId { get; set; } 16 | 17 | public bool? DisableNotification { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/GetUpdates.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to receive incoming updates using long polling (wiki). 5 | /// An Array of objects is returned. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class GetUpdates() : RequestBase("getUpdates") 11 | { 12 | public long? Offset { get; set; } 13 | 14 | public int? Limit { get; set; } 15 | 16 | public int? Timeout { get; set; } 17 | 18 | public string[]? AllowedUpdates { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NetTelegramBotApi/ResponseBase.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | /// 4 | /// The response contains a JSON object. 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// Result of the query. 10 | public class ResponseBase 11 | { 12 | public bool Ok { get; set; } 13 | 14 | public string? Description { get; set; } 15 | 16 | public TResult? Result { get; set; } 17 | 18 | public long? ErrorCode { get; set; } 19 | 20 | public ResponseParameters? Parameters { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/VideoNote.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a video message (available in Telegram apps as of v.4.0). 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class VideoNote 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public int Length { get; set; } 16 | 17 | public int Duration { get; set; } 18 | 19 | public PhotoSize? Thumbnail { get; set; } 20 | 21 | public long? FileSize { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Document.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a general file (as opposed to photos, voice messages and audio files). 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Document 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public PhotoSize? Thumbnail { get; set; } 16 | 17 | public string? FileName { get; set; } 18 | 19 | public string? MimeType { get; set; } 20 | 21 | public long? FileSize { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/IntegerOrStringConverter.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Util 2 | { 3 | public class IntegerOrStringConverter : JsonConverter 4 | { 5 | public override bool CanConvert(Type typeToConvert) 6 | { 7 | return typeToConvert == typeof(IntegerOrString); 8 | } 9 | 10 | public override IntegerOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override void Write(Utf8JsonWriter writer, IntegerOrString value, JsonSerializerOptions options) 16 | { 17 | writer.WriteStringValue(value.Value); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/InputFileOrStringConverter.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Util 2 | { 3 | public class InputFileOrStringConverter : JsonConverter 4 | { 5 | public override bool CanConvert(Type typeToConvert) 6 | { 7 | return typeToConvert == typeof(InputFileOrString); 8 | } 9 | 10 | public override InputFileOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override void Write(Utf8JsonWriter writer, InputFileOrString value, JsonSerializerOptions options) 16 | { 17 | writer.WriteStringValue(value.String); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NetTelegramBotApi/IntegerOrString.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | public readonly struct IntegerOrString 4 | { 5 | public IntegerOrString(string value) 6 | { 7 | this.Value = value; 8 | } 9 | 10 | public IntegerOrString(long value) 11 | { 12 | this.Value = value.ToString(System.Globalization.CultureInfo.InvariantCulture); 13 | } 14 | 15 | public string Value { get; } 16 | 17 | public static implicit operator IntegerOrString(string value) => new(value); 18 | 19 | public static implicit operator IntegerOrString(long value) => new(value); 20 | 21 | public override readonly string ToString() 22 | { 23 | return this.Value; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/SwitchInlineQueryChosenChat.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an inline button that switches the current user to inline mode in a chosen chat, with an optional default inline query. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SwitchInlineQueryChosenChat 10 | { 11 | public string? Query { get; set; } 12 | 13 | public bool? AllowUserChats { get; set; } 14 | 15 | public bool? AllowBotChats { get; set; } 16 | 17 | public bool? AllowGroupChats { get; set; } 18 | 19 | public bool? AllowChannelChats { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InputMediaPhoto.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a photo to be sent. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InputMediaPhoto : InputMedia 10 | { 11 | public override string Type { get; } = "photo"; 12 | 13 | public required InputFileOrString Media { get; set; } 14 | 15 | public string? Caption { get; set; } 16 | 17 | public ParseMode? ParseMode { get; set; } 18 | 19 | public MessageEntity[]? CaptionEntities { get; set; } 20 | 21 | public bool? ShowCaptionAboveMedia { get; set; } 22 | 23 | public bool? HasSpoiler { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ReplyParameters.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes reply parameters for the message that is being sent. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ReplyParameters 10 | { 11 | public required long MessageId { get; set; } 12 | 13 | public string? ChatId { get; set; } 14 | 15 | public bool? AllowSendingWithoutReply { get; set; } 16 | 17 | public string? Quote { get; set; } 18 | 19 | public ParseMode? QuoteParseMode { get; set; } 20 | 21 | public MessageEntity[]? QuoteEntities { get; set; } 22 | 23 | public int? QuotePosition { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/MessageEntity.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class MessageEntity 10 | { 11 | public required MessageEntityType Type { get; set; } 12 | 13 | public required int Offset { get; set; } 14 | 15 | public required int Length { get; set; } 16 | 17 | public string? Url { get; set; } 18 | 19 | public User? User { get; set; } 20 | 21 | public string? Language { get; set; } 22 | 23 | public string? CustomEmojiId { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ForceReply.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Upon receiving a message with this object, Telegram clients will display a reply interface to the user 5 | /// (act as if the user has selected the bot‘s message and tapped ’Reply'). 6 | /// This can be extremely useful if you want to create user-friendly step-by-step interfaces 7 | /// without having to sacrifice privacy mode. 8 | /// 9 | /// 10 | /// 11 | /// 12 | public class ForceReply : ReplyMarkupBase 13 | { 14 | public required bool Force { get; set; } 15 | 16 | public string? InputFieldPlaceholder { get; set; } 17 | 18 | public bool? Selective { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InputMediaDocument.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a general file to be sent. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InputMediaDocument : InputMedia 10 | { 11 | public override string Type { get; } = "document"; 12 | 13 | public required InputFileOrString Media { get; set; } 14 | 15 | public InputFileOrString? Thumbnail { get; set; } 16 | 17 | public string? Caption { get; set; } 18 | 19 | public ParseMode? ParseMode { get; set; } 20 | 21 | public MessageEntity[]? CaptionEntities { get; set; } 22 | 23 | public bool? DisableContentTypeDetection { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/LoginUrl.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a parameter of the inline keyboard button used to automatically authorize a user. 5 | /// Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram. 6 | /// All the user needs to do is tap/click a button and confirm that they want to log in. 7 | /// 8 | /// 9 | /// 10 | /// 11 | public class LoginUrl 12 | { 13 | public required string Url { get; set; } 14 | 15 | public string? ForwardText { get; set; } 16 | 17 | public string? BotUsername { get; set; } 18 | 19 | public bool? RequestWriteAccess { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Video.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a video file. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Video 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public int Width { get; set; } 16 | 17 | public int Height { get; set; } 18 | 19 | public int Duration { get; set; } 20 | 21 | public PhotoSize? Thumbnail { get; set; } 22 | 23 | public string? FileName { get; set; } 24 | 25 | public string? MimeType { get; set; } 26 | 27 | public long? FileSize { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/UnixdateTimeConverter.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Util 2 | { 3 | public class UnixDateTimeConverter : JsonConverter 4 | { 5 | public override bool CanConvert(Type typeToConvert) 6 | { 7 | return typeToConvert == typeof(DateTimeOffset); 8 | } 9 | 10 | public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 11 | { 12 | var t = reader.GetInt64(); 13 | return DateTimeOffset.FromUnixTimeSeconds(t); 14 | } 15 | 16 | public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) 17 | { 18 | var t = value.ToUnixTimeSeconds(); 19 | writer.WriteNumberValue(t); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SetWebhook.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to specify a URL and receive incoming updates via an outgoing webhook. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SetWebhook() : RequestBase("setWebhook", true) 10 | { 11 | public required string Url { get; set; } 12 | 13 | public InputFile? Certificate { get; set; } 14 | 15 | public string? IpAddress { get; set; } 16 | 17 | public int? MaxConnections { get; set; } 18 | 19 | public string[]? AllowedUpdates { get; set; } 20 | 21 | public bool? DropPendingUpdates { get; set; } 22 | 23 | public string? SecretToken { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetTelegramBotApi/InputFile.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | public readonly struct InputFile(Stream content, string name) 4 | { 5 | public readonly Stream Content { get; } = content; 6 | 7 | public readonly string Name { get; } = name; 8 | 9 | public static implicit operator InputFile(FileInfo fileInfo) 10 | { 11 | ArgumentNullException.ThrowIfNull(fileInfo); 12 | 13 | return new(fileInfo.OpenRead(), fileInfo.Name); 14 | } 15 | 16 | public static implicit operator InputFile((Stream Content, string FileName) fileData) 17 | { 18 | ArgumentNullException.ThrowIfNull(fileData.Content); 19 | ArgumentException.ThrowIfNullOrWhiteSpace(fileData.FileName); 20 | 21 | return new(fileData.Content, fileData.FileName); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendChatAction.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method when you need to tell the user that something is happening on the bot's side. 5 | /// The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). 6 | /// Returns True on success. 7 | /// 8 | /// 9 | /// 10 | /// 11 | public class SendChatAction() : RequestBase("sendChatAction") 12 | { 13 | public string? BusinessConnectionId { get; set; } 14 | 15 | public required IntegerOrString ChatId { get; set; } 16 | 17 | public long? MessageThreadId { get; set; } 18 | 19 | public required ChatAction Action { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Audio.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an audio file to be treated as music by the Telegram clients. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Audio 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public int Duration { get; set; } 16 | 17 | public string? Performer { get; set; } 18 | 19 | public string? Title { get; set; } 20 | 21 | public string? FileName { get; set; } 22 | 23 | public string? MimeType { get; set; } 24 | 25 | public long? FileSize { get; set; } 26 | 27 | public PhotoSize? Thumbnail { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Animation.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Animation 10 | { 11 | public string FileId { get; set; } = string.Empty; 12 | 13 | public string FileUniqueId { get; set; } = string.Empty; 14 | 15 | public int Width { get; set; } 16 | 17 | public int Height { get; set; } 18 | 19 | public int Duration { get; set; } 20 | 21 | public PhotoSize? Thumbnail { get; set; } 22 | 23 | public string? FileName { get; set; } 24 | 25 | public string? MimeType { get; set; } 26 | 27 | public long? FileSize { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/ForwardMessage.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ForwardMessage() : RequestBase("forwardMessage") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | 13 | public long? MessageThreadId { get; set; } 14 | 15 | public required IntegerOrString FromChatId { get; set; } 16 | 17 | public bool? DisableNotification { get; set; } 18 | 19 | public bool? ProtectContent { get; set; } 20 | 21 | public required long MessageId { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/WebhookInfo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes the current status of a webhook. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class WebhookInfo 10 | { 11 | public string? Url { get; set; } 12 | 13 | public bool HasCustomCertificate { get; set; } 14 | 15 | public int PendingUpdateCount { get; set; } 16 | 17 | public string? IpAddress { get; set; } 18 | 19 | public DateTimeOffset? LastErrorDate { get; set; } 20 | 21 | public string? LastErrorMessage { get; set; } 22 | 23 | public DateTimeOffset? LastSynchronizationErrorDate { get; set; } 24 | 25 | public int? MaxConnections { get; set; } 26 | 27 | public string[]? AllowedUpdates { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/ForwardMessages.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ForwardMessages() : RequestBase("forwardMessages") 10 | { 11 | public required IntegerOrString ChatId { get; set; } 12 | 13 | public long? MessageThreadId { get; set; } 14 | 15 | public required IntegerOrString FromChatId { get; set; } 16 | 17 | public required long[] MessageIds { get; set; } 18 | 19 | public bool? DisableNotification { get; set; } 20 | 21 | public bool? ProtectContent { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/KeyboardButtonRequestUsers.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object defines the criteria used to request suitable users. 5 | /// Information about the selected users will be shared with the bot when the corresponding button is pressed. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class KeyboardButtonRequestUsers 11 | { 12 | public required int RequestId { get; set; } 13 | 14 | public bool? UserIsBot { get; set; } 15 | 16 | public bool? UserIsPremium { get; set; } 17 | 18 | public byte? MaxQuantity { get; set; } 19 | 20 | public bool? RequestName { get; set; } 21 | 22 | public bool? RequestUsername { get; set; } 23 | 24 | public bool? RequestPhoto { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ReplyKeyboardMarkup.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). 5 | /// Not supported in channels and for messages sent on behalf of a Telegram Business account. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class ReplyKeyboardMarkup : ReplyMarkupBase 11 | { 12 | public required KeyboardButton[][] Keyboard { get; set; } 13 | 14 | public bool? IsPersistent { get; set; } 15 | 16 | public bool? ResizeKeyboard { get; set; } 17 | 18 | public bool? OneTimeKeyboard { get; set; } 19 | 20 | public string? InputFieldPlaceholder { get; set; } 21 | 22 | public bool? Selective { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InputMediaAudio.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents an audio file to be treated as music to be sent. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InputMediaAudio : InputMedia 10 | { 11 | public override string Type { get; } = "audio"; 12 | 13 | public required InputFileOrString Media { get; set; } 14 | 15 | public InputFileOrString? Thumbnail { get; set; } 16 | 17 | public string? Caption { get; set; } 18 | 19 | public ParseMode? ParseMode { get; set; } 20 | 21 | public MessageEntity[]? CaptionEntities { get; set; } 22 | 23 | public int? Duration { get; set; } 24 | 25 | public string? Performer { get; set; } 26 | 27 | public string? Title { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ReplyKeyboardRemove.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Upon receiving a message with this object, Telegram clients will remove the current custom keyboard 5 | /// and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. 6 | /// An exception is made for one-time keyboards that are hidden immediately after the user presses a button 7 | /// (see ReplyKeyboardMarkup). 8 | /// Not supported in channels and for messages sent on behalf of a Telegram Business account. 9 | /// 10 | /// 11 | /// 12 | /// 13 | public class ReplyKeyboardRemove : ReplyMarkupBase 14 | { 15 | public required bool RemoveKeyboard { get; set; } 16 | 17 | public bool? Selective { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/EditMessageMedia.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. 5 | /// On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class EditMessageMedia() : RequestBase("editMessageMedia", true) 11 | { 12 | public string? BusinessConnectionId { get; set; } 13 | 14 | public IntegerOrString? ChatId { get; set; } 15 | 16 | public long? MessageId { get; set; } 17 | 18 | public string? InlineMessageId { get; set; } 19 | 20 | public required InputMedia Media { get; set; } 21 | 22 | public ReplyMarkupBase? ReplyMarkup { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/KeyboardButton.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents one button of the reply keyboard. At most one of the optional fields must be used to specify type of the button. 5 | /// For simple text buttons, String can be used instead of this object to specify the button text. 6 | /// 7 | /// 8 | /// 9 | /// 10 | public class KeyboardButton 11 | { 12 | public required string Text { get; set; } 13 | 14 | public KeyboardButtonRequestUsers? RequestUsers { get; set; } 15 | 16 | // TODO: Implement 17 | public object? RequestChat { get; set; } 18 | 19 | public bool? RequestContact { get; set; } 20 | 21 | public bool? RequestLocation { get; set; } 22 | 23 | // TODO: Implement 24 | public object? RequestPoll { get; set; } 25 | 26 | public WebAppInfo? WebApp { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InlineKeyboardButton.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents one button of an inline keyboard. You must use exactly one of the optional fields. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InlineKeyboardButton 10 | { 11 | public required string Text { get; set; } 12 | 13 | public string? Url { get; set; } 14 | 15 | public string? CallbackData { get; set; } 16 | 17 | public WebAppInfo? WebApp { get; set; } 18 | 19 | public LoginUrl? LoginUrl { get; set; } 20 | 21 | public string? SwitchInlineQuery { get; set; } 22 | 23 | public string? SwitchInlineQueryCurrentChat { get; set; } 24 | 25 | public SwitchInlineQueryChosenChat? SwitchInlineQueryChosenChat { get; set; } 26 | 27 | public CallbackGame? CallbackGame { get; set; } 28 | 29 | public bool? Pay { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/EditMessageReplyMarkup.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to edit only the reply markup of messages. 5 | /// On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. 6 | /// 7 | /// 8 | /// Note that business messages that were not sent by the bot and do not contain an inline keyboard 9 | /// can only be edited within 48 hours from the time they were sent. 10 | /// 11 | /// 12 | public class EditMessageReplyMarkup() : RequestBase("editMessageReplyMarkup") 13 | { 14 | public string? BusinessConnectionId { get; set; } 15 | 16 | public IntegerOrString? ChatId { get; set; } 17 | 18 | public long? MessageId { get; set; } 19 | 20 | public string? InlineMessageId { get; set; } 21 | 22 | public ReplyMarkupBase? ReplyMarkup { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InputMediaAnimation.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InputMediaAnimation : InputMedia 10 | { 11 | public override string Type { get; } = "animation"; 12 | 13 | public required InputFileOrString Media { get; set; } 14 | 15 | public InputFileOrString? Thumbnail { get; set; } 16 | 17 | public string? Caption { get; set; } 18 | 19 | public ParseMode? ParseMode { get; set; } 20 | 21 | public MessageEntity[]? CaptionEntities { get; set; } 22 | 23 | public bool? ShowCaptionAboveMedia { get; set; } 24 | 25 | public int? Width { get; set; } 26 | 27 | public int? Height { get; set; } 28 | 29 | public int? Duration { get; set; } 30 | 31 | public bool? HasSpoiler { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/User.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a Telegram user or bot. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class User 10 | { 11 | public long Id { get; set; } 12 | 13 | public bool IsBot { get; set; } 14 | 15 | public string FirstName { get; set; } = string.Empty; 16 | 17 | public string? LastName { get; set; } 18 | 19 | public string? Username { get; set; } 20 | 21 | public string? LanguageCode { get; set; } 22 | 23 | public bool? IsPremium { get; set; } 24 | 25 | public bool? AddedToAttachmentMenu { get; set; } 26 | 27 | public bool? CanJoinGroups { get; set; } 28 | 29 | public bool? CanReadAllGroupMessages { get; set; } 30 | 31 | public bool? SupportsInlineQueries { get; set; } 32 | 33 | public bool? CanConnectToBusiness { get; set; } 34 | 35 | public bool? HasMainWebApp { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015 Dmitry Popov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NetTelegramBotApi/RequestFailedException.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | using System; 4 | using System.Net; 5 | 6 | public class RequestFailedException(string message) : Exception(message) 7 | { 8 | /// 9 | /// HTTP Status Code retuned by server. 10 | /// 11 | public required HttpStatusCode StatusCode { get; set; } 12 | 13 | /// 14 | /// Response body text. 15 | /// 16 | public required string ResponseBody { get; set; } 17 | 18 | /// 19 | /// Optional. Human-readable description of the result (by Telegram). 20 | /// 21 | public string? Description { get; set; } 22 | 23 | /// 24 | /// Contents are subject to change in the future (by Telegram). 25 | /// 26 | public long? ErrorCode { get; set; } 27 | 28 | /// 29 | /// Optional. Can help to automatically handle the error (by Telegram). 30 | /// 31 | public ResponseParameters? Parameters { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendMessage.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send text messages. On success, the sent Message is returned. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendMessage() : RequestBase("sendMessage") 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required string Text { get; set; } 18 | 19 | public ParseMode? ParseMode { get; set; } 20 | 21 | public MessageEntity[]? Entities { get; set; } 22 | 23 | public LinkPreviewOptions? LinkPreviewOptions { get; set; } 24 | 25 | public bool? DisableNotification { get; set; } 26 | 27 | public bool? ProtectContent { get; set; } 28 | 29 | public string? MessageEffectId { get; set; } 30 | 31 | public ReplyParameters? ReplyParameters { get; set; } 32 | 33 | public ReplyMarkupBase? ReplyMarkup { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/InputMediaVideo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a video to be sent. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class InputMediaVideo : InputMedia 10 | { 11 | public override string Type { get; } = "video"; 12 | 13 | public required InputFileOrString Media { get; set; } 14 | 15 | public InputFileOrString? Thumbnail { get; set; } 16 | 17 | public InputFileOrString? Cover { get; set; } 18 | 19 | public DateTimeOffset? StartTimestamp { get; set; } 20 | 21 | public string? Caption { get; set; } 22 | 23 | public ParseMode? ParseMode { get; set; } 24 | 25 | public MessageEntity[]? CaptionEntities { get; set; } 26 | 27 | public bool? ShowCaptionAboveMedia { get; set; } 28 | 29 | public int? Width { get; set; } 30 | 31 | public int? Height { get; set; } 32 | 33 | public int? Duration { get; set; } 34 | 35 | public bool? SupportsStreaming { get; set; } 36 | 37 | public bool? HasSpoiler { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatPermissions.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Describes actions that a non-administrator user is allowed to take in a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatPermissions 10 | { 11 | public bool? CanSendMessages { get; set; } 12 | 13 | public bool? CanSendAudios { get; set; } 14 | 15 | public bool? CanSendDocuments { get; set; } 16 | 17 | public bool? CanSendPhotos { get; set; } 18 | 19 | public bool? CanSendVideos { get; set; } 20 | 21 | public bool? CanSendVideoNotes { get; set; } 22 | 23 | public bool? CanSendVoiceNotes { get; set; } 24 | 25 | public bool? CanSendPolls { get; set; } 26 | 27 | public bool? CanSendOtherMessages { get; set; } 28 | 29 | public bool? CanAddWebPagePreviews { get; set; } 30 | 31 | public bool? CanChangeInfo { get; set; } 32 | 33 | public bool? CanInviteUsers { get; set; } 34 | 35 | public bool? CanPinMessages { get; set; } 36 | 37 | public bool? CanManageTopics { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendVideoNote.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendVideoNote() : RequestBase("sendVideoNote", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString VideoNote { get; set; } 18 | 19 | public int? Duration { get; set; } 20 | 21 | public int? Length { get; set; } 22 | 23 | public InputFileOrString? Thumbnail { get; set; } 24 | 25 | public bool? DisableNotification { get; set; } 26 | 27 | public bool? ProtectContent { get; set; } 28 | 29 | public string? MessageEffectId { get; set; } 30 | 31 | public ReplyParameters? ReplyParameters { get; set; } 32 | 33 | public ReplyMarkupBase? ReplyMarkup { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Tests/NetTelegramBotApi.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | NetTelegramBotApi 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | all 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | 16 | 17 | 18 | all 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendVoice.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendVoice() : RequestBase("sendVoice", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString Voice { get; set; } 18 | 19 | public string? Caption { get; set; } 20 | 21 | public ParseMode? ParseMode { get; set; } 22 | 23 | public MessageEntity[]? CaptionEntities { get; set; } 24 | 25 | public int? Duration { get; set; } 26 | 27 | public bool? DisableNotification { get; set; } 28 | 29 | public bool? ProtectContent { get; set; } 30 | 31 | public string? MessageEffectId { get; set; } 32 | 33 | public ReplyParameters? ReplyParameters { get; set; } 34 | 35 | public ReplyMarkupBase? ReplyMarkup { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/EditMessageText.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to edit text and game messages. 5 | /// On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. 6 | /// 7 | /// 8 | /// Note that business messages that were not sent by the bot and do not contain an inline keyboard 9 | /// can only be edited within 48 hours from the time they were sent. 10 | /// 11 | /// 12 | public class EditMessageText() : RequestBase("editMessageText") 13 | { 14 | public string? BusinessConnectionId { get; set; } 15 | 16 | public IntegerOrString? ChatId { get; set; } 17 | 18 | public long? MessageId { get; set; } 19 | 20 | public string? InlineMessageId { get; set; } 21 | 22 | public required string Text { get; set; } 23 | 24 | public ParseMode? ParseMode { get; set; } 25 | 26 | public MessageEntity[]? Entities { get; set; } 27 | 28 | public LinkPreviewOptions? LinkPreviewOptions { get; set; } 29 | 30 | public ReplyMarkupBase? ReplyMarkup { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/EditMessageCaption.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// UsUse this method to edit captions of messages. 5 | /// On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. 6 | /// 7 | /// 8 | /// Note that business messages that were not sent by the bot and do not contain an inline keyboard 9 | /// can only be edited within 48 hours from the time they were sent. 10 | /// 11 | /// 12 | public class EditMessageCaption() : RequestBase("editMessageCaption") 13 | { 14 | public string? BusinessConnectionId { get; set; } 15 | 16 | public IntegerOrString? ChatId { get; set; } 17 | 18 | public long? MessageId { get; set; } 19 | 20 | public string? InlineMessageId { get; set; } 21 | 22 | public string? Caption { get; set; } 23 | 24 | public ParseMode? ParseMode { get; set; } 25 | 26 | public MessageEntity[]? CaptionEntities { get; set; } 27 | 28 | public bool? ShowCaptionAboveMedia { get; set; } 29 | 30 | public ReplyMarkupBase? ReplyMarkup { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendDocument.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send general files. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendDocument() : RequestBase("sendDocument", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString Document { get; set; } 18 | 19 | public InputFileOrString? Thumbnail { get; set; } 20 | 21 | public string? Caption { get; set; } 22 | 23 | public ParseMode? ParseMode { get; set; } 24 | 25 | public MessageEntity[]? CaptionEntities { get; set; } 26 | 27 | public bool? DisableContentTypeDetection { get; set; } 28 | 29 | public bool? DisableNotification { get; set; } 30 | 31 | public bool? ProtectContent { get; set; } 32 | 33 | public string? MessageEffectId { get; set; } 34 | 35 | public ReplyParameters? ReplyParameters { get; set; } 36 | 37 | public ReplyMarkupBase? ReplyMarkup { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendPhoto.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send photos. On success, the sent Message is returned. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendPhoto() : RequestBase("sendPhoto", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString Photo { get; set; } 18 | 19 | public string? Caption { get; set; } 20 | 21 | public ParseMode? ParseMode { get; set; } 22 | 23 | public MessageEntity[]? CaptionEntities { get; set; } 24 | 25 | public bool? ShowCaptionAboveMedia { get; set; } 26 | 27 | public bool? HasSpoiler { get; set; } 28 | 29 | public bool? DisableNotification { get; set; } 30 | 31 | public bool? ProtectContent { get; set; } 32 | 33 | public string? MessageEffectId { get; set; } 34 | 35 | public ReplyParameters? ReplyParameters { get; set; } 36 | 37 | public ReplyMarkupBase? ReplyMarkup { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Sorry, no")] 9 | 10 | [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "I'm lazy")] 11 | 12 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "I'm lazy")] 13 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "I'm lazy")] 14 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1615:Element return value should be documented", Justification = "I'm lazy")] 15 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:Property summary documentation should match accessors", Justification = "I'm lazy")] 16 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "I'm lazy")] 17 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberRestricted.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a chat member that is under certain restrictions in the chat. Supergroups only. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberRestricted : ChatMember 10 | { 11 | public bool IsMember { get; set; } 12 | 13 | public bool CanSendMessages { get; set; } 14 | 15 | public bool CanSendAudios { get; set; } 16 | 17 | public bool CanSendDocuments { get; set; } 18 | 19 | public bool CanSendPhotos { get; set; } 20 | 21 | public bool CanSendVideos { get; set; } 22 | 23 | public bool CanSendVideoNotes { get; set; } 24 | 25 | public bool CanSendVoiceNotes { get; set; } 26 | 27 | public bool CanSendPolls { get; set; } 28 | 29 | public bool CanSendOtherMessages { get; set; } 30 | 31 | public bool CanAddWebPagePreviews { get; set; } 32 | 33 | public bool CanChangeInfo { get; set; } 34 | 35 | public bool CanInviteUsers { get; set; } 36 | 37 | public bool CanPinMessages { get; set; } 38 | 39 | public bool CanManageTopics { get; set; } 40 | 41 | public DateTimeOffset UntilDate { get; set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatMemberAdministrator.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// Represents a chat member that owns the chat and has all administrator privileges. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatMemberAdministrator : ChatMember 10 | { 11 | public bool IsAnonymous { get; set; } 12 | 13 | public bool CanBeEdited { get; set; } 14 | 15 | public bool CanManageChat { get; set; } 16 | 17 | public bool CanDeleteMessages { get; set; } 18 | 19 | public bool CanManageVideoChats { get; set; } 20 | 21 | public bool CanRestrictMembers { get; set; } 22 | 23 | public bool CanPromoteMembers { get; set; } 24 | 25 | public bool CanChangeInfo { get; set; } 26 | 27 | public bool CanInviteUsers { get; set; } 28 | 29 | public bool CanPostStories { get; set; } 30 | 31 | public bool CanEditStories { get; set; } 32 | 33 | public bool CanDeleteStories { get; set; } 34 | 35 | public bool? CanPostMessages { get; set; } 36 | 37 | public bool? CanEditMessages { get; set; } 38 | 39 | public bool? CanPinMessages { get; set; } 40 | 41 | public bool? CanManageTopics { get; set; } 42 | 43 | public string? CustomTitle { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendAudio.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send audio files, if you want Telegram clients to display them in the music player. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendAudio() : RequestBase("sendAudio", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString Audio { get; set; } 18 | 19 | public string? Caption { get; set; } 20 | 21 | public ParseMode? ParseMode { get; set; } 22 | 23 | public MessageEntity[]? CaptionEntities { get; set; } 24 | 25 | public int? Duration { get; set; } 26 | 27 | public string? Performer { get; set; } 28 | 29 | public string? Title { get; set; } 30 | 31 | public InputFileOrString? Thumbnail { get; set; } 32 | 33 | public bool? DisableNotification { get; set; } 34 | 35 | public bool? ProtectContent { get; set; } 36 | 37 | public string? MessageEffectId { get; set; } 38 | 39 | public ReplyParameters? ReplyParameters { get; set; } 40 | 41 | public ReplyMarkupBase? ReplyMarkup { get; set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /NetTelegramBotApi/InputFileOrString.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | public readonly struct InputFileOrString 4 | { 5 | public InputFileOrString(InputFile value) 6 | { 7 | ArgumentNullException.ThrowIfNull(value); 8 | this.InputFile = value; 9 | } 10 | 11 | public InputFileOrString(string value) 12 | { 13 | ArgumentException.ThrowIfNullOrWhiteSpace(value); 14 | this.String = value; 15 | } 16 | 17 | public readonly InputFile? InputFile { get; } 18 | 19 | public readonly string? String { get; } 20 | 21 | public static implicit operator InputFileOrString(InputFile value) 22 | { 23 | ArgumentNullException.ThrowIfNull(value); 24 | return new(value); 25 | } 26 | 27 | public static implicit operator InputFileOrString(FileInfo fileInfo) => new((InputFile)fileInfo); 28 | 29 | public static implicit operator InputFileOrString((Stream Content, string FileName) fileData) => new((InputFile)fileData); 30 | 31 | public static implicit operator InputFileOrString(Uri value) 32 | { 33 | ArgumentNullException.ThrowIfNull(value); 34 | return new(value.ToString()); 35 | } 36 | 37 | public static implicit operator InputFileOrString(string value) 38 | { 39 | ArgumentException.ThrowIfNullOrWhiteSpace(value); 40 | return new(value); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendAnimation.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendAnimation() : RequestBase("sendAnimation", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString Animation { get; set; } 18 | 19 | public int? Duration { get; set; } 20 | 21 | public int? Width { get; set; } 22 | 23 | public int? Height { get; set; } 24 | 25 | public InputFileOrString? Thumbnail { get; set; } 26 | 27 | public string? Caption { get; set; } 28 | 29 | public ParseMode? ParseMode { get; set; } 30 | 31 | public MessageEntity[]? CaptionEntities { get; set; } 32 | 33 | public bool? ShowCaptionAboveMedia { get; set; } 34 | 35 | public bool? HasSpoiler { get; set; } 36 | 37 | public bool? DisableNotification { get; set; } 38 | 39 | public bool? ProtectContent { get; set; } 40 | 41 | public string? MessageEffectId { get; set; } 42 | 43 | public ReplyParameters? ReplyParameters { get; set; } 44 | 45 | public ReplyMarkupBase? ReplyMarkup { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/NetTelegramBotApi.Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | all 33 | runtime; build; native; contentfiles; analyzers; buildtransitive 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Requests/SendVideo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Requests 2 | { 3 | /// 4 | /// Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class SendVideo() : RequestBase("sendVideo", true) 10 | { 11 | public string? BusinessConnectionId { get; set; } 12 | 13 | public required IntegerOrString ChatId { get; set; } 14 | 15 | public long? MessageThreadId { get; set; } 16 | 17 | public required InputFileOrString Video { get; set; } 18 | 19 | public int? Duration { get; set; } 20 | 21 | public int? Width { get; set; } 22 | 23 | public int? Height { get; set; } 24 | 25 | public InputFileOrString? Thumbnail { get; set; } 26 | 27 | public string? Caption { get; set; } 28 | 29 | public ParseMode? ParseMode { get; set; } 30 | 31 | public MessageEntity[]? CaptionEntities { get; set; } 32 | 33 | public bool? ShowCaptionAboveMedia { get; set; } 34 | 35 | public bool? HasSpoiler { get; set; } 36 | 37 | public bool? SupportsStreaming { get; set; } 38 | 39 | public bool? DisableNotification { get; set; } 40 | 41 | public bool? ProtectContent { get; set; } 42 | 43 | public string? MessageEffectId { get; set; } 44 | 45 | public ReplyParameters? ReplyParameters { get; set; } 46 | 47 | public ReplyMarkupBase? ReplyMarkup { get; set; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace System 2 | { 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | public static class StringExtensions 8 | { 9 | private static readonly char[] MarkdownV1Chars = ['\\', '_', '*', '`', '[']; 10 | 11 | private static readonly char[] MarkdownV2Chars = ['\\', '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!']; 12 | 13 | [return: NotNullIfNotNull(nameof(value))] 14 | public static string EscapeMarkdown(this string value) 15 | { 16 | return Escape(value, MarkdownV1Chars); 17 | } 18 | 19 | [return: NotNullIfNotNull(nameof(value))] 20 | public static string EscapeMarkdownV2(this string value) 21 | { 22 | return Escape(value, MarkdownV2Chars); 23 | } 24 | 25 | [return: NotNullIfNotNull(nameof(source))] 26 | private static string Escape(string source, char[] characters) 27 | { 28 | if (string.IsNullOrWhiteSpace(source)) 29 | { 30 | return source; 31 | } 32 | 33 | if (source.IndexOfAny(characters) == -1) 34 | { 35 | return source; 36 | } 37 | 38 | var sb = new StringBuilder(source.Length + 100); 39 | foreach (var c in source) 40 | { 41 | if (characters.Contains(c)) 42 | { 43 | sb.Append('\\'); 44 | } 45 | 46 | sb.Append(c); 47 | } 48 | 49 | return sb.ToString(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/MessageOriginConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | 3 | namespace NetTelegramBotApi.Util 4 | { 5 | public class MessageOriginConverter : JsonConverter 6 | { 7 | public override bool CanConvert(Type typeToConvert) 8 | { 9 | return typeToConvert == typeof(MessageOrigin); 10 | } 11 | 12 | public override MessageOrigin? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 13 | { 14 | var node = JsonNode.Parse(ref reader, new() { PropertyNameCaseInsensitive = true }); 15 | if (node == null) 16 | { 17 | return null; 18 | } 19 | 20 | var typeText = node[nameof(MessageOrigin.Type)]?.GetValue(); 21 | if (string.IsNullOrWhiteSpace(typeText)) 22 | { 23 | return null; 24 | } 25 | 26 | if (!Enum.TryParse(typeText, true, out var status)) 27 | { 28 | return null; 29 | } 30 | 31 | return status switch 32 | { 33 | MessageOriginType.User => JsonSerializer.Deserialize(node, options), 34 | MessageOriginType.HiddenUser => JsonSerializer.Deserialize(node, options), 35 | MessageOriginType.Chat => JsonSerializer.Deserialize(node, options), 36 | MessageOriginType.Channel => JsonSerializer.Deserialize(node, options), 37 | _ => JsonSerializer.Deserialize(node, options), 38 | }; 39 | } 40 | 41 | public override void Write(Utf8JsonWriter writer, MessageOrigin? value, JsonSerializerOptions options) 42 | { 43 | throw new NotImplementedException(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Update.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents an incoming update. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Update 10 | { 11 | public long UpdateId { get; set; } 12 | 13 | public Message? Message { get; set; } 14 | 15 | public Message? EditedMessage { get; set; } 16 | 17 | public Message? ChannelPost { get; set; } 18 | 19 | public Message? EditedChannelPost { get; set; } 20 | 21 | public BusinessConnection? BusinessConnection { get; set; } 22 | 23 | public Message? BusinessMessage { get; set; } 24 | 25 | public Message? EditedBusinessMessage { get; set; } 26 | 27 | public BusinessMessagesDeleted? DeletedBusinessMessages { get; set; } 28 | 29 | public MessageReactionUpdated? MessageReaction { get; set; } 30 | 31 | public MessageReactionCountUpdated? MessageReactionCount { get; set; } 32 | 33 | public InlineQuery? InlineQuery { get; set; } 34 | 35 | public ChosenInlineResult? ChosenInlineResult { get; set; } 36 | 37 | public CallbackQuery? CallbackQuery { get; set; } 38 | 39 | public ShippingQuery? ShippingQuery { get; set; } 40 | 41 | public PreCheckoutQuery? PreCheckoutQuery { get; set; } 42 | 43 | public PaidMediaPurchased? PurchasedPaidMedia { get; set; } 44 | 45 | public Poll? Poll { get; set; } 46 | 47 | public PollAnswer? PollAnswer { get; set; } 48 | 49 | public ChatMemberUpdated? MyChatMember { get; set; } 50 | 51 | public ChatMemberUpdated? ChatMember { get; set; } 52 | 53 | public ChatJoinRequest? ChatJoinRequest { get; set; } 54 | 55 | public ChatBoostUpdated? ChatBoost { get; set; } 56 | 57 | public ChatBoostRemoved? RemovedChatBoost { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Util/ChatMemberConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | 3 | namespace NetTelegramBotApi.Util 4 | { 5 | public class ChatMemberConverter : JsonConverter 6 | { 7 | public override bool CanConvert(Type typeToConvert) 8 | { 9 | return typeToConvert == typeof(ChatMember); 10 | } 11 | 12 | public override ChatMember? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 13 | { 14 | var node = JsonNode.Parse(ref reader, new() { PropertyNameCaseInsensitive = true }); 15 | if (node == null) 16 | { 17 | return null; 18 | } 19 | 20 | var statusText = node[nameof(ChatMember.Status)]?.GetValue(); 21 | if (string.IsNullOrWhiteSpace(statusText)) 22 | { 23 | return null; 24 | } 25 | 26 | if (!Enum.TryParse(statusText, true, out var status)) 27 | { 28 | return null; 29 | } 30 | 31 | return status switch 32 | { 33 | ChatMemberStatus.Creator => JsonSerializer.Deserialize(node, options), 34 | ChatMemberStatus.Administrator => JsonSerializer.Deserialize(node, options), 35 | ChatMemberStatus.Member => JsonSerializer.Deserialize(node, options), 36 | ChatMemberStatus.Restricted => JsonSerializer.Deserialize(node, options), 37 | ChatMemberStatus.Left => JsonSerializer.Deserialize(node, options), 38 | ChatMemberStatus.Kicked => JsonSerializer.Deserialize(node, options), 39 | _ => JsonSerializer.Deserialize(node, options), 40 | }; 41 | } 42 | 43 | public override void Write(Utf8JsonWriter writer, ChatMember? value, JsonSerializerOptions options) 44 | { 45 | throw new NotImplementedException(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetTelegramBotApi 2 | 3 | C# client library for building Telegram bots (https://core.telegram.org/bots/api). 4 | 5 | Contains strongly-typed request and response classes, and transport class for sending requests and receiving results. Uses `System.Text.Json` only. 6 | 7 | 8 | [![NuGet](https://img.shields.io/nuget/v/NetTelegramBotApi.svg)](https://www.nuget.org/packages/NetTelegramBotApi/) 9 | ![.NET 9.0](https://img.shields.io/badge/.NET-9.0-512BD4) 10 | ![.NET 8.0](https://img.shields.io/badge/.NET-8.0-512BD4) 11 | ![MIT License](https://img.shields.io/github/license/justdmitry/NetTelegramBotApi) 12 | 13 | ## Usage 14 | 15 | ```csharp 16 | var bot = new TelegramBot(accessToken, new HttpClient()); 17 | var me = await bot.GetMe(); 18 | if (me != null) 19 | { 20 | Console.WriteLine("Me: {0} (@{1})", me.FirstName, me.Username); 21 | } 22 | ``` 23 | 24 | See `TelegramBotDemo` project for more samples. 25 | 26 | Use with `AddHttpClient(...)` in web projects, use `Polly` (or any other you like) to handle transient faults and improve the resilience. 27 | 28 | ## Extensibility 29 | 30 | Just describe new request (or data) class: 31 | 32 | ```csharp 33 | public class PinChatMessage() : RequestBase("pinChatMessage") 34 | { 35 | public string? BusinessConnectionId { get; set; } 36 | 37 | public required IntegerOrString ChatId { get; set; } 38 | 39 | public required long MessageId { get; set; } 40 | 41 | public bool? DisableNotification { get; set; } 42 | } 43 | ``` 44 | 45 | This works out-of-the-box: 46 | 47 | * snake_case property naming (`BusinessConnectionId` -> `business_connection_id`); 48 | * `DateTimeOffset` [de]serialization of unix-time fields; 49 | * use `IntegerOrString` type for number-or-string fields (like `chat_id`); 50 | * use `InputFile` or `InputFileOrString` types for requests with files (don't forget to pass `withFiles: true` to `RequestBase`, check [`SetWebhook`](./NetTelegramBotApi/Requests/SetWebhook.cs) for example); 51 | 52 | 53 | ## Installation 54 | 55 | Use NuGet package [NetTelegramBotApi](https://www.nuget.org/packages/NetTelegramBotApi/). 56 | 57 | 58 | ## Dependencies 59 | 60 | Only `System.Text.Json`. -------------------------------------------------------------------------------- /NetTelegramBotApi/NetTelegramBotApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Telegram Bot API library 5 | NetTelegramBotApi 6 | 7.1.0 7 | net8.0;net9.0 8 | enable 9 | enable 10 | NetTelegramBotApi 11 | NetTelegramBotApi 12 | telegram;bot;api 13 | See GitHub releases. 14 | package-icon.png 15 | https://github.com/justdmitry/NetTelegramBotApi 16 | git 17 | https://github.com/justdmitry/NetTelegramBotApi.git 18 | Dmitry Popov 19 | Copyright © Dmitry Popov, 2015-2025 20 | True 21 | MIT 22 | README.md 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | all 32 | runtime; build; native; contentfiles; analyzers; buildtransitive 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | True 47 | 48 | 49 | 50 | True 51 | \ 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/ChatFullInfo.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object contains full information about a chat. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class ChatFullInfo 10 | { 11 | public long Id { get; set; } 12 | 13 | public ChatType Type { get; set; } 14 | 15 | public string? Title { get; set; } 16 | 17 | public string? Username { get; set; } 18 | 19 | public string? FirstName { get; set; } 20 | 21 | public string? LastName { get; set; } 22 | 23 | public bool? IsForum { get; set; } 24 | 25 | public int AccentColorId { get; set; } 26 | 27 | public int MaxReactionCount { get; set; } 28 | 29 | public ChatPhoto? Photo { get; set; } 30 | 31 | public string[]? ActiveUsernames { get; set; } 32 | 33 | public Birthdate? Birthdate { get; set; } 34 | 35 | public BusinessIntro? BusinessIntro { get; set; } 36 | 37 | public BusinessLocation? BusinessLocation { get; set; } 38 | 39 | public BusinessOpeningHours? BusinessOpeningHours { get; set; } 40 | 41 | public Chat? PersonalChat { get; set; } 42 | 43 | public ReactionType[]? AvailableReactions { get; set; } 44 | 45 | public string? BackgroundCustomEmojiId { get; set; } 46 | 47 | public int? ProfileAccentColorId { get; set; } 48 | 49 | public string? ProfileBackgroundCustomEmojiId { get; set; } 50 | 51 | public string? EmojiStatusCustomEmojiId { get; set; } 52 | 53 | public DateTimeOffset? EmojiStatusExpirationDate { get; set; } 54 | 55 | public string? Bio { get; set; } 56 | 57 | public bool? HasPrivateForwards { get; set; } 58 | 59 | public bool? HasRestrictedVoiceAndVideoMessages { get; set; } 60 | 61 | public bool? JoinToSendMessages { get; set; } 62 | 63 | public bool? JoinByRequest { get; set; } 64 | 65 | public string? Description { get; set; } 66 | 67 | public string? InviteLink { get; set; } 68 | 69 | public Message? PinnedMessage { get; set; } 70 | 71 | public ChatPermissions? Permissions { get; set; } 72 | 73 | public bool? CanSendPaidMedia { get; set; } 74 | 75 | public int? SlowModeDelay { get; set; } 76 | 77 | public int? UnrestrictBoostCount { get; set; } 78 | 79 | public int? MessageAutoDeleteTime { get; set; } 80 | 81 | public bool? HasAggressiveAntiSpamEnabled { get; set; } 82 | 83 | public bool? HasHiddenMembers { get; set; } 84 | 85 | public bool? HasProtectedContent { get; set; } 86 | 87 | public bool? HasVisibleHistory { get; set; } 88 | 89 | public string? StickerSetName { get; set; } 90 | 91 | public bool? CanSetStickerSet { get; set; } 92 | 93 | public string? CustomEmojiStickerSetName { get; set; } 94 | 95 | public long? LinkedChatId { get; set; } 96 | 97 | public ChatLocation? Location { get; set; } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /NetTelegramBotApi/TelegramBot.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | using NetTelegramBotApi.Util; 4 | 5 | public class TelegramBot : ITelegramBot 6 | { 7 | public static readonly JsonSerializerOptions JsonOptions = new() 8 | { 9 | PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, 10 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, 11 | Converters = 12 | { 13 | new UnixDateTimeConverter(), 14 | new IntegerOrStringConverter(), 15 | new InputFileOrStringConverter(), 16 | new ChatMemberConverter(), 17 | new MessageOriginConverter(), 18 | }, 19 | }; 20 | 21 | private readonly string accessToken; 22 | private readonly HttpClient httpClient; 23 | 24 | public TelegramBot(string accessToken, HttpClient httpClient) 25 | { 26 | ArgumentException.ThrowIfNullOrWhiteSpace(accessToken); 27 | ArgumentNullException.ThrowIfNull(httpClient); 28 | 29 | this.accessToken = accessToken; 30 | this.httpClient = httpClient; 31 | } 32 | 33 | /// 34 | /// When non-Ok response returned from server. 35 | public async Task Execute(RequestBase request, CancellationToken cancellationToken = default) 36 | { 37 | (var methodName, var content) = request.CreateHttpContent(); 38 | using (content) 39 | { 40 | var uri = new Uri($"https://api.telegram.org/bot{this.accessToken}/{methodName}"); 41 | using var response = await this.httpClient.PostAsync(uri, content, cancellationToken).ConfigureAwait(false); 42 | 43 | if ((int)response.StatusCode >= 500) 44 | { 45 | // It's server fault. Throw default exception. 46 | response.EnsureSuccessStatusCode(); 47 | } 48 | 49 | var responseText = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); 50 | var result = DeserializeMessage>(responseText); 51 | if (!response.IsSuccessStatusCode || result == null || !result.Ok || result.Result is null) 52 | { 53 | var exceptionMessage = $"Request failed ({response.StatusCode}): {responseText}"; 54 | throw new RequestFailedException(exceptionMessage) 55 | { 56 | StatusCode = response.StatusCode, 57 | ResponseBody = responseText, 58 | Description = result?.Description, 59 | ErrorCode = result?.ErrorCode, 60 | Parameters = result?.Parameters, 61 | }; 62 | } 63 | 64 | return result.Result; 65 | } 66 | } 67 | 68 | /// 69 | public Update? DeserializeUpdate(string json) 70 | { 71 | return DeserializeMessage(json); 72 | } 73 | 74 | protected static TResult? DeserializeMessage(string json) 75 | where TResult : class 76 | { 77 | return JsonSerializer.Deserialize(json, JsonOptions); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Types/Message.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Types 2 | { 3 | /// 4 | /// This object represents a message. 5 | /// 6 | /// 7 | /// 8 | /// 9 | public class Message 10 | { 11 | public long MessageId { get; set; } 12 | 13 | public long? MessageThreadId { get; set; } 14 | 15 | public User? From { get; set; } 16 | 17 | public Chat? SenderChat { get; set; } 18 | 19 | public long? SenderBoostCount { get; set; } 20 | 21 | public User? SenderBusinessBot { get; set; } 22 | 23 | public DateTimeOffset Date { get; set; } 24 | 25 | public string? BusinessConnectionId { get; set; } 26 | 27 | public Chat Chat { get; set; } = default!; 28 | 29 | public MessageOrigin? ForwardOrigin { get; set; } 30 | 31 | public bool? IsTopicMessage { get; set; } 32 | 33 | public bool? IsAutomaticForward { get; set; } 34 | 35 | public Message? ReplyToMessage { get; set; } 36 | 37 | public ExternalReplyInfo? ExternalReply { get; set; } 38 | 39 | public TextQuote? Quote { get; set; } 40 | 41 | public Story? ReplyToStory { get; set; } 42 | 43 | public User? ViaBot { get; set; } 44 | 45 | public DateTimeOffset? EditDate { get; set; } 46 | 47 | public bool? HasProtectedContent { get; set; } 48 | 49 | public bool? IsFromOffline { get; set; } 50 | 51 | public string? MediaGroupId { get; set; } 52 | 53 | public string? AuthorSignature { get; set; } 54 | 55 | public string? Text { get; set; } 56 | 57 | public MessageEntity[]? Entities { get; set; } 58 | 59 | public LinkPreviewOptions? LinkPreviewOptions { get; set; } 60 | 61 | public string? EffectId { get; set; } 62 | 63 | public Animation? Animation { get; set; } 64 | 65 | public Audio? Audio { get; set; } 66 | 67 | public Document? Document { get; set; } 68 | 69 | public PaidMediaInfo? PaidMedia { get; set; } 70 | 71 | public PhotoSize[]? Photo { get; set; } 72 | 73 | public Sticker? Sticker { get; set; } 74 | 75 | public Story? Story { get; set; } 76 | 77 | public Video? Video { get; set; } 78 | 79 | public VideoNote? VideoNote { get; set; } 80 | 81 | public Voice? Voice { get; set; } 82 | 83 | public string? Caption { get; set; } 84 | 85 | public MessageEntity[]? CaptionEntities { get; set; } 86 | 87 | public bool? ShowCaptionAboveMedia { get; set; } 88 | 89 | public bool? HasMediaSpoiler { get; set; } 90 | 91 | public Contact? Contact { get; set; } 92 | 93 | public Dice? Dice { get; set; } 94 | 95 | public Game? Game { get; set; } 96 | 97 | public Poll? Poll { get; set; } 98 | 99 | public Venue? Venue { get; set; } 100 | 101 | public Location? Location { get; set; } 102 | 103 | public User[]? NewChatMembers { get; set; } 104 | 105 | public User? LeftChatMember { get; set; } 106 | 107 | public string? NewChatTitle { get; set; } 108 | 109 | public PhotoSize[]? NewChatPhoto { get; set; } 110 | 111 | public bool? DeleteChatPhoto { get; set; } 112 | 113 | public bool? GroupChatCreated { get; set; } 114 | 115 | public bool? SupergroupChatCreated { get; set; } 116 | 117 | public bool? ChannelChatCreated { get; set; } 118 | 119 | // TODO: Add other fields 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /NetTelegramBotApi.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.11.35327.3 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ABC2A4CB-9443-434E-B2EA-E739D288F330}" 6 | ProjectSection(SolutionItems) = preProject 7 | .gitignore = .gitignore 8 | appveyor.yml = appveyor.yml 9 | NetTelegramBotApi\GlobalSuppressions.cs = NetTelegramBotApi\GlobalSuppressions.cs 10 | LICENSE = LICENSE 11 | README.md = README.md 12 | EndProjectSection 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetTelegramBotApi", "NetTelegramBotApi\NetTelegramBotApi.csproj", "{0CA802AD-0F85-4314-8D70-2C5F182C9F42}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetTelegramBotApi.Tests", "NetTelegramBotApi.Tests\NetTelegramBotApi.Tests.csproj", "{82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetTelegramBotApi.Demo", "NetTelegramBotApi.Demo\NetTelegramBotApi.Demo.csproj", "{5A74984E-48DE-4373-8738-A722D817C9C8}" 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Debug|x64 = Debug|x64 24 | Debug|x86 = Debug|x86 25 | Release|Any CPU = Release|Any CPU 26 | Release|x64 = Release|x64 27 | Release|x86 = Release|x86 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x64.ActiveCfg = Debug|Any CPU 33 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x64.Build.0 = Debug|Any CPU 34 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x86.ActiveCfg = Debug|Any CPU 35 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x86.Build.0 = Debug|Any CPU 36 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x64.ActiveCfg = Release|Any CPU 39 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x64.Build.0 = Release|Any CPU 40 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x86.ActiveCfg = Release|Any CPU 41 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x86.Build.0 = Release|Any CPU 42 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x64.ActiveCfg = Debug|Any CPU 45 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x64.Build.0 = Debug|Any CPU 46 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x86.ActiveCfg = Debug|Any CPU 47 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x86.Build.0 = Debug|Any CPU 48 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x64.ActiveCfg = Release|Any CPU 51 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x64.Build.0 = Release|Any CPU 52 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x86.ActiveCfg = Release|Any CPU 53 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x86.Build.0 = Release|Any CPU 54 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Debug|x64.ActiveCfg = Debug|Any CPU 57 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Debug|x64.Build.0 = Debug|Any CPU 58 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Debug|x86.ActiveCfg = Debug|Any CPU 59 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Debug|x86.Build.0 = Debug|Any CPU 60 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Release|x64.ActiveCfg = Release|Any CPU 63 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Release|x64.Build.0 = Release|Any CPU 64 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Release|x86.ActiveCfg = Release|Any CPU 65 | {5A74984E-48DE-4373-8738-A722D817C9C8}.Release|x86.Build.0 = Release|Any CPU 66 | EndGlobalSection 67 | GlobalSection(SolutionProperties) = preSolution 68 | HideSolutionNode = FALSE 69 | EndGlobalSection 70 | GlobalSection(ExtensibilityGlobals) = postSolution 71 | SolutionGuid = {1AE94356-8779-4DAE-A0A5-7F6DE8FC7E48} 72 | EndGlobalSection 73 | EndGlobal 74 | -------------------------------------------------------------------------------- /NetTelegramBotApi/RequestBase.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Net.Http.Json; 5 | using System.Text.Json.Nodes; 6 | 7 | public abstract class RequestBase(string methodName, bool withFiles = false) 8 | { 9 | public virtual (string Method, HttpContent Content) CreateHttpContent() 10 | { 11 | if (!withFiles) 12 | { 13 | return (methodName, JsonContent.Create(this, this.GetType(), options: TelegramBot.JsonOptions)); 14 | } 15 | 16 | var mc = new MultipartFormDataContent(); 17 | var namesToSkip = new HashSet(5); 18 | 19 | var props = this.GetType().GetProperties(); 20 | 21 | foreach (var prop in props) 22 | { 23 | if (prop.PropertyType == typeof(InputFile)) 24 | { 25 | var val = (InputFile?)prop.GetValue(this); 26 | if (val.HasValue) 27 | { 28 | var name = TelegramBot.JsonOptions.PropertyNamingPolicy!.ConvertName(prop.Name); 29 | CreateAttachment(val.Value, name, mc); 30 | namesToSkip.Add(name); 31 | } 32 | } 33 | else if (prop.PropertyType == typeof(InputFileOrString)) 34 | { 35 | var val = (InputFileOrString?)prop.GetValue(this); 36 | if (val.HasValue) 37 | { 38 | var name = TelegramBot.JsonOptions.PropertyNamingPolicy!.ConvertName(prop.Name); 39 | if (CreateAttachmentIfNeeded(val.Value, name, mc, out var newValue)) 40 | { 41 | prop.SetValue(this, newValue); 42 | } 43 | } 44 | } 45 | else if (prop.PropertyType.IsClass) 46 | { 47 | // Ideally, a recursion is needed here. 48 | // But there are no such 'deep' objects in TG (yet), so I made a simple inner loop for now. 49 | var val = prop.GetValue(this); 50 | if (val != null) 51 | { 52 | var name = TelegramBot.JsonOptions.PropertyNamingPolicy!.ConvertName(prop.Name); 53 | var innerProps = val.GetType().GetProperties(); 54 | foreach (var innerProp in innerProps.Where(x => x.PropertyType == typeof(InputFileOrString))) 55 | { 56 | var innerVal = (InputFileOrString?)innerProp.GetValue(val); 57 | if (innerVal.HasValue) 58 | { 59 | var innerName = name + "_" + TelegramBot.JsonOptions.PropertyNamingPolicy!.ConvertName(innerProp.Name); 60 | if (CreateAttachmentIfNeeded(innerVal.Value, innerName, mc, out var newValue)) 61 | { 62 | innerProp.SetValue(val, newValue); 63 | } 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | var json = JsonSerializer.Serialize(this, this.GetType(), options: TelegramBot.JsonOptions); 71 | var root = JsonNode.Parse(json)!.AsObject(); 72 | 73 | foreach (var (key, value) in root.Where(x => x.Value != null && !namesToSkip.Contains(x.Key))) 74 | { 75 | switch (value!.GetValueKind()) 76 | { 77 | case JsonValueKind.Object: 78 | case JsonValueKind.Array: 79 | mc.Add(new StringContent(value.ToJsonString()), key); 80 | break; 81 | 82 | case JsonValueKind.String: 83 | case JsonValueKind.False: 84 | case JsonValueKind.True: 85 | case JsonValueKind.Number: 86 | var sv = value.GetValue()?.ToString(); 87 | if (sv != null) 88 | { 89 | mc.Add(new StringContent(sv), key); 90 | } 91 | 92 | break; 93 | } 94 | } 95 | 96 | return (methodName, mc); 97 | } 98 | 99 | protected static void CreateAttachment(InputFile value, string propertyName, MultipartFormDataContent formContent) 100 | { 101 | // HACK, but utf-8 file names (issue #5) sent correctly now (in filename, not filename*), 102 | // thanks to http://stackoverflow.com/questions/21928982/how-to-disable-base64-encoded-filenames-in-httpclient-multipartformdatacontent 103 | var contentDispositionValue = string.Format( 104 | "form-data; name={0}; filename=\"{1}\"", 105 | propertyName, 106 | string.Concat(System.Text.Encoding.UTF8.GetBytes(value.Name).Select(x => (char)x).Where(x => x != '"'))); 107 | var fileContent = new StreamContent(value.Content); 108 | fileContent.Headers.Add("Content-Disposition", contentDispositionValue); 109 | formContent.Add(fileContent, propertyName); 110 | } 111 | 112 | protected static bool CreateAttachmentIfNeeded(InputFileOrString value, string propertyName, MultipartFormDataContent formContent, [NotNullWhen(true)] out InputFileOrString? newValue) 113 | { 114 | if (value.InputFile == null) 115 | { 116 | newValue = null; 117 | return false; 118 | } 119 | 120 | CreateAttachment(value.InputFile.Value, propertyName, formContent); 121 | 122 | newValue = new InputFileOrString("attach://" + propertyName); 123 | return true; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /NetTelegramBotApi/Extensions/TelegramBotExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi 2 | { 3 | using NetTelegramBotApi.Requests; 4 | 5 | public static class TelegramBotExtensions 6 | { 7 | public static Task GetMe(this ITelegramBot bot, CancellationToken cancellationToken = default) 8 | { 9 | return bot.Execute(new GetMe(), cancellationToken); 10 | } 11 | 12 | public static Task GetUpdates(this ITelegramBot bot, GetUpdates request, CancellationToken cancellationToken = default) 13 | { 14 | return bot.Execute(request, cancellationToken); 15 | } 16 | 17 | public static Task SetWebhook(this ITelegramBot bot, SetWebhook request, CancellationToken cancellationToken = default) 18 | { 19 | return bot.Execute(request, cancellationToken); 20 | } 21 | 22 | public static Task DeleteWebhook(this ITelegramBot bot, DeleteWebhook request, CancellationToken cancellationToken = default) 23 | { 24 | return bot.Execute(request, cancellationToken); 25 | } 26 | 27 | public static Task GetWebhookInfo(this ITelegramBot bot, CancellationToken cancellationToken = default) 28 | { 29 | return bot.Execute(new GetWebhookInfo(), cancellationToken); 30 | } 31 | 32 | public static Task ForwardMessage(this ITelegramBot bot, ForwardMessage request, CancellationToken cancellationToken = default) 33 | { 34 | return bot.Execute(request, cancellationToken); 35 | } 36 | 37 | public static Task ForwardMessages(this ITelegramBot bot, ForwardMessages request, CancellationToken cancellationToken = default) 38 | { 39 | return bot.Execute(request, cancellationToken); 40 | } 41 | 42 | public static Task SendAnimation(this ITelegramBot bot, SendAnimation request, CancellationToken cancellationToken = default) 43 | { 44 | return bot.Execute(request, cancellationToken); 45 | } 46 | 47 | public static Task SendAudio(this ITelegramBot bot, SendAudio request, CancellationToken cancellationToken = default) 48 | { 49 | return bot.Execute(request, cancellationToken); 50 | } 51 | 52 | public static Task SendChatAction(this ITelegramBot bot, SendChatAction request, CancellationToken cancellationToken = default) 53 | { 54 | return bot.Execute(request, cancellationToken); 55 | } 56 | 57 | public static Task SendDocument(this ITelegramBot bot, SendDocument request, CancellationToken cancellationToken = default) 58 | { 59 | return bot.Execute(request, cancellationToken); 60 | } 61 | 62 | public static Task SendMessage(this ITelegramBot bot, SendMessage request, CancellationToken cancellationToken = default) 63 | { 64 | return bot.Execute(request, cancellationToken); 65 | } 66 | 67 | public static Task SendPhoto(this ITelegramBot bot, SendPhoto request, CancellationToken cancellationToken = default) 68 | { 69 | return bot.Execute(request, cancellationToken); 70 | } 71 | 72 | public static Task SendVideo(this ITelegramBot bot, SendVideo request, CancellationToken cancellationToken = default) 73 | { 74 | return bot.Execute(request, cancellationToken); 75 | } 76 | 77 | public static Task SendVideoNote(this ITelegramBot bot, SendVideoNote request, CancellationToken cancellationToken = default) 78 | { 79 | return bot.Execute(request, cancellationToken); 80 | } 81 | 82 | public static Task SendVoice(this ITelegramBot bot, SendVoice request, CancellationToken cancellationToken = default) 83 | { 84 | return bot.Execute(request, cancellationToken); 85 | } 86 | 87 | public static Task PinChatMessage(this ITelegramBot bot, PinChatMessage request, CancellationToken cancellationToken = default) 88 | { 89 | return bot.Execute(request, cancellationToken); 90 | } 91 | 92 | public static Task UnpinChatMessage(this ITelegramBot bot, UnpinChatMessage request, CancellationToken cancellationToken = default) 93 | { 94 | return bot.Execute(request, cancellationToken); 95 | } 96 | 97 | public static Task UnpinAllChatMessages(this ITelegramBot bot, UnpinAllChatMessages request, CancellationToken cancellationToken = default) 98 | { 99 | return bot.Execute(request, cancellationToken); 100 | } 101 | 102 | public static Task GetChat(this ITelegramBot bot, GetChat request, CancellationToken cancellationToken = default) 103 | { 104 | return bot.Execute(request, cancellationToken); 105 | } 106 | 107 | public static Task GetChatAdministrators(this ITelegramBot bot, GetChatAdministrators request, CancellationToken cancellationToken = default) 108 | { 109 | return bot.Execute(request, cancellationToken); 110 | } 111 | 112 | public static Task GetChatMember(this ITelegramBot bot, GetChatMember request, CancellationToken cancellationToken = default) 113 | { 114 | return bot.Execute(request, cancellationToken); 115 | } 116 | 117 | public static Task GetChatMemberCount(this ITelegramBot bot, GetChatMemberCount request, CancellationToken cancellationToken = default) 118 | { 119 | return bot.Execute(request, cancellationToken); 120 | } 121 | 122 | public static Task DeleteMessage(this ITelegramBot bot, DeleteMessage request, CancellationToken cancellationToken = default) 123 | { 124 | return bot.Execute(request, cancellationToken); 125 | } 126 | 127 | public static Task DeleteMessages(this ITelegramBot bot, DeleteMessages request, CancellationToken cancellationToken = default) 128 | { 129 | return bot.Execute(request, cancellationToken); 130 | } 131 | 132 | public static Task EditMessageCaption(this ITelegramBot bot, EditMessageCaption request, CancellationToken cancellationToken = default) 133 | { 134 | return bot.Execute(request, cancellationToken); 135 | } 136 | 137 | public static Task EditMessageMedia(this ITelegramBot bot, EditMessageMedia request, CancellationToken cancellationToken = default) 138 | { 139 | return bot.Execute(request, cancellationToken); 140 | } 141 | 142 | public static Task EditMessageReplyMarkup(this ITelegramBot bot, EditMessageReplyMarkup request, CancellationToken cancellationToken = default) 143 | { 144 | return bot.Execute(request, cancellationToken); 145 | } 146 | 147 | public static Task EditMessageText(this ITelegramBot bot, EditMessageText request, CancellationToken cancellationToken = default) 148 | { 149 | return bot.Execute(request, cancellationToken); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/BotServiceHost.cs: -------------------------------------------------------------------------------- 1 | namespace NetTelegramBotApi.Demo 2 | { 3 | using System.Reflection; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using NetTelegramBotApi.Types; 9 | 10 | public class BotServiceHost(ITelegramBot bot, ILogger logger) 11 | : BackgroundService 12 | { 13 | private string uploadedPhotoId = string.Empty; 14 | private string uploadedDocumentId = string.Empty; 15 | 16 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) 17 | { 18 | var me = await bot.GetMe(stoppingToken); 19 | logger.LogInformation("Hello, I'm {Name} (@{Username})!", me.FirstName, me.Username); 20 | 21 | long offset = 0; 22 | while (!stoppingToken.IsCancellationRequested) 23 | { 24 | var updates = await bot.GetUpdates(new() { Offset = offset }, stoppingToken); 25 | if (updates == null) 26 | { 27 | continue; 28 | } 29 | 30 | foreach (var update in updates) 31 | { 32 | offset = update.UpdateId + 1; 33 | var msg = update.Message; 34 | if (msg != null) 35 | { 36 | try 37 | { 38 | await ProcessMessage(msg); 39 | } 40 | catch (RequestFailedException ex) 41 | { 42 | logger.LogError(ex, "Ooops"); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | 49 | protected async Task ProcessMessage(Message msg) 50 | { 51 | logger.LogInformation( 52 | "Msg from {Name} ({Username}) at {Date}: {Text}", 53 | msg.From?.FirstName, 54 | msg.From?.Username, 55 | msg.Date, 56 | msg.Text); 57 | 58 | if (string.IsNullOrEmpty(msg.Text)) 59 | { 60 | return; 61 | } 62 | else if (msg.Text == "/gcm") 63 | { 64 | var cm = await bot.GetChatMember(new() { ChatId = msg.Chat.Id, UserId = msg.From!.Id }); 65 | await bot.SendMessage(new() { ChatId = msg.Chat.Id, Text = $"User is {cm.Status}" }); 66 | } 67 | else if (msg.Text == "/photo") 68 | { 69 | if (string.IsNullOrEmpty(uploadedPhotoId)) 70 | { 71 | await bot.SendChatAction(new() { ChatId = msg.Chat.Id, Action = ChatAction.UploadPhoto }); 72 | await Task.Delay(500); 73 | 74 | using var photoData = typeof(Program).Assembly.GetManifestResourceStream("NetTelegramBotApi.Demo.t_logo.png"); 75 | var resp = await bot.SendPhoto(new() { ChatId = msg.Chat.Id, Photo = (photoData, "Telegram_logo.png"), Caption = "Telegram logo" }); 76 | uploadedPhotoId = resp.Photo.Last().FileId; 77 | } 78 | else 79 | { 80 | await bot.SendPhoto(new() { ChatId = msg.Chat.Id, Photo = uploadedPhotoId, Caption = "Resending photo id=" + uploadedPhotoId }); 81 | } 82 | } 83 | else if (msg.Text == "/updateMessage") 84 | { 85 | await bot.SendChatAction(new() { ChatId = msg.Chat.Id, Action = ChatAction.UploadPhoto }); 86 | await Task.Delay(500); 87 | 88 | using var photoData = typeof(Program).Assembly.GetManifestResourceStream("NetTelegramBotApi.Demo.t_logo.png")!; 89 | var resp = await bot.SendPhoto(new() { ChatId = msg.Chat.Id, Photo = (photoData, "Telegram_logo.png"), Caption = "Telegram logo" }); 90 | var firstId = resp.Photo.Last().FileId; 91 | 92 | await Task.Delay(1000); 93 | using var photoData2 = typeof(Program).Assembly.GetManifestResourceStream("NetTelegramBotApi.Demo.t_logo_180.png")!; 94 | await bot.EditMessageMedia(new() { ChatId = msg.Chat.Id, MessageId = resp.MessageId, Media = new InputMediaPhoto() { Media = (photoData2, "Telegram_logo_180.png"), Caption = "Photo updated" } }); 95 | 96 | await Task.Delay(1000); 97 | await bot.EditMessageMedia(new() { ChatId = msg.Chat.Id, MessageId = resp.MessageId, Media = new InputMediaPhoto() { Media = firstId, Caption = "Now updated back to first photo" } }); 98 | } 99 | else if (msg.Text == "/doc") 100 | { 101 | if (string.IsNullOrEmpty(uploadedDocumentId)) 102 | { 103 | await bot.SendChatAction(new() { ChatId = msg.Chat.Id, Action = ChatAction.UploadDocument }); 104 | await Task.Delay(500); 105 | 106 | using var docData = typeof(Program).GetTypeInfo().Assembly.GetManifestResourceStream("NetTelegramBotApi.Demo.Telegram_Bot_API.htm"); 107 | var resp = await bot.SendDocument(new() { ChatId = msg.Chat.Id, Document = (docData, "Telegram_Bot_API.htm"), Caption = "Here is your file" }); 108 | uploadedDocumentId = resp.Document.FileId; 109 | } 110 | else 111 | { 112 | await bot.SendDocument(new() { ChatId = msg.Chat.Id, Document = uploadedDocumentId, Caption = "Resending doc id=" + uploadedDocumentId }); 113 | } 114 | } 115 | else if (msg.Text == "/docutf8") 116 | { 117 | await bot.SendChatAction(new() { ChatId = msg.Chat.Id, Action = ChatAction.UploadDocument }); 118 | await Task.Delay(500); 119 | 120 | using var docData = typeof(Program).GetTypeInfo().Assembly.GetManifestResourceStream("NetTelegramBotApi.Demo.Пример_UTF8_filename.txt"); 121 | await bot.SendDocument(new() { ChatId = msg.Chat.Id, Document = (docData, "Пример_UTF8_filename.txt"), Caption = "Here is your file with UTF8" }); 122 | } 123 | else if (msg.Text == "/help") 124 | { 125 | var keyb = new ReplyKeyboardMarkup() 126 | { 127 | Keyboard = 128 | [ 129 | [new() { Text = "/photo" }, new() { Text = "/doc" }, new() { Text = "/longmsg" }, new() { Text = "/docutf8" }], 130 | [new() { Text = "/contact", RequestContact = true }, new() { Text = "/location", RequestLocation = true }], 131 | [new() { Text = "/help" }], 132 | ], 133 | OneTimeKeyboard = true, 134 | ResizeKeyboard = true, 135 | }; 136 | await bot.SendMessage(new() { ChatId = msg.Chat.Id, Text = "Here is all my commands", ReplyMarkup = keyb }); 137 | } 138 | else if (msg.Text == "/longmsg") 139 | { 140 | var text = new string('X', 4096 + 1); 141 | await bot.SendMessage(new() { ChatId = msg.Chat.Id, Text = text }); 142 | } 143 | else if (msg.Text == "/countdown") 144 | { 145 | var resp = await bot.SendMessage(new() { ChatId = msg.Chat.Id, Text = "Please wait..." }); 146 | var messageId = resp.MessageId; 147 | 148 | for (var i = 5; i > 0; i--) 149 | { 150 | await bot.EditMessageText(new() { ChatId = msg.Chat.Id, MessageId = messageId, Text = $"Please wait {i}..." }); 151 | await Task.Delay(1000); 152 | } 153 | 154 | await bot.EditMessageText(new() { ChatId = msg.Chat.Id, MessageId = messageId, Text = "Done. Thank you." }); 155 | await Task.Delay(1000); 156 | await bot.DeleteMessage(new() { ChatId = msg.Chat.Id, MessageId = messageId }); 157 | } 158 | else if (msg.Text.Length % 2 == 0) 159 | { 160 | await bot.SendMessage(new() 161 | { 162 | ChatId = msg.Chat.Id, 163 | Text = "You wrote: \r\n" + msg.Text.EscapeMarkdownV2(), 164 | ParseMode = ParseMode.MarkdownV2, 165 | }); 166 | } 167 | else 168 | { 169 | await bot.ForwardMessage(new() 170 | { 171 | ChatId = msg.Chat.Id, 172 | FromChatId = msg.Chat.Id, 173 | MessageId = msg.MessageId, 174 | }); 175 | } 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /NetTelegramBotApi.Demo/Telegram_Bot_API.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Telegram Bot API 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 |
20 | 35 |
36 |
37 |
38 |
39 |

Telegram Bot API

40 | 41 |
42 |

The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.
To learn how to create and set up a bot, please consult our Introduction to Bots »

43 |
44 |

Authorization
Making requests
Getting updates
Available types
Available methods

45 |

Authorizing your bot

46 |

Each bot is given a unique authentication token when it is created. The token looks something like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11, but we'll use simply <token> in this document instead. You can learn about obtaining tokens and generating new ones in this document.

47 |

Making requests

48 |

All queries to the Telegram Bot API must be served over HTTPS and need to be presented in this form: https://api.telegram.org/bot<token>/METHOD_NAME. Like this for example:

49 |
https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe
50 |

We support GET and POST HTTP methods. Use either URL query string or application/x-www-form-urlencoded or multipart/form-data for passing parameters in Bot API requests.

51 |

The response contains a JSON object, which always has a Boolean field ‘ok’ and may have an optional String field ‘description’ with a human-readable description of the result. If ‘ok’ equals true, the request was successful and the result of the query can be found in the ‘result’ field. In case of an unsuccessful request, ‘ok’ equals false and the error is explained in the ‘description’. An Integer ‘error_code’ field is also returned, but its contents are subject to change in the future.

52 |
    53 |
  • All methods in the Bot API are case-insensitive.
  • 54 |
  • All queries must be made using UTF-8.
  • 55 |
56 |

Getting updates

57 |

There are two mutually exclusive ways of receiving updates for your bot — the getUpdates method on one hand and Webhooks on the other. Incoming updates are stored on the server until the bot receives them either way, but they will not be kept longer than 24 hours.

58 |

Regardless of which option you choose, you will receive JSON-serialized Update objects as a result.

59 |

Update

60 |

This object represents an incoming update.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
FieldTypeDescription
update_idIntegerThe update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
messageMessageOptional. New incoming message of any kind — text, photo, sticker, etc.
80 |

getUpdates

81 |

Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.

82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
ParametersTypeRequiredDescription
offsetIntegerOptionalIdentifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
limitIntegerOptionalLimits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100
timeoutIntegerOptionalTimeout in seconds for long polling. Defaults to 0, i.e. usual short polling
110 |
111 |

Notes
1. This method will not work if an outgoing webhook is set up.
2. In order to avoid getting duplicate updates, recalculate offset after each server response.

112 |
113 |

setWebhook

114 |

Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.

115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 |
ParametersTypeRequiredDescription
urlStringOptionalHTTPS url to send updates to. Use an empty string to remove webhook integration
131 |
132 |

Notes
1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
2. We currently do not support self-signed certificates.
3. Ports currently supported for Webhooks: 443, 80, 88, 8443.

133 |
134 |

Available types

135 |

All types used in the Bot API responses are represented as JSON-objects.

136 | 154 |

It is safe to use 32-bit signed integers for storing all Integer fields unless otherwise noted.

155 |
156 |

Optional fields may be not returned when irrelevant.

157 |
158 |

User

159 |

This object represents a Telegram user or bot.

160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 |
FieldTypeDescription
idIntegerUnique identifier for this user or bot
first_nameStringUser‘s or bot’s first name
last_nameStringOptional. User‘s or bot’s last name
usernameStringOptional. User‘s or bot’s username
189 |

GroupChat

190 |

This object represents a group chat.

191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 |
FieldTypeDescription
idIntegerUnique identifier for this group chat
titleStringGroup name
210 |

Message

211 |

This object represents a message.

212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 |
FieldTypeDescription
message_idIntegerUnique message identifier
fromUserSender
dateIntegerDate the message was sent in Unix time
chatUser or GroupChatConversation the message belongs to — user in case of a private message, GroupChat in case of a group
forward_fromUserOptional. For forwarded messages, sender of the original message
forward_dateIntegerOptional. For forwarded messages, date the original message was sent in Unix time
reply_to_messageMessageOptional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
textStringOptional. For text messages, the actual UTF-8 text of the message
audioAudioOptional. Message is an audio file, information about the file
documentDocumentOptional. Message is a general file, information about the file
photoArray of PhotoSizeOptional. Message is a photo, available sizes of the photo
stickerStickerOptional. Message is a sticker, information about the sticker
videoVideoOptional. Message is a video, information about the video
contactContactOptional. Message is a shared contact, information about the contact
locationLocationOptional. Message is a shared location, information about the location
new_chat_participantUserOptional. A new member was added to the group, information about them (this member may be bot itself)
left_chat_participantUserOptional. A member was removed from the group, information about them (this member may be bot itself)
new_chat_titleStringOptional. A group title was changed to this value
new_chat_photoArray of PhotoSizeOptional. A group photo was change to this value
delete_chat_photoTrueOptional. Informs that the group photo was deleted
group_chat_createdTrueOptional. Informs that the group has been created
326 |

PhotoSize

327 |

This object represents one size of a photo or a file / sticker thumbnail.

328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 |
FieldTypeDescription
file_idStringUnique identifier for this file
widthIntegerPhoto width
heightIntegerPhoto height
file_sizeIntegerOptional. File size
357 |
358 |

A missing thumbnail for a file (or sticker) is presented as an empty object.

359 |
360 |

Audio

361 |

This object represents an audio file (voice note).

362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 |
FieldTypeDescription
file_idStringUnique identifier for this file
durationIntegerDuration of the audio in seconds as defined by sender
mime_typeStringOptional. MIME type of the file as defined by sender
file_sizeIntegerOptional. File size
391 |

Document

392 |

This object represents a general file (as opposed to photos and audio files).

393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 |
FieldTypeDescription
file_idStringUnique file identifier
thumbPhotoSizeDocument thumbnail as defined by sender
file_nameStringOptional. Original filename as defined by sender
mime_typeStringOptional. MIME type of the file as defined by sender
file_sizeIntegerOptional. File size
427 |

Sticker

428 |

This object represents a sticker.

429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 |
FieldTypeDescription
file_idStringUnique identifier for this file
widthIntegerSticker width
heightIntegerSticker height
thumbPhotoSizeSticker thumbnail in .webp or .jpg format
file_sizeIntegerOptional. File size
463 |

Video

464 |

This object represents a video file.

465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 |
FieldTypeDescription
file_idStringUnique identifier for this file
widthIntegerVideo width as defined by sender
heightIntegerVideo height as defined by sender
durationIntegerDuration of the video in seconds as defined by sender
thumbPhotoSizeVideo thumbnail
mime_typeStringOptional. Mime type of a file as defined by sender
file_sizeIntegerOptional. File size
captionStringOptional. Text description of the video (usually empty)
514 |

Contact

515 |

This object represents a phone contact.

516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 |
FieldTypeDescription
phone_numberStringContact's phone number
first_nameStringContact's first name
last_nameStringOptional. Contact's last name
user_idStringOptional. Contact's user identifier in Telegram
545 |

Location

546 |

This object represents a point on the map.

547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 |
FieldTypeDescription
longitudeFloatLongitude as defined by sender
latitudeFloatLatitude as defined by sender
566 |

UserProfilePhotos

567 |

This object represent a user's profile pictures.

568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 |
FieldTypeDescription
total_countIntegerTotal number of profile pictures the target user has
photosArray of Array of PhotoSizeRequested profile pictures (in up to 4 sizes each)
587 |

ReplyKeyboardMarkup

588 |

This object represents a custom keyboard with reply options (see Introduction to bots for details and examples).

589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 |
FieldTypeDescription
keyboardArray of Array of StringArray of button rows, each represented by an Array of Strings
resize_keyboardBooleanOptional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
one_time_keyboardBooleanOptional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
selectiveBooleanOptional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.

Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.
618 |

ReplyKeyboardHide

619 |

Upon receiving a message with this object, Telegram clients will hide the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).

620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 |
FieldTypeDescription
hide_keyboardTrueRequests clients to hide the custom keyboard
selectiveBooleanOptional. Use this parameter if you want to hide keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.

Example: A user votes in a poll, bot returns confirmation message in reply to the vote and hides keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
639 |

ForceReply

640 |

Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.

641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 |
FieldTypeDescription
force_replyTrueShows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'
selectiveBooleanOptional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
660 |
661 |

Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). There could be two ways to create a new poll:

662 |
663 |
    664 |
  • Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). May be appealing for hardcore users but lacks modern day polish.
  • 665 |
  • Guide the user through a step-by-step process. ‘Please send me your question’, ‘Cool, now let’s add the first answer option‘, ’Great. Keep adding answer options, then send /done when you‘re ready’.
  • 666 |
667 |

The last option is definitely more attractive. And if you use ForceReply in your bot‘s questions, it will receive the user’s answers even if it only receives replies, commands and mentions — without any extra work for the user.

668 |

InputFile

669 |

This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser.

670 |
Resending files without reuploading
671 |

There are two ways of sending a file (photo, sticker, audio etc.). If it‘s a new file, you can upload it using multipart/form-data. If the file is already on our servers, you don’t need to reupload it: each file object has a file_id field, you can simply pass this file_id as a parameter instead.

672 |
    673 |
  • It is not possible to change the file type when resending by file_id. I.e. a video can't be sent as a photo, a photo can't be sent as a document, etc.
  • 674 |
  • It is not possible to resend thumbnails.
  • 675 |
  • Resending a photo by file_id will send all of its sizes.
  • 676 |
677 |

Available methods

678 | 693 |
694 |

All methods in the Bot API are case-insensitive. We support GET and POST HTTP methods. Use either URL query string]() or application/x-www-form-urlencoded or multipart/form-data for passing parameters in Bot API requests.
On successful call, a JSON-object containing the result will be returned.

695 |
696 |

getMe

697 |

A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object.

698 |

sendMessage

699 |

Use this method to send text messages. On success, the sent Message is returned.

700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
textStringYesText of the message to be sent
disable_web_page_previewBooleanOptionalDisables link previews for links in this message
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
740 |

forwardMessage

741 |

Use this method to forward messages of any kind. On success, the sent Message is returned.

742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
from_chat_idIntegerYesUnique identifier for the chat where the original message was sent — User or GroupChat id
message_idIntegerYesUnique message identifier
770 |

sendPhoto

771 |

Use this method to send photos. On success, the sent Message is returned.

772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
photoInputFile or StringYesPhoto to send. You can either pass a file_id as String to resend a photo that is already on the Telegram servers, or upload a new photo using multipart/form-data.
captionStringOptionalPhoto caption (may also be used when resending photos by file_id).
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
812 |

sendAudio

813 |

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
audioInputFile or StringYesAudio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
848 |

sendDocument

849 |

Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.

850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
documentInputFile or StringYesFile to send. You can either pass a file_id as String to resend a file that is already on the Telegram servers, or upload a new file using multipart/form-data.
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
884 |

sendSticker

885 |

Use this method to send .webp stickers. On success, the sent Message is returned.

886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
stickerInputFile or StringYesSticker to send. You can either pass a file_id as String to resend a sticker that is already on the Telegram servers, or upload a new sticker using multipart/form-data.
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
920 |

sendVideo

921 |

Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.

922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
videoInputFile or StringYesVideo to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video file using multipart/form-data.
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
956 |

sendLocation

957 |

Use this method to send point on the map. On success, the sent Message is returned.

958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
latitudeFloat numberYesLatitude of location
longitudeFloat numberYesLongitude of location
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
reply_markupReplyKeyboardMarkup or ReplyKeyboardHide or ForceReplyOptionalAdditional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
998 |

sendChatAction

999 |

Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).

1000 |
1001 |

Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.

1002 |
1003 |

We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.

1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 |
ParametersTypeRequiredDescription
chat_idIntegerYesUnique identifier for the message recipient — User or GroupChat id
actionStringYesType of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.
1026 |

getUserProfilePhotos

1027 |

Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.

1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 |
ParametersTypeRequiredDescription
user_idIntegerYesUnique identifier of the target user
offsetIntegerOptionalSequential number of the first photo to be returned. By default, all photos are returned.
limitIntegerOptionalLimits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
1056 |
1057 | 1058 |
1059 | 1060 |
1061 |
1062 | 1121 |
1122 | 1123 | 1124 | 1132 | 1133 | 1134 | 1135 | --------------------------------------------------------------------------------