Skip to content

Commit

Permalink
Bot API 7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz0u committed Jul 1, 2024
1 parent b3ec8d0 commit a003047
Show file tree
Hide file tree
Showing 28 changed files with 330 additions and 47 deletions.
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
6 changes: 3 additions & 3 deletions src/Telegram.Bot/Types/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
/// <summary>This object represents a general file (as opposed to <see cref="PhotoSize">photos</see>, <see cref="Voice">voice messages</see> and <see cref="Audio">audio files</see>).</summary>
public partial class Document : FileBase
{
/// <summary><em>Optional</em>. Document thumbnail as defined by sender</summary>
/// <summary><em>Optional</em>. Document thumbnail as defined by the sender</summary>
public PhotoSize? Thumbnail { 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; }
}
11 changes: 11 additions & 0 deletions src/Telegram.Bot/Types/Enums/InputPaidMediaType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Telegram.Bot.Types.Enums;

/// <summary>Type of the media</summary>
[JsonConverter(typeof(InputPaidMediaTypeConverter))]
public enum InputPaidMediaType
{
/// <summary>The paid media to send is a photo.<br/><br/><i>(<see cref="InputPaidMedia"/> can be cast into <see cref="InputPaidMediaPhoto"/>)</i></summary>
Photo = 1,
/// <summary>The paid media to send is a video.<br/><br/><i>(<see cref="InputPaidMedia"/> can be cast into <see cref="InputPaidMediaVideo"/>)</i></summary>
Video,
}
2 changes: 2 additions & 0 deletions src/Telegram.Bot/Types/Enums/MessageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public enum MessageType
BoostAdded,
/// <summary>The <see cref="Message"/> contains a <see cref="Message.ChatBackgroundSet"/></summary>
ChatBackgroundSet,
/// <summary>The <see cref="Message"/> contains a <see cref="Message.PaidMedia"/></summary>
PaidMedia,

#pragma warning disable CS1591
WebsiteConnected = ConnectedWebsite,
Expand Down
Loading

0 comments on commit a003047

Please sign in to comment.