Skip to content

Commit

Permalink
Merge pull request #1393 from TelegramBots/develop
Browse files Browse the repository at this point in the history
Bot API 7.6
  • Loading branch information
wiz0u authored Jul 1, 2024
2 parents 9b2f81b + f571fcd commit 6c799fc
Show file tree
Hide file tree
Showing 31 changed files with 333 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/variables.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variables:
- group: Integration Tests Variables
- name: versionPrefix
value: 21.3.0
value: 21.4.0
- name: versionSuffix
value: ''
- name: ciVersionSuffix
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .NET Client for Telegram Bot API

[![Nuget](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fnuget.voids.site%2Fv3%2Fpackage%2FTelegram.Bot%2Findex.json&query=versions%5B-1%3A%5D&style=flat-square&label=Telegram.Bot&color=d8b541)](https://nuget.voids.site/packages/Telegram.Bot)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-7.5-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api#march-31-2024)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-7.6-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api#july-1-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)
[![Master build](https://img.shields.io/azure-devops/build/tgbots/14f9ab3f-313a-4339-8534-e8b96c7763cc/6?style=flat-square&label=master)](https://dev.azure.com/tgbots/Telegram.Bot/_build/latest?definitionId=6&branchName=master)
Expand Down
24 changes: 24 additions & 0 deletions src/Telegram.Bot/Extend.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,30 @@ public override HttpContent ToHttpContent()
}
}

public partial class SendPaidMediaRequest
{
/// <inheritdoc />
public override HttpContent ToHttpContent()
{
var multipartContent = GenerateMultipartFormDataContent();

foreach (var mediaItem in Media)
{
if (mediaItem is InputPaidMedia { Media: InputFileStream file })
{
multipartContent.AddContentIfInputFile(file, file.FileName!);
}

if (mediaItem is IInputMediaThumb { Thumbnail: InputFileStream thumbnail })
{
multipartContent.AddContentIfInputFile(thumbnail, thumbnail.FileName!);
}
}

return multipartContent;
}
}

public partial class SendPollRequest
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Telegram.Bot.Requests;

/// <summary>Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessageAsync">ForwardMessage</see>, but the copied message doesn't have a link to the original message.<para>Returns: The <see cref="MessageId"/> of the sent message on success.</para></summary>
/// <summary>Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessageAsync">ForwardMessage</see>, but the copied message doesn't have a link to the original message.<para>Returns: The <see cref="MessageId"/> of the sent message on success.</para></summary>
public partial class CopyMessageRequest : RequestBase<MessageId>, IChatTargetable
{
/// <summary>Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Telegram.Bot.Requests;

/// <summary>Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessagesAsync">ForwardMessages</see>, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages.<para>Returns: An array of <see cref="MessageId"/> of the sent messages is returned.</para></summary>
/// <summary>Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessagesAsync">ForwardMessages</see>, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages.<para>Returns: An array of <see cref="MessageId"/> of the sent messages is returned.</para></summary>
public partial class CopyMessagesRequest : RequestBase<MessageId[]>, IChatTargetable
{
/// <summary>Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Telegram.Bot.Requests;

/// <summary>Use this method to send paid media to channel chats.<para>Returns: The sent <see cref="Message"/> is returned.</para></summary>
public partial class SendPaidMediaRequest : FileRequestBase<Message>, IChatTargetable
{
/// <summary>Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required ChatId ChatId { get; set; }

/// <summary>The number of Telegram Stars that must be paid to buy access to the media</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required int StarCount { get; set; }

/// <summary>A array describing the media to be sent; up to 10 items</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required IEnumerable<InputPaidMedia> Media { get; set; }

/// <summary>Media caption, 0-1024 characters after entities parsing</summary>
public string? Caption { get; set; }

/// <summary>Mode for parsing entities in the media caption. See <a href="https://core.telegram.org/bots/api#formatting-options">formatting options</a> for more details.</summary>
public ParseMode ParseMode { get; set; }

/// <summary>A list of special entities that appear in the caption, which can be specified instead of <see cref="ParseMode">ParseMode</see></summary>
public IEnumerable<MessageEntity>? CaptionEntities { get; set; }

/// <summary>Pass <see langword="true"/>, if the caption must be shown above the message media</summary>
public bool ShowCaptionAboveMedia { get; set; }

/// <summary>Sends the message <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</summary>
public bool DisableNotification { get; set; }

/// <summary>Protects the contents of the sent message from forwarding and saving</summary>
public bool ProtectContent { get; set; }

/// <summary>Description of the message to reply to</summary>
public ReplyParameters? ReplyParameters { get; set; }

/// <summary>Additional interface options. An object for an <a href="https://core.telegram.org/bots/features#inline-keyboards">inline keyboard</a>, <a href="https://core.telegram.org/bots/features#keyboards">custom reply keyboard</a>, instructions to remove a reply keyboard or to force a reply from the user</summary>
public IReplyMarkup? ReplyMarkup { get; set; }

/// <summary>Initializes an instance of <see cref="SendPaidMediaRequest"/></summary>
/// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</param>
/// <param name="starCount">The number of Telegram Stars that must be paid to buy access to the media</param>
/// <param name="media">A array describing the media to be sent; up to 10 items</param>
[Obsolete("Use parameterless constructor with required properties")]
[SetsRequiredMembers]
public SendPaidMediaRequest(ChatId chatId, int starCount, IEnumerable<InputPaidMedia> media) : this()
{
ChatId = chatId;
StarCount = starCount;
Media = media;
}

/// <summary>Instantiates a new <see cref="SendPaidMediaRequest"/></summary>
public SendPaidMediaRequest() : base("sendPaidMedia") { }
}
48 changes: 46 additions & 2 deletions src/Telegram.Bot/TelegramBotClientExtensions.ApiMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static async Task<MessageId[]> ForwardMessagesAsync(
ProtectContent = protectContent,
}, cancellationToken).ConfigureAwait(false);

/// <summary>Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessageAsync">ForwardMessage</see>, but the copied message doesn't have a link to the original message.</summary>
/// <summary>Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessageAsync">ForwardMessage</see>, but the copied message doesn't have a link to the original message.</summary>
/// <param name="botClient">An instance of <see cref="ITelegramBotClient"/></param>
/// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</param>
/// <param name="fromChatId">Unique identifier for the chat where the original message was sent (or channel username in the format <c>@channelusername</c>)</param>
Expand Down Expand Up @@ -287,7 +287,7 @@ public static async Task<MessageId> CopyMessageAsync(
ReplyMarkup = replyMarkup,
}, cancellationToken).ConfigureAwait(false);

/// <summary>Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessagesAsync">ForwardMessages</see>, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages.</summary>
/// <summary>Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz <see cref="Poll"/> can be copied only if the value of the field <em>CorrectOptionId</em> is known to the bot. The method is analogous to the method <see cref="TelegramBotClientExtensions.ForwardMessagesAsync">ForwardMessages</see>, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages.</summary>
/// <param name="botClient">An instance of <see cref="ITelegramBotClient"/></param>
/// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</param>
/// <param name="fromChatId">Unique identifier for the chat where the original messages were sent (or channel username in the format <c>@channelusername</c>)</param>
Expand Down Expand Up @@ -719,6 +719,50 @@ public static async Task<Message> SendVideoNoteAsync(
BusinessConnectionId = businessConnectionId,
}, cancellationToken).ConfigureAwait(false);

