Skip to content

Commit

Permalink
Merge pull request #1359 from TelegramBots/develop
Browse files Browse the repository at this point in the history
Release v20-alpha.3
  • Loading branch information
tuscen committed Mar 3, 2024
2 parents 843756a + c939a58 commit ecd98b3
Show file tree
Hide file tree
Showing 326 changed files with 12,681 additions and 4,314 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/variables.yml
Expand Up @@ -3,7 +3,7 @@ variables:
- name: versionPrefix
value: 20.0.0
- name: versionSuffix
value: 'alpha.2'
value: 'alpha.3'
- name: ciVersionSuffix
value: ci.$(Build.BuildId)+git.commit.$(Build.SourceVersion)
- name: isPreRelease
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
@@ -1,5 +1,5 @@
ARG DOTNET_VERSION=6.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-bullseye-slim
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-bookworm-slim
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=${USER_UID}
Expand Down
22 changes: 13 additions & 9 deletions .devcontainer/devcontainer.json
Expand Up @@ -4,14 +4,18 @@
"service": "devhost",
"shutdownAction": "stopCompose",
"workspaceFolder": "/workspace",
"extensions": [
"ms-dotnettools.csharp",
"ms-azuretools.vscode-docker",
"editorconfig.editorconfig",
"eamodio.gitlens",
"tintoy.msbuild-project-tools",
"logerfo.sln-support",
"formulahendry.dotnet-test-explorer"
],
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csdevkit",
"ms-azuretools.vscode-docker",
"editorconfig.editorconfig",
"eamodio.gitlens",
"tintoy.msbuild-project-tools",
"logerfo.sln-support",
"formulahendry.dotnet-test-explorer"
]
}
},
"remoteUser": "vscode"
}
114 changes: 114 additions & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,120 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

<!-- markdownlint-configure-file { "MD024": false } -->

## [Unreleased]

