Skip to content

Commit

Permalink
Bot API 7.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Aug 14, 2024
1 parent 6d069ba commit 1ab285e
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 15 deletions.
10 changes: 10 additions & 0 deletions Sources/SwiftTelegramSdk/Bot/TGBotPrtcl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ public protocol TGBotPrtcl {



@discardableResult
func createChatSubscriptionInviteLink(params: TGCreateChatSubscriptionInviteLinkParams) async throws -> Bool



@discardableResult
func editChatSubscriptionInviteLink(params: TGEditChatSubscriptionInviteLinkParams) async throws -> Bool



@discardableResult
func revokeChatInviteLink(params: TGRevokeChatInviteLinkParams) async throws -> Bool

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Swift Telegram SDK - Telegram Bot Swift SDK.

import Foundation

/// DESCRIPTION:
/// Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.


/// Parameters container struct for `createChatSubscriptionInviteLink` method
public struct TGCreateChatSubscriptionInviteLinkParams: Encodable {

/// Unique identifier for the target channel chat or username of the target channel (in the format @channelusername)
public var chatId: TGChatId

/// Invite link name; 0-32 characters
public var name: String?

/// The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days).
public var subscriptionPeriod: Int

/// The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500
public var subscriptionPrice: Int

/// Custom keys for coding/decoding `CreateChatSubscriptionInviteLinkParams` struct
public enum CodingKeys: String, CodingKey {
case chatId = "chat_id"
case name = "name"
case subscriptionPeriod = "subscription_period"
case subscriptionPrice = "subscription_price"
}

public init(chatId: TGChatId, name: String? = nil, subscriptionPeriod: Int, subscriptionPrice: Int) {
self.chatId = chatId
self.name = name
self.subscriptionPeriod = subscriptionPeriod
self.subscriptionPrice = subscriptionPrice
}
}


public extension TGBot {

/**
Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
SeeAlso Telegram Bot API Reference:
[CreateChatSubscriptionInviteLinkParams](https://core.telegram.org/bots/api#createchatsubscriptioninvitelink)
- Parameters:
- params: Parameters container, see `CreateChatSubscriptionInviteLinkParams` struct
- Throws: Throws on errors
- Returns: `Bool`
*/

@discardableResult
func createChatSubscriptionInviteLink(params: TGCreateChatSubscriptionInviteLinkParams) async throws -> Bool {
guard let methodURL: URL = .init(string: getMethodURL("createChatSubscriptionInviteLink")) else {
throw BotError("Bad URL: \(getMethodURL("createChatSubscriptionInviteLink"))")
}
let result: Bool = try await tgClient.post(methodURL, params: params, as: nil)
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Swift Telegram SDK - Telegram Bot Swift SDK.

import Foundation

/// DESCRIPTION:
/// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.


/// Parameters container struct for `editChatSubscriptionInviteLink` method
public struct TGEditChatSubscriptionInviteLinkParams: Encodable {

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
public var chatId: TGChatId

/// The invite link to edit
public var inviteLink: String

/// Invite link name; 0-32 characters
public var name: String?

/// Custom keys for coding/decoding `EditChatSubscriptionInviteLinkParams` struct
public enum CodingKeys: String, CodingKey {
case chatId = "chat_id"
case inviteLink = "invite_link"
case name = "name"
}

public init(chatId: TGChatId, inviteLink: String, name: String? = nil) {
self.chatId = chatId
self.inviteLink = inviteLink
self.name = name
}
}


public extension TGBot {

/**
Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
SeeAlso Telegram Bot API Reference:
[EditChatSubscriptionInviteLinkParams](https://core.telegram.org/bots/api#editchatsubscriptioninvitelink)
- Parameters:
- params: Parameters container, see `EditChatSubscriptionInviteLinkParams` struct
- Throws: Throws on errors
- Returns: `Bool`
*/

@discardableResult
func editChatSubscriptionInviteLink(params: TGEditChatSubscriptionInviteLinkParams) async throws -> Bool {
guard let methodURL: URL = .init(string: getMethodURL("editChatSubscriptionInviteLink")) else {
throw BotError("Bad URL: \(getMethodURL("editChatSubscriptionInviteLink"))")
}
let result: Bool = try await tgClient.post(methodURL, params: params, as: nil)
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation

/// DESCRIPTION:
/// Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
/// Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.


/// Parameters container struct for `editForumTopic` method
Expand Down Expand Up @@ -41,7 +41,7 @@ public struct TGEditForumTopicParams: Encodable {
public extension TGBot {

/**
Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
SeeAlso Telegram Bot API Reference:
[EditForumTopicParams](https://core.telegram.org/bots/api#editforumtopic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation

/// DESCRIPTION:
/// Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
/// Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.


/// Parameters container struct for `editGeneralForumTopic` method
Expand Down Expand Up @@ -31,7 +31,7 @@ public struct TGEditGeneralForumTopicParams: Encodable {
public extension TGBot {

/**
Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
SeeAlso Telegram Bot API Reference:
[EditGeneralForumTopicParams](https://core.telegram.org/bots/api#editgeneralforumtopic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import Foundation

/// DESCRIPTION:
/// Use this method to send paid media to channel chats. On success, the sent Message is returned.
/// Use this method to send paid media. On success, the sent Message is returned.


/// Parameters container struct for `sendPaidMedia` method
public struct TGSendPaidMediaParams: Encodable {

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
/// Unique identifier of the business connection on behalf of which the message will be sent
public var businessConnectionId: String?

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername). If the chat is a channel, all Telegram Star proceeds from this media will be credited to the chat's balance. Otherwise, they will be credited to the bot's balance.
public var chatId: TGChatId

/// The number of Telegram Stars that must be paid to buy access to the media
Expand Down Expand Up @@ -44,6 +47,7 @@ public struct TGSendPaidMediaParams: Encodable {

/// Custom keys for coding/decoding `SendPaidMediaParams` struct
public enum CodingKeys: String, CodingKey {
case businessConnectionId = "business_connection_id"
case chatId = "chat_id"
case starCount = "star_count"
case media = "media"
Expand All @@ -57,7 +61,8 @@ public struct TGSendPaidMediaParams: Encodable {
case replyMarkup = "reply_markup"
}

public init(chatId: TGChatId, starCount: Int, media: [TGInputPaidMedia], caption: String? = nil, parseMode: TGParseMode? = nil, captionEntities: [TGMessageEntity]? = nil, showCaptionAboveMedia: Bool? = nil, disableNotification: Bool? = nil, protectContent: Bool? = nil, replyParameters: TGReplyParameters? = nil, replyMarkup: TGReplyMarkup? = nil) {
public init(businessConnectionId: String? = nil, chatId: TGChatId, starCount: Int, media: [TGInputPaidMedia], caption: String? = nil, parseMode: TGParseMode? = nil, captionEntities: [TGMessageEntity]? = nil, showCaptionAboveMedia: Bool? = nil, disableNotification: Bool? = nil, protectContent: Bool? = nil, replyParameters: TGReplyParameters? = nil, replyMarkup: TGReplyMarkup? = nil) {
self.businessConnectionId = businessConnectionId
self.chatId = chatId
self.starCount = starCount
self.media = media
Expand All @@ -76,7 +81,7 @@ public struct TGSendPaidMediaParams: Encodable {
public extension TGBot {

/**
Use this method to send paid media to channel chats. On success, the sent Message is returned.
Use this method to send paid media. On success, the sent Message is returned.
SeeAlso Telegram Bot API Reference:
[SendPaidMediaParams](https://core.telegram.org/bots/api#sendpaidmedia)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation

/// DESCRIPTION:
/// Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Returns True on success.
/// Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.


/// Parameters container struct for `setMessageReaction` method
Expand All @@ -15,7 +15,7 @@ public struct TGSetMessageReactionParams: Encodable {
/// Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.
public var messageId: Int

/// A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.
/// A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
public var reaction: [TGReactionType]?

/// Pass True to set the reaction with a big animation
Expand All @@ -41,7 +41,7 @@ public struct TGSetMessageReactionParams: Encodable {
public extension TGBot {

/**
Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Returns True on success.
Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
SeeAlso Telegram Bot API Reference:
[SetMessageReactionParams](https://core.telegram.org/bots/api#setmessagereaction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public final class TGChatMemberMember: Codable {
public enum CodingKeys: String, CodingKey {
case status = "status"
case user = "user"
case untilDate = "until_date"
}

/// The member's status in the chat, always “member”
Expand All @@ -20,8 +21,12 @@ public final class TGChatMemberMember: Codable {
/// Information about the user
public var user: TGUser

public init (status: String, user: TGUser) {
/// Optional. Date when the user's subscription will expire; Unix time
public var untilDate: Int?

public init (status: String, user: TGUser, untilDate: Int? = nil) {
self.status = status
self.user = user
self.untilDate = untilDate
}
}
4 changes: 2 additions & 2 deletions Sources/SwiftTelegramSdk/Bot/Telegram/Models/TGMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public final class TGMessage: Codable {
/// Optional. Unique identifier of a message thread to which the message belongs; for supergroups only
public var messageThreadId: Int?

/// Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
/// Optional. Sender of the message; may be empty for messages sent to channels. For backward compatibility, if the message was sent on behalf of a chat, the field contains a fake sender user in non-channel chats
public var from: TGUser?

/// Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
/// Optional. Sender of the message when sent on behalf of a chat. For example, the supergroup itself for messages sent by its anonymous administrators or a linked channel for messages automatically forwarded to the channel's discussion group. For backward compatibility, if the message was sent on behalf of a chat, the field from contains a fake sender user in non-channel chats.
public var senderChat: TGChat?

/// Optional. If the sender of the message boosted the chat, the number of boosts added by the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
This object describes the type of a reaction. Currently, it can be one of
ReactionTypeEmoji
ReactionTypeCustomEmoji
ReactionTypePaid
SeeAlso Telegram Bot API Reference:
[ReactionType](https://core.telegram.org/bots/api#reactiontype)
**/
public enum TGReactionType: Codable {
case reactionTypeEmoji(TGReactionTypeEmoji)
case reactionTypeCustomEmoji(TGReactionTypeCustomEmoji)
case reactionTypePaid(TGReactionTypePaid)

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let value = try? container.decode(TGReactionTypeEmoji.self) {
self = .reactionTypeEmoji(value)
} else if let value = try? container.decode(TGReactionTypeCustomEmoji.self) {
self = .reactionTypeCustomEmoji(value)
} else if let value = try? container.decode(TGReactionTypePaid.self) {
self = .reactionTypePaid(value)
} else {
throw BotError("Failed! Can't decode ANY_TYPE ReactionType.")
}
Expand All @@ -30,6 +34,8 @@ public enum TGReactionType: Codable {
try container.encode(value)
case let .reactionTypeCustomEmoji(value):
try container.encode(value)
case let .reactionTypePaid(value):
try container.encode(value)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Swift Telegram SDK - Telegram Bot Swift SDK.

/**
The reaction is paid.
SeeAlso Telegram Bot API Reference:
[ReactionTypePaid](https://core.telegram.org/bots/api#reactiontypepaid)
**/
public final class TGReactionTypePaid: Codable {

/// Custom keys for coding/decoding `ReactionTypePaid` struct
public enum CodingKeys: String, CodingKey {
case type = "type"
}

/// Type of the reaction, always “paid”
public var type: TGReactionTypePaidType

public init (type: TGReactionTypePaidType) {
self.type = type
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Swift Telegram SDK - Telegram Bot Swift SDK.

/**
The reaction is paid.
SeeAlso Telegram Bot API Reference:
[ReactionTypePaid](https://core.telegram.org/bots/api#reactiontypepaid)
*/

public enum TGReactionTypePaidType: String, Codable {
case paid = "paid"
case undefined

public init(from decoder: Decoder) throws {
let value = try decoder.singleValueContainer().decode(String.self)
guard let type = TGReactionTypePaidType(rawValue: value) else {
self = .undefined
return
}
self = type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class TGTransactionPartnerUser: Codable {
case type = "type"
case user = "user"
case invoicePayload = "invoice_payload"
case paidMedia = "paid_media"
}

/// Type of the transaction partner, always “user”
Expand All @@ -24,9 +25,13 @@ public final class TGTransactionPartnerUser: Codable {
/// Optional. Bot-specified invoice payload
public var invoicePayload: String?

public init (type: TGTransactionPartnerUserType, user: TGUser, invoicePayload: String? = nil) {
/// Optional. Information about the paid media bought by the user
public var paidMedia: [TGPaidMedia]?

public init (type: TGTransactionPartnerUserType, user: TGUser, invoicePayload: String? = nil, paidMedia: [TGPaidMedia]? = nil) {
self.type = type
self.user = user
self.invoicePayload = invoicePayload
self.paidMedia = paidMedia
}
}

0 comments on commit 1ab285e

Please sign in to comment.