/// <summary>Use this method to send paid media to channel chats.</summary>
/// <param name="botClient">An instance of <see cref="ITelegramBotClient"/></param>
/// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</param>
/// <param name="starCount">The number of Telegram Stars that must be paid to buy access to the media</param>
/// <param name="media">A array describing the media to be sent; up to 10 items</param>
/// <param name="caption">Media caption, 0-1024 characters after entities parsing</param>
/// <param name="parseMode">Mode for parsing entities in the media caption. See <a href="https://core.telegram.org/bots/api#formatting-options">formatting options</a> for more details.</param>
/// <param name="captionEntities">A list of special entities that appear in the caption, which can be specified instead of <paramref name="parseMode"/></param>
/// <param name="showCaptionAboveMedia">Pass <see langword="true"/>, if the caption must be shown above the message media</param>
/// <param name="disableNotification">Sends the message <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</param>
/// <param name="protectContent">Protects the contents of the sent message from forwarding and saving</param>
/// <param name="replyParameters">Description of the message to reply to</param>
/// <param name="replyMarkup">Additional interface options. An object for an <a href="https://core.telegram.org/bots/features#inline-keyboards">inline keyboard</a>, <a href="https://core.telegram.org/bots/features#keyboards">custom reply keyboard</a>, instructions to remove a reply keyboard or to force a reply from the user</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>The sent <see cref="Message"/> is returned.</returns>
public static async Task<Message> SendPaidMedia(
this ITelegramBotClient botClient,
ChatId chatId,
int starCount,
IEnumerable<InputPaidMedia> media,
string? caption = default,
ParseMode parseMode = default,
IEnumerable<MessageEntity>? captionEntities = default,
bool showCaptionAboveMedia = default,
bool disableNotification = default,
bool protectContent = default,
ReplyParameters? replyParameters = default,
IReplyMarkup? replyMarkup = default,
CancellationToken cancellationToken = default
) => await botClient.ThrowIfNull().MakeRequestAsync(new SendPaidMediaRequest
{
ChatId = chatId,
StarCount = starCount,
Media = media,
Caption = caption,
ParseMode = parseMode,
CaptionEntities = captionEntities,
ShowCaptionAboveMedia = showCaptionAboveMedia,
DisableNotification = disableNotification,
ProtectContent = protectContent,
ReplyParameters = replyParameters,
ReplyMarkup = replyMarkup,
}, cancellationToken).ConfigureAwait(false);