> [Bot API 7.0](https://core.telegram.org/bots/api#december-29-2023) (December 29, 2023)
> [Bot API 7.1](https://core.telegram.org/bots/api#february-16-2024) (February 16, 2024)
### Added

- API methods on `ITelegramBotClient` that accept request classes with parameters
- Class `UnpinAllGeneralForumTopicMessagesRequest`
- The classes `ReactionType`, `ReactionTypeEmoji` and `ReactionTypeCustomEmoji` representing different types of reaction.
- Enum `ReactionTypeKind`
- Enum `ChatBoostSourceType`
- The class `KnownReactionTypeEmoji` containing Emojis available for `ReactionTypeEmoji`.
- Updates about a reaction change on a message with non-anonymous reactions, represented by the class `MessageReactionUpdated`
and the property `MessageReaction` in the class `Update`. The bot must explicitly allow the update to receive it.
- Updates about reaction changes on a message with anonymous reactions, represented by the class `MessageReactionCountUpdated`
and the property `MessageReactionCount` in the class `Update`. The bot must explicitly allow the update to receive it.
- New enum values `MessageReaction`, `MessageReactionCount` for `UpdateType`.
- Type `ReactionCount`.
- Request classes `SetMessageReactionRequest` that allows bots to react to messages.
- New method `ITelegramBotClient.SetMessageReactionAsync` that allows bots to react to messages.
- The property `AvailableReactions` to the class `Chat`.
- The class `ExternalReplyInfo` and the property `ExternalReply` of type `ExternalReplyInfo` to the class `Message`,
containing information about a message that is replied to by the current message, but can be from another chat or forum topic.
- The class `TextQuote` and the property `Quote` of type `TextQuote` to the class `Message`,
which contains the part of the replied message text or caption that is quoted in the current message.
- The class `ReplyParameters`.
- The class `LinkPreviewOptions`.
- The property `LinkPreviewOptions` to the class `Message` with information about the link preview options used to send the message.
- New enum value `Blockquote` for `MessageEntityType`.
- Request classes `DeleteMessagesRequest`, `ForwardMessagesRequest` and `CopyMessagesRequest`.
- New methods `ITelegramBotClient.DeleteMessagesAsync`, `ITelegramBotClient.ForwardMessagesAsync` and `ITelegramBotClient.CopyMessagesAsync`.
- Updates about chat boost changes, represented by the classes `ChatBoostUpdated` and `ChatBoostRemoved` and the properties `ChatBoost` and `RemovedChatBoost`
in the class `Update`. The bot must be an administrator in the chat to receive these updates.
- The classes `ChatBoostSourcePremium`, `ChatBoostSourceGiftCode` and `ChatBoostSourceGiveaway`, representing different sources of a chat boost.
- The method `ITelegramBotClient.GetUserChatBoostsAsync` for obtaining the list of all active boosts a user has contributed to a chat.
- Request class `GetUserChatBoostsRequest` for obtaining the list of all active boosts a user has contributed to a chat.
- The class `Giveaway` and the property `Giveaway` to the class `Message` for messages about scheduled giveaways.
- The class `GiveawayCreated` and the property `GiveawayCreated` to the class `Message` for service messages about the creation of a scheduled giveaway.
- The class `GiveawayWinners` and the property `GiveawayWinners` to the class `Message` for messages about the completion of a giveaway with public winners.
- The class `GiveawayCompleted` and the property `GiveawayCompleted` to the class `Message` for service messages about the completion of a giveaway without public winners.
- New `MessageType` enum members: `Giveaway`, `GiveawayCreated`, `GiveawayWinners` and `GiveawayCompleted`
- The properties `AccentColorId`, `BackgroundCustomEmojiId`, `ProfileAccentColorId`, and `ProfileBackgroundCustomEmojiId` to the class `Chat`.
- The property `HasVisibleHistory` to the class `Chat`.
- Classes `MaybeInaccessibleMessage` and `InaccessibleMessage`.
- The class `ChatBoostAdded`
- Classes `MessageOrigin`, `MessageOriginUser`, `MessageOriginHiddenUser` and `MessageOriginChannel`
- Enum `MessageOriginType`
- Fields `UnrestrictBoostCount` and `CustomEmojiStickerSetName` to type `Chat`
- Enum member `MessageType.BoostAdded`
- Fields `SenderBoostCount`, `ReplyToStory` and `BoostAdded` to type `Message`
- Fields `Chat` and `Id` to type `Story`

### Changed
- All required properties without setters marked as required using `required` keyword
- All non-default ctors are marked as obsolete in favor of the default ctors with object initialization syntax and required properties
- All API methods with positional parameters on `ITelegramBotClient` are marked obsolete
- Class `UnpinAllGeneralForumTopicMessages` marked as obsolete
- Replaced parameters `ReplyToMessageId` and `AllowSendingWithoutReply` with the property `ReplyParameters` of type `ReplyParameters` in the methods
- `ITelegramBotClient.CopyMessageAsync`,
- `ITelegramBotClient.SendMessageAsync`,
- `ITelegramBotClient.SendPhotoAsync`,
- `ITelegramBotClient.SendVideoAsync`,
- `ITelegramBotClient.SendAnimationAsync`,
- `ITelegramBotClient.SendAudioAsync`,
- `ITelegramBotClient.SendDocumentAsync`,
- `ITelegramBotClient.SendStickerAsync`,
- `ITelegramBotClient.SendVideoNoteAsync`,
- `ITelegramBotClient.SendVoiceAsync`,
- `ITelegramBotClient.SendLocationAsync`,
- `ITelegramBotClient.SendVenueAsync`,
- `ITelegramBotClient.SendContactAsync`,
- `ITelegramBotClient.SendPollAsync`,
- `ITelegramBotClient.SendDiceAsync`,
- `ITelegramBotClient.SendInvoiceAsync`,
- `ITelegramBotClient.SendGameAsync`,
- `ITelegramBotClient.SendMediaGroupAsync`
- Replaced properties `ReplyToMessageId` and `AllowSendingWithoutReply` with the property `ReplyParameters` of type `ReplyParameters` in the request classes
- `CopyMessageRequest`,
- `SendMessageRequest`,
- `SendPhotoRequest`,
- `SendVideoRequest`,
- `SendAnimationRequest`,
- `SendAudioRequest`,
- `SendDocumentRequest`,
- `SendStickerRequest`,
- `SendVideoNoteRequest`,
- `SendVoiceRequest`,
- `SendLocationRequest`,
- `SendVenueRequest`,
- `SendContactRequest`,
- `SendPollRequest`,
- `SendDiceRequest`,
- `SendInvoiceRequest`,
- `SendGameRequest`,
- `SendMediaGroupRequest`
- Replaced the parameter `DisableWebPagePreview` with `LinkPreviewOptions` in the methods `SendTextMessageAsync` and `EditMessageTextAsync`.
- Replaced the property `DisableWebPagePreview` with `LinkPreviewOptions` in the request classes `SendMessageRequest`, `EditMessageTextRequest`
and `EditInlineMessageTextRequest`.
- Replaced the property disable_web_page_preview with `DisableWebPagePreview` in the class `InputTextMessageContent`.
- Renamed the class `KeyboardButtonRequestUser` to `KeyboardButtonRequestUsers` and added the property `MaxQuantity` to it.
- Renamed the property `RequestUser` in the class `KeyboardButton` to `RequestUsers`. The old name will still work for backward compatibility.
- Renamed the class `UserShared` to `UsersShared` and changed the property `UserId` to `UserIds`.
- Replaced the property `UserShared` in the class Message with the property `UsersShared`.
- Replaced enum member `MessageType.UserShared` with `MessageType.UsersShared`
- Fields `ForwardFrom`, `ForwardFromChat`, `ForwardFromMessageId`, `ForwardSignature`, `ForwardSenderName`
and `ForwardDate` replaced with the field `ForwardOrigin` of type `MessageOrigin` in the class `Message`.
- Type of the property `Message` of the class `CallbackQuery` to `MaybeInaccessibleMessage`
- Type of the property `PinnedMessage` of the class `Message` to `MaybeInaccessibleMessage`.

### Removed
- Fields `ForwardFrom`, `ForwardFromChat`, `ForwardFromMessageId`, `ForwardSignature`, `ForwardSenderName`
and `ForwardDate` from type `Message`

## [v20.0.0] - Unreleased

> [Bot API 6.9](https://core.telegram.org/bots/api#september-22-2023) (September 22, 2023)
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<PreferredUILang>en</PreferredUILang>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# .NET Client for Telegram Bot API

[![package](https://img.shields.io/nuget/vpre/Telegram.Bot.svg?label=Telegram.Bot&style=flat-square)](https://www.nuget.org/packages/Telegram.Bot)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-6.9%20(September%2022,%202023)-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api#september-22-2023)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-7.1%20(February%2016,%202024)-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api#february-16-2024)
[![documentations](https://img.shields.io/badge/Documentations-Book-orange.svg?style=flat-square)](https://telegrambots.github.io/book/)
[![telegram chat](https://img.shields.io/badge/Support_Chat-Telegram-blue.svg?style=flat-square)](https://t.me/joinchat/B35YY0QbLfd034CFnvCtCA)

Expand Down
1 change: 1 addition & 0 deletions Telegram.Bot.sln
Expand Up @@ -25,6 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
.gitpod.yml = .gitpod.yml
LICENSE = LICENSE
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".azure-pipelines", ".azure-pipelines", "{71662597-40F2-4192-AC4D-5FB9A1F12642}"
Expand Down
6 changes: 3 additions & 3 deletions src/EnumSerializer.Generator/EnumSerializer.Generator.csproj
Expand Up @@ -14,10 +14,10 @@

<!-- The following libraries include the source generator interfaces and types we need -->
<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.85" PrivateAssets="all" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.141" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Scriban" Version="5.9.0" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Scriban" Version="5.9.1" GeneratePathProperty="true" PrivateAssets="all" />

<!-- This ensures the library will be packaged as a source generator when we use `dotnet pack` -->
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
Expand Down
58 changes: 58 additions & 0 deletions src/Telegram.Bot/Converters/ChatBoostSourceConverter.cs
@@ -0,0 +1,58 @@
using System.Reflection;
using Newtonsoft.Json.Linq;
using Telegram.Bot.Types.Enums;

namespace Telegram.Bot.Converters;

internal class ChatBoostSourceConverter : JsonConverter
{
static readonly TypeInfo BaseType = typeof(ChatBoostSource).GetTypeInfo();

public override bool CanWrite => false;
public override bool CanRead => true;
public override bool CanConvert(Type objectType) =>
BaseType.IsAssignableFrom(objectType.GetTypeInfo());

public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is null)
{
writer.WriteNull();
}
else
{
var jo = JObject.FromObject(value);
jo.WriteTo(writer);
}
}

public override object? ReadJson(
JsonReader reader,
Type objectType,
object? existingValue,
JsonSerializer serializer)
{
var jo = JObject.Load(reader);
var type = jo["source"]?.ToObject<ChatBoostSourceType>();

if (type is null)
{
return null;
}

var actualType = type switch
{
ChatBoostSourceType.Premium => typeof(ChatBoostSourcePremium),
ChatBoostSourceType.GiftCode => typeof(ChatBoostSourceGiftCode),
ChatBoostSourceType.Giveaway => typeof(ChatBoostSourceGiveaway),
_ => throw new JsonSerializationException($"Unknown chat boost source value of '{jo["source"]}'")
};

// Remove status because status property only has getter
jo.Remove("source");
var value = Activator.CreateInstance(actualType)!;
serializer.Populate(jo.CreateReader(), value);

return value;
}
}
4 changes: 2 additions & 2 deletions src/Telegram.Bot/Converters/InputFileConverter.cs
Expand Up @@ -32,7 +32,7 @@ public override void WriteJson(JsonWriter writer, InputFile? value, JsonSerializ
}

return Uri.TryCreate(value, UriKind.Absolute, out var url)
? new InputFileUrl(url)
: new InputFileId(value);
? InputFile.FromUri(url)
: InputFile.FromFileId(value);
}
}
54 changes: 54 additions & 0 deletions src/Telegram.Bot/Converters/MaybeInaccessibleMessageConverter.cs
@@ -0,0 +1,54 @@
using System.Reflection;
using Newtonsoft.Json.Linq;

namespace Telegram.Bot.Converters;

internal class MaybeInaccessibleMessageConverter : JsonConverter
{
static readonly TypeInfo BaseType = typeof(MaybeInaccessibleMessage).GetTypeInfo();

public override bool CanWrite => false;
public override bool CanRead => true;
public override bool CanConvert(Type objectType) =>
BaseType.IsAssignableFrom(objectType.GetTypeInfo());

public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is null)
{
writer.WriteNull();
}
else
{
var jo = JObject.FromObject(value);
jo.WriteTo(writer);
}
}

public override object? ReadJson(
JsonReader reader,
Type objectType,
object? existingValue,
JsonSerializer serializer)
{
var jo = JObject.Load(reader);
var date = jo["date"]?.Value<int>();

if (date is null)
{
return null;
}

var actualType = date switch
{
0 => typeof(InaccessibleMessage),
_ => typeof(Message),
};

// Remove status because status property only has getter
var value = Activator.CreateInstance(actualType)!;
serializer.Populate(jo.CreateReader(), value);

return value;
}
}
59 changes: 59 additions & 0 deletions src/Telegram.Bot/Converters/MessageOriginConverter.cs
@@ -0,0 +1,59 @@
using System.Reflection;
using Newtonsoft.Json.Linq;
using Telegram.Bot.Types.Enums;

namespace Telegram.Bot.Converters;

internal class MessageOriginConverter : JsonConverter
{
static readonly TypeInfo BaseType = typeof(MessageOrigin).GetTypeInfo();

public override bool CanWrite => false;
public override bool CanRead => true;
public override bool CanConvert(Type objectType) =>
BaseType.IsAssignableFrom(objectType.GetTypeInfo());

public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is null)
{
writer.WriteNull();
}
else
{
var jo = JObject.FromObject(value);
jo.WriteTo(writer);
}
}

public override object? ReadJson(
JsonReader reader,
Type objectType,
object? existingValue,
JsonSerializer serializer)
{
var jo = JObject.Load(reader);
var type = jo["type"]?.ToObject<MessageOriginType>();

if (type is null)
{
return null;
}

var actualType = type switch
{
MessageOriginType.User => typeof(MessageOriginUser),
MessageOriginType.HiddenUser => typeof(MessageOriginHiddenUser),
MessageOriginType.Chat => typeof(MessageOriginChat),
MessageOriginType.Channel => typeof(MessageOriginChannel),
_ => throw new JsonSerializationException($"Unknown message origin type value of '{jo["type"]}'")
};

// Remove status because status property only has getter
jo.Remove("type");
var value = Activator.CreateInstance(actualType)!;
serializer.Populate(jo.CreateReader(), value);

return value;
}
}

0 comments on commit ecd98b3

Please sign in to comment.