Skip to content

Commit

Permalink
feat: Update to Bot API 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Eptagone committed Nov 17, 2024
1 parent f4573df commit 5730a1b
Show file tree
Hide file tree
Showing 21 changed files with 627 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
| -------------------------------------------------- | -------------------------------- |

[![NuGet version (Telegram.BotAPI)](https://img.shields.io/nuget/v/Telegram.BotAPI?style=flat-square&logo=nuget)](https://www.nuget.org/packages/Telegram.BotAPI/)
[![Compatible with Bot API v7.11](https://img.shields.io/badge/Bot%20API%20version-v7.11-blue?style=flat-square)](https://core.telegram.org/bots/api#october-31-2024)
[![Compatible with Bot API v8.0](https://img.shields.io/badge/Bot%20API%20version-v8.0-blue?style=flat-square)](https://core.telegram.org/bots/api#november-17-2024)

**Telegram.BotAPI** is one of the most complete libraries available to interact with the Telegram Bot API in your .NET projects. It contains all the methods and types available in the Bot API 7.11 released on October 31, 2024.
**Telegram.BotAPI** is one of the most complete libraries available to interact with the Telegram Bot API in your .NET projects. It contains all the methods and types available in the Bot API 8.0 released on November 17, 2024.

[![Telegram Chat](https://img.shields.io/badge/Telegram.BotAPI%20--%20Chat-Join-blue?style=social&logo=telegram)](https://t.me/TBAPINET)

---

## Features

- Contains pre-defined methods for all Bot API 7.11 methods.
- Contains classes for each object type used in the Bot API 7.11.
- Contains pre-defined methods for all Bot API 8.0 methods.
- Contains classes for each object type used in the Bot API 8.0.
- Sync and async methods.
- Uses [System.Text.Json](https://www.nuget.org/packages/System.Text.Json/).

Expand Down
2 changes: 1 addition & 1 deletion src/examples/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Telegram.BotAPI NET Examples

[![NuGet version (Telegram.BotAPI)](https://img.shields.io/nuget/v/Telegram.BotAPI?style=flat-square&logo=nuget)](https://www.nuget.org/packages/Telegram.BotAPI/)
[![Compatible with Bot API v7.11](https://img.shields.io/badge/Bot%20API%20version-v7.11-blue?style=flat-square)](https://core.telegram.org/bots/api#october-31-2024)
[![Compatible with Bot API v8.0](https://img.shields.io/badge/Bot%20API%20version-v8.0-blue?style=flat-square)](https://core.telegram.org/bots/api#november-17-2024)

## Sample list

Expand Down
58 changes: 58 additions & 0 deletions src/library/Telegram.BotAPI/AvailableMethods/setUserEmojiStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2024 Quetzal Rivera.
// Licensed under the MIT License, See LICENCE in the project root for license information.
//* This file is auto-generated. Don't edit it manually!

namespace Telegram.BotAPI.AvailableMethods;

/// <summary>
/// Extension methods for the Telegram Bot API.
/// </summary>
public static partial class AvailableMethodsExtensions
{
/// <summary>
/// Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method <a href="https://core.telegram.org/bots/webapps#initializing-mini-apps">requestEmojiStatusAccess</a>. Returns <em>True</em> on success.
/// </summary>
/// <param name="client">The <see cref="ITelegramBotClient"/> instance.</param>
/// <param name="userId">Unique identifier of the target user</param>
/// <param name="emojiStatusCustomEmojiId">Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status.</param>
/// <param name="emojiStatusExpirationDate">Expiration date of the emoji status, if any</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> is <c>null</c>.</exception>
/// <exception cref="BotRequestException">Thrown if the request to the Telegram Bot API fails.</exception>
/// <returns></returns>
public static bool SetUserEmojiStatus(this ITelegramBotClient client, long userId, string? emojiStatusCustomEmojiId = null, int? emojiStatusExpirationDate = null) =>
client.SetUserEmojiStatusAsync(userId, emojiStatusCustomEmojiId, emojiStatusExpirationDate).GetAwaiter().GetResult();

/// <summary>
/// Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method <a href="https://core.telegram.org/bots/webapps#initializing-mini-apps">requestEmojiStatusAccess</a>. Returns <em>True</em> on success.
/// </summary>
/// <param name="client">The <see cref="ITelegramBotClient"/> instance.</param>
/// <param name="userId">Unique identifier of the target user</param>
/// <param name="emojiStatusCustomEmojiId">Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status.</param>
/// <param name="emojiStatusExpirationDate">Expiration date of the emoji status, if any</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> is <c>null</c>.</exception>
/// <exception cref="BotRequestException">Thrown if the request to the Telegram Bot API fails.</exception>
/// <returns></returns>
public static Task<bool> SetUserEmojiStatusAsync(this ITelegramBotClient client, long userId, string? emojiStatusCustomEmojiId = null, int? emojiStatusExpirationDate = null, CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}

var args = new Dictionary<string, object>()
{
{ PropertyNames.UserId, userId }
};
if (emojiStatusCustomEmojiId is not null)
{
args.Add(PropertyNames.EmojiStatusCustomEmojiId, emojiStatusCustomEmojiId);
}
if (emojiStatusExpirationDate is not null)
{
args.Add(PropertyNames.EmojiStatusExpirationDate, emojiStatusExpirationDate);
}

return client.CallMethodAsync<bool>(MethodNames.SetUserEmojiStatus, args, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2024 Quetzal Rivera.
// Licensed under the MIT License, See LICENCE in the project root for license information.
//* This file is auto-generated. Don't edit it manually!

namespace Telegram.BotAPI.InlineMode;

/// <summary>
/// Represents the arguments of the "SavePreparedInlineMessage" method.
/// </summary>
public class SavePreparedInlineMessageArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="SavePreparedInlineMessageArgs"/> class.
/// </summary>
/// <param name="userId">Unique identifier of the target user that can use the prepared message</param>
/// <param name="result">A JSON-serialized object describing the message to be sent</param>
public SavePreparedInlineMessageArgs(long userId, InlineQueryResult result)
{
this.UserId = userId;
this.Result = result ?? throw new ArgumentNullException(nameof(result));
}

/// <summary>
/// Unique identifier of the target user that can use the prepared message
/// </summary>
[JsonPropertyName(PropertyNames.UserId)]
public long UserId { get; set; }

/// <summary>
/// A JSON-serialized object describing the message to be sent
/// </summary>
[JsonPropertyName(PropertyNames.Result)]
public InlineQueryResult Result { get; set; }

/// <summary>
/// Pass <em>True</em> if the message can be sent to private chats with users
/// </summary>
[JsonPropertyName(PropertyNames.AllowUserChats)]
public bool? AllowUserChats { get; set; }

/// <summary>
/// Pass <em>True</em> if the message can be sent to private chats with bots
/// </summary>
[JsonPropertyName(PropertyNames.AllowBotChats)]
public bool? AllowBotChats { get; set; }

/// <summary>
/// Pass <em>True</em> if the message can be sent to group and supergroup chats
/// </summary>
[JsonPropertyName(PropertyNames.AllowGroupChats)]
public bool? AllowGroupChats { get; set; }

/// <summary>
/// Pass <em>True</em> if the message can be sent to channel chats
/// </summary>
[JsonPropertyName(PropertyNames.AllowChannelChats)]
public bool? AllowChannelChats { get; set; }
}
23 changes: 23 additions & 0 deletions src/library/Telegram.BotAPI/InlineMode/PreparedInlineMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2024 Quetzal Rivera.
// Licensed under the MIT License, See LICENCE in the project root for license information.
//* This file is auto-generated. Don't edit it manually!

namespace Telegram.BotAPI.InlineMode;

/// <summary>
/// Describes an inline message to be sent by a user of a Mini App.
/// </summary>
public class PreparedInlineMessage
{
/// <summary>
/// Unique identifier of the prepared message
/// </summary>
[JsonPropertyName(PropertyNames.Id)]
public string Id { get; set; } = null!;

/// <summary>
/// Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used
/// </summary>
[JsonPropertyName(PropertyNames.ExpirationDate)]
public int ExpirationDate { get; set; }
}
103 changes: 103 additions & 0 deletions src/library/Telegram.BotAPI/InlineMode/savePreparedInlineMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) 2024 Quetzal Rivera.
// Licensed under the MIT License, See LICENCE in the project root for license information.
//* This file is auto-generated. Don't edit it manually!

namespace Telegram.BotAPI.InlineMode;

/// <summary>
/// Extension methods for the Telegram Bot API.
/// </summary>
public static partial class InlineModeExtensions
{
/// <summary>
/// Stores a message that can be sent by a user of a Mini App. Returns a <see cref="PreparedInlineMessage"/> object.
/// </summary>
/// <param name="client">The <see cref="ITelegramBotClient"/> instance.</param>
/// <param name="args">The arguments for the "SavePreparedInlineMessage" method.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> is <c>null</c>.</exception>
/// <exception cref="BotRequestException">Thrown if the request to the Telegram Bot API fails.</exception>
/// <returns></returns>
public static PreparedInlineMessage SavePreparedInlineMessage(this ITelegramBotClient client, SavePreparedInlineMessageArgs args) =>
client.SavePreparedInlineMessageAsync(args).GetAwaiter().GetResult();

/// <summary>
/// Stores a message that can be sent by a user of a Mini App. Returns a <see cref="PreparedInlineMessage"/> object.
/// </summary>
/// <param name="client">The <see cref="ITelegramBotClient"/> instance.</param>
/// <param name="args">The arguments for the "SavePreparedInlineMessage" method.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> is <c>null</c>.</exception>
/// <exception cref="BotRequestException">Thrown if the request to the Telegram Bot API fails.</exception>
/// <returns></returns>
public static Task<PreparedInlineMessage> SavePreparedInlineMessageAsync(this ITelegramBotClient client, SavePreparedInlineMessageArgs args, CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}

return client.CallMethodAsync<PreparedInlineMessage>(MethodNames.SavePreparedInlineMessage, args, cancellationToken);
}

/// <summary>
/// Stores a message that can be sent by a user of a Mini App. Returns a <see cref="PreparedInlineMessage"/> object.
/// </summary>
/// <param name="client">The <see cref="ITelegramBotClient"/> instance.</param>
/// <param name="userId">Unique identifier of the target user that can use the prepared message</param>
/// <param name="result">A JSON-serialized object describing the message to be sent</param>
/// <param name="allowUserChats">Pass <em>True</em> if the message can be sent to private chats with users</param>
/// <param name="allowBotChats">Pass <em>True</em> if the message can be sent to private chats with bots</param>
/// <param name="allowGroupChats">Pass <em>True</em> if the message can be sent to group and supergroup chats</param>
/// <param name="allowChannelChats">Pass <em>True</em> if the message can be sent to channel chats</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> is <c>null</c>.</exception>
/// <exception cref="BotRequestException">Thrown if the request to the Telegram Bot API fails.</exception>
/// <returns></returns>
public static PreparedInlineMessage SavePreparedInlineMessage(this ITelegramBotClient client, long userId, InlineQueryResult result, bool? allowUserChats = null, bool? allowBotChats = null, bool? allowGroupChats = null, bool? allowChannelChats = null) =>
client.SavePreparedInlineMessageAsync(userId, result, allowUserChats, allowBotChats, allowGroupChats, allowChannelChats).GetAwaiter().GetResult();

/// <summary>
/// Stores a message that can be sent by a user of a Mini App. Returns a <see cref="PreparedInlineMessage"/> object.
/// </summary>
/// <param name="client">The <see cref="ITelegramBotClient"/> instance.</param>
/// <param name="userId">Unique identifier of the target user that can use the prepared message</param>
/// <param name="result">A JSON-serialized object describing the message to be sent</param>
/// <param name="allowUserChats">Pass <em>True</em> if the message can be sent to private chats with users</param>
/// <param name="allowBotChats">Pass <em>True</em> if the message can be sent to private chats with bots</param>
/// <param name="allowGroupChats">Pass <em>True</em> if the message can be sent to group and supergroup chats</param>
/// <param name="allowChannelChats">Pass <em>True</em> if the message can be sent to channel chats</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> is <c>null</c>.</exception>
/// <exception cref="BotRequestException">Thrown if the request to the Telegram Bot API fails.</exception>
/// <returns></returns>
public static Task<PreparedInlineMessage> SavePreparedInlineMessageAsync(this ITelegramBotClient client, long userId, InlineQueryResult result, bool? allowUserChats = null, bool? allowBotChats = null, bool? allowGroupChats = null, bool? allowChannelChats = null, CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}

var args = new Dictionary<string, object>()
{
{ PropertyNames.UserId, userId },
{ PropertyNames.Result, result ?? throw new ArgumentNullException(nameof(result)) }
};
if (allowUserChats is not null)
{
args.Add(PropertyNames.AllowUserChats, allowUserChats);
}
if (allowBotChats is not null)
{
args.Add(PropertyNames.AllowBotChats, allowBotChats);
}
if (allowGroupChats is not null)
{
args.Add(PropertyNames.AllowGroupChats, allowGroupChats);
}
if (allowChannelChats is not null)
{
args.Add(PropertyNames.AllowChannelChats, allowChannelChats);
}

return client.CallMethodAsync<PreparedInlineMessage>(MethodNames.SavePreparedInlineMessage, args, cancellationToken);
}
}
5 changes: 5 additions & 0 deletions src/library/Telegram.BotAPI/MethodNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public static partial class MethodNames
public const string EditMessageMedia = "editMessageMedia";
public const string EditMessageReplyMarkup = "editMessageReplyMarkup";
public const string EditMessageText = "editMessageText";
public const string EditUserStarSubscription = "editUserStarSubscription";
public const string ExportChatInviteLink = "exportChatInviteLink";
public const string ForwardMessage = "forwardMessage";
public const string ForwardMessages = "forwardMessages";
public const string GetAvailableGifts = "getAvailableGifts";
public const string GetBusinessConnection = "getBusinessConnection";
public const string GetChat = "getChat";
public const string GetChatAdministrators = "getChatAdministrators";
Expand Down Expand Up @@ -84,13 +86,15 @@ public static partial class MethodNames
public const string ReplaceStickerInSet = "replaceStickerInSet";
public const string RestrictChatMember = "restrictChatMember";
public const string RevokeChatInviteLink = "revokeChatInviteLink";
public const string SavePreparedInlineMessage = "savePreparedInlineMessage";
public const string SendAnimation = "sendAnimation";
public const string SendAudio = "sendAudio";
public const string SendChatAction = "sendChatAction";
public const string SendContact = "sendContact";
public const string SendDice = "sendDice";
public const string SendDocument = "sendDocument";
public const string SendGame = "sendGame";
public const string SendGift = "sendGift";
public const string SendInvoice = "sendInvoice";
public const string SendLocation = "sendLocation";
public const string SendMediaGroup = "sendMediaGroup";
Expand Down Expand Up @@ -125,6 +129,7 @@ public static partial class MethodNames
public const string SetStickerPositionInSet = "setStickerPositionInSet";
public const string SetStickerSetThumbnail = "setStickerSetThumbnail";
public const string SetStickerSetTitle = "setStickerSetTitle";
public const string SetUserEmojiStatus = "setUserEmojiStatus";
public const string SetWebhook = "setWebhook";
public const string StopMessageLiveLocation = "stopMessageLiveLocation";
public const string StopPoll = "stopPoll";
Expand Down
12 changes: 12 additions & 0 deletions src/library/Telegram.BotAPI/Payments/Args/CreateInvoiceLinkArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public CreateInvoiceLinkArgs(string title, string description, string payload, s
this.Prices = prices ?? throw new ArgumentNullException(nameof(prices));
}

/// <summary>
/// Unique identifier of the business connection on behalf of which the link will be created
/// </summary>
[JsonPropertyName(PropertyNames.BusinessConnectionId)]
public string? BusinessConnectionId { get; set; }

/// <summary>
/// Product name, 1-32 characters
/// </summary>
Expand Down Expand Up @@ -62,6 +68,12 @@ public CreateInvoiceLinkArgs(string title, string description, string payload, s
[JsonPropertyName(PropertyNames.Prices)]
public IEnumerable<LabeledPrice> Prices { get; set; }

/// <summary>
/// The number of seconds the subscription will be active for before the next payment. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified.
/// </summary>
[JsonPropertyName(PropertyNames.SubscriptionPeriod)]
public int? SubscriptionPeriod { get; set; }

/// <summary>
/// The maximum accepted amount for tips in the <em>smallest units</em> of the currency (integer, <strong>not</strong> float/double). For example, for a maximum tip of <em>US$ 1.45</em> pass <em>max_tip_amount = 145</em>. See the <em>exp</em> parameter in <a href="https://core.telegram.org/bots/payments/currencies.json">currencies.json</a>, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in <a href="https://t.me/BotNews/90">Telegram Stars</a>.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions src/library/Telegram.BotAPI/Payments/SuccessfulPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ public class SuccessfulPayment
[JsonPropertyName(PropertyNames.InvoicePayload)]
public string InvoicePayload { get; set; } = null!;

/// <summary>
/// Optional. Expiration date of the subscription, in Unix time; for recurring payments only
/// </summary>
[JsonPropertyName(PropertyNames.SubscriptionExpirationDate)]
public int? SubscriptionExpirationDate { get; set; }

/// <summary>
/// Optional. True, if the payment is a recurring payment for a subscription
/// </summary>
[JsonPropertyName(PropertyNames.IsRecurring)]
public bool? IsRecurring { get; set; }

/// <summary>
/// Optional. True, if the payment is the first payment for a subscription
/// </summary>
[JsonPropertyName(PropertyNames.IsFirstRecurring)]
public bool? IsFirstRecurring { get; set; }

/// <summary>
/// Optional. Identifier of the shipping option chosen by the user
/// </summary>
Expand Down
Loading

0 comments on commit 5730a1b

Please sign in to comment.