-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
211 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Sources/SwiftTelegramSdk/Bot/Telegram/Methods/CreateChatSubscriptionInviteLink.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Sources/SwiftTelegramSdk/Bot/Telegram/Methods/EditChatSubscriptionInviteLink.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Sources/SwiftTelegramSdk/Bot/Telegram/Models/TGReactionTypePaid.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Sources/SwiftTelegramSdk/Bot/Telegram/Models/TGReactionTypePaidType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters