Skip to content

Commit

Permalink
"Deprecate AttachedFile; replace 'attachedFiles' with 'files' in all …
Browse files Browse the repository at this point in the history
…methods"
  • Loading branch information
Eptagone committed Jan 15, 2024
1 parent 1454881 commit c05a605
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 122 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ using Telegram.BotAPI.AvailableTypes;
using Telegram.BotAPI.AvailableMethods;

var file = new InputFile(filebytes, "file.zip");
var files = new AttachedFile[]
{
new AttachedFile("file56", file)
}
var files = new Dictionary<string, InputFile>() {
{ "file56", file }
};
// Upload document
api.SendDocument(chatId, "attach://file56", attachedFiles: files);
api.SendDocument(chatId, "attach://file56", files: files);
```

## Making custom requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ namespace Telegram.BotAPI.AvailableMethods;
/// <summary>
/// Defines a property to send attached files through multipart/form-data.
/// </summary>
/// <param name="attachedFiles">List of attached files to send.</param>
public abstract class AttachedFilesArgsBase(IEnumerable<AttachedFile>? attachedFiles = null)
/// <param name="files">List of attached files to send.</param>
public abstract class AttachedFilesArgsBase(IDictionary<string, InputFile>? files = null)
{
/// <summary>
/// List of files to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
/// </summary>
[JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public IEnumerable<AttachedFile> AttachedFiles { get; set; } = attachedFiles ?? new List<AttachedFile>();
[Obsolete("Use Files instead.")]
public IEnumerable<AttachedFile> AttachedFiles { get; set; } = new List<AttachedFile>();

/// <summary>
/// Files to send.
/// </summary>
[JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public IDictionary<string, InputFile> Files { get; set; } = files ?? new Dictionary<string, InputFile>();
}
24 changes: 12 additions & 12 deletions src/library/Telegram.BotAPI/Available Methods/sendAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public static Message SendAnimation(this ITelegramBotClient client, long chatId,
/// <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. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.</param>
/// <param name="attachedFiles">Attached files.</param>
/// <param name="files">Attached files.</param>
/// <exception cref="BotRequestException">Thrown when a request to Telegram Bot API got an error response.</exception>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
public static Message SendAnimation(this ITelegramBotClient client, long chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IEnumerable<AttachedFile>? attachedFiles = null)
public static Message SendAnimation(this ITelegramBotClient client, long chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IDictionary<string, InputFile>? files = null)
{
if (client is null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -125,7 +125,7 @@ public static Message SendAnimation(this ITelegramBotClient client, long chatId,
ProtectContent = protectContent,
ReplyParameters = replyParameters,
ReplyMarkup = replyMarkup,
AttachedFiles = attachedFiles ?? []
Files = files ?? new Dictionary<string, InputFile>()
};
return client.CallMethod<Message>(MethodNames.SendAnimation, args);
}
Expand Down Expand Up @@ -193,10 +193,10 @@ public static Message SendAnimation(this ITelegramBotClient client, string chatI
/// <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. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.</param>
/// <param name="attachedFiles">Attached files.</param>
/// <param name="files">Attached files.</param>
/// <exception cref="BotRequestException">Thrown when a request to Telegram Bot API got an error response.</exception>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
public static Message SendAnimation(this ITelegramBotClient client, string chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IEnumerable<AttachedFile>? attachedFiles = null)
public static Message SendAnimation(this ITelegramBotClient client, string chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IDictionary<string, InputFile>? files = null)
{
if (client is null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -215,7 +215,7 @@ public static Message SendAnimation(this ITelegramBotClient client, string chatI
ProtectContent = protectContent,
ReplyParameters = replyParameters,
ReplyMarkup = replyMarkup,
AttachedFiles = attachedFiles ?? []
Files = files ?? new Dictionary<string, InputFile>()
};
return client.CallMethod<Message>(MethodNames.SendAnimation, args);
}
Expand Down Expand Up @@ -284,11 +284,11 @@ public static async Task<Message> SendAnimationAsync(this ITelegramBotClient cli
/// <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. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.</param>
/// <param name="attachedFiles">Attached files.</param>
/// <param name="files">Attached files.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <exception cref="BotRequestException">Thrown when a request to Telegram Bot API got an error response.</exception>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
public static async Task<Message> SendAnimationAsync(this ITelegramBotClient client, long chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IEnumerable<AttachedFile>? attachedFiles = null, CancellationToken cancellationToken = default)
public static async Task<Message> SendAnimationAsync(this ITelegramBotClient client, long chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IDictionary<string, InputFile>? files = null, CancellationToken cancellationToken = default)
{
if (client is null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -307,7 +307,7 @@ public static async Task<Message> SendAnimationAsync(this ITelegramBotClient cli
ProtectContent = protectContent,
ReplyParameters = replyParameters,
ReplyMarkup = replyMarkup,
AttachedFiles = attachedFiles ?? []
Files = files ?? new Dictionary<string, InputFile>()
};
return await client.CallMethodAsync<Message>(MethodNames.SendAnimation, args, cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -376,11 +376,11 @@ public static async Task<Message> SendAnimationAsync(this ITelegramBotClient cli
/// <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. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.</param>
/// <param name="attachedFiles">Attached files.</param>
/// <param name="files">Attached files.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <exception cref="BotRequestException">Thrown when a request to Telegram Bot API got an error response.</exception>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
public static async Task<Message> SendAnimationAsync(this ITelegramBotClient client, string chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IEnumerable<AttachedFile>? attachedFiles = null, CancellationToken cancellationToken = default)
public static async Task<Message> SendAnimationAsync(this ITelegramBotClient client, string chatId, string animation, int? messageThreadId = null, uint? duration = null, uint? width = null, uint? height = null, string? thumbnail = null, string? caption = null, string? parseMode = null, IEnumerable<MessageEntity>? captionEntities = null, bool? hasSpoiler = null, bool? disableNotification = null, bool? protectContent = null, ReplyParameters? replyParameters = null, ReplyMarkup? replyMarkup = null, IDictionary<string, InputFile>? files = null, CancellationToken cancellationToken = default)
{
if (client is null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -399,7 +399,7 @@ public static async Task<Message> SendAnimationAsync(this ITelegramBotClient cli
ProtectContent = protectContent,
ReplyParameters = replyParameters,
ReplyMarkup = replyMarkup,
AttachedFiles = attachedFiles ?? []
Files = files ?? new Dictionary<string, InputFile>()
};
return await client.CallMethodAsync<Message>(MethodNames.SendAnimation, args, cancellationToken).ConfigureAwait(false);
}
Expand Down
Loading

0 comments on commit c05a605

Please sign in to comment.