/// <summary>Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type.</summary>
/// <param name="botClient">An instance of <see cref="ITelegramBotClient"/></param>
/// <param name="chatId">Unique identifier for the target chat or username of the target channel (in the format <c>@channelusername</c>)</param>
Expand Down
12 changes: 6 additions & 6 deletions src/Telegram.Bot/Types/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
/// <summary>This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).</summary>
public partial class Animation : FileBase
{
/// <summary>Video width as defined by sender</summary>
/// <summary>Video width as defined by the sender</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int Width { get; set; }

/// <summary>Video height as defined by sender</summary>
/// <summary>Video height as defined by the sender</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int Height { get; set; }

/// <summary>Duration of the video in seconds as defined by sender</summary>
/// <summary>Duration of the video in seconds as defined by the sender</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int Duration { get; set; }

/// <summary><em>Optional</em>. Animation thumbnail as defined by sender</summary>
/// <summary><em>Optional</em>. Animation thumbnail as defined by the sender</summary>
public PhotoSize? Thumbnail { get; set; }

/// <summary><em>Optional</em>. Original animation filename as defined by sender</summary>
/// <summary><em>Optional</em>. Original animation filename as defined by the sender</summary>
public string? FileName { get; set; }

/// <summary><em>Optional</em>. MIME type of the file as defined by sender</summary>
/// <summary><em>Optional</em>. MIME type of the file as defined by the sender</summary>
public string? MimeType { get; set; }
}
10 changes: 5 additions & 5 deletions src/Telegram.Bot/Types/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
/// <summary>This object represents an audio file to be treated as music by the Telegram clients.</summary>
public partial class Audio : FileBase
{
/// <summary>Duration of the audio in seconds as defined by sender</summary>
/// <summary>Duration of the audio in seconds as defined by the sender</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int Duration { get; set; }

/// <summary><em>Optional</em>. Performer of the audio as defined by sender or by audio tags</summary>
/// <summary><em>Optional</em>. Performer of the audio as defined by the sender or by audio tags</summary>
public string? Performer { get; set; }

/// <summary><em>Optional</em>. Title of the audio as defined by sender or by audio tags</summary>
/// <summary><em>Optional</em>. Title of the audio as defined by the sender or by audio tags</summary>
public string? Title { get; set; }

/// <summary><em>Optional</em>. Original filename as defined by sender</summary>
/// <summary><em>Optional</em>. Original filename as defined by the sender</summary>
public string? FileName { get; set; }

/// <summary><em>Optional</em>. MIME type of the file as defined by sender</summary>
/// <summary><em>Optional</em>. MIME type of the file as defined by the sender</summary>
public string? MimeType { get; set; }

/// <summary><em>Optional</em>. Thumbnail of the album cover to which the music file belongs</summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Telegram.Bot/Types/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public partial class ChatFullInfo : Chat
/// <summary><em>Optional</em>. Default chat member permissions, for groups and supergroups</summary>
public ChatPermissions? Permissions { get; set; }

/// <summary><em>Optional</em>. <see langword="true"/>, if paid media messages can be sent or forwarded to the channel chat. The field is available only for channel chats.</summary>
public bool CanSendPaidMedia { get; set; }

/// <summary><em>Optional</em>. For supergroups, the minimum allowed delay between consecutive messages sent by each unprivileged user; in seconds</summary>
public int? SlowModeDelay { get; set; }

Expand Down
Loading

0 comments on commit 6c799fc

Please sign in to comment.