├── Api ├── Gemfile └── start.rb ├── .gitignore ├── Sources └── SwiftTelegramBot │ └── Bot │ ├── Helpers │ ├── Extensions │ │ └── Array+RemoveHandler.swift │ └── SendableValue.swift │ ├── Telegram │ ├── Models │ │ ├── TGCallbackGame.swift │ │ ├── TGForumTopicClosed.swift │ │ ├── TGVideoChatStarted.swift │ │ ├── TGForumTopicReopened.swift │ │ ├── TGGeneralForumTopicHidden.swift │ │ ├── TGGeneralForumTopicUnhidden.swift │ │ ├── TGBotName.swift │ │ ├── TGGifts.swift │ │ ├── TGChatBackground.swift │ │ ├── TGWebAppInfo.swift │ │ ├── TGReactionTypePaid.swift │ │ ├── TGPaidMediaPhotoType.swift │ │ ├── TGPaidMediaVideoType.swift │ │ ├── TGPollType.swift │ │ ├── TGBotDescription.swift │ │ ├── TGReactionTypePaidType.swift │ │ ├── TGInputMediaPhotoType.swift │ │ ├── TGInputMediaVideoType.swift │ │ ├── TGInlineQueryResultGameType.swift │ │ ├── TGReactionTypeEmojiType.swift │ │ ├── TGVideoChatEnded.swift │ │ ├── TGChatBoostAdded.swift │ │ ├── TGInputMediaDocumentType.swift │ │ ├── TGInputPaidMediaPhotoType.swift │ │ ├── TGInputPaidMediaVideoType.swift │ │ ├── TGMessageOriginUserType.swift │ │ ├── TGUserChatBoosts.swift │ │ ├── TGInputMediaAudioType.swift │ │ ├── TGMenuButtonDefault.swift │ │ ├── TGMenuButtonWebAppType.swift │ │ ├── TGOwnedGiftRegularType.swift │ │ ├── TGPaidMediaPreviewType.swift │ │ ├── TGCopyTextButton.swift │ │ ├── TGOwnedGiftUniqueType.swift │ │ ├── TGStickerType.swift │ │ ├── TGBackgroundFillSolidType.swift │ │ ├── TGInputStoryContentPhotoType.swift │ │ ├── TGInputStoryContentVideoType.swift │ │ ├── TGStarTransactions.swift │ │ ├── TGTransactionPartnerChatType.swift │ │ ├── TGTransactionPartnerUserType.swift │ │ ├── TGBackgroundFillGradientType.swift │ │ ├── TGMenuButtonCommands.swift │ │ ├── TGMenuButtonDefaultType.swift │ │ ├── TGMessageOriginChatType.swift │ │ ├── TGBackgroundTypeFillType.swift │ │ ├── TGBotCommandScopeChatType.swift │ │ ├── TGMessageOriginChannelType.swift │ │ ├── TGChatType.swift │ │ ├── TGInputProfilePhotoStaticType.swift │ │ ├── TGMenuButtonCommandsType.swift │ │ ├── TGStory.swift │ │ ├── TGInlineQueryResultArticleType.swift │ │ ├── TGReactionTypeCustomEmojiType.swift │ │ ├── TGBackgroundTypeWallpaperType.swift │ │ ├── TGBotShortDescription.swift │ │ ├── TGInputProfilePhotoAnimatedType.swift │ │ ├── TGMessageOriginHiddenUserType.swift │ │ ├── TGTransactionPartnerOtherType.swift │ │ ├── TGRevenueWithdrawalStatePendingType.swift │ │ ├── TGBackgroundTypeChatThemeType.swift │ │ ├── TGRevenueWithdrawalStateSucceededType.swift │ │ ├── TGStoryAreaTypeLinkType.swift │ │ ├── TGTransactionPartnerFragmentType.swift │ │ ├── TGInputMediaAnimationType.swift │ │ ├── TGRevenueWithdrawalStatePending.swift │ │ ├── TGTransactionPartnerOther.swift │ │ ├── TGRevenueWithdrawalStateFailedType.swift │ │ ├── TGVideoChatParticipantsInvited.swift │ │ ├── TGRevenueWithdrawalStateFailed.swift │ │ ├── TGStoryAreaTypeLocationType.swift │ │ ├── TGStoryAreaTypeWeatherType.swift │ │ ├── TGTransactionPartnerTelegramApiType.swift │ │ ├── TGChatFullInfoType.swift │ │ ├── TGTransactionPartnerTelegramAdsType.swift │ │ ├── TGVideoChatScheduled.swift │ │ ├── TGBotCommandScopeAllGroupChats.swift │ │ ├── TGBotCommandScopeChatMemberType.swift │ │ ├── TGPaidMediaVideo.swift │ │ ├── TGStoryAreaTypeUniqueGiftType.swift │ │ ├── TGBotCommandScopeAllGroupChatsType.swift │ │ ├── TGBotCommandScopeAllPrivateChats.swift │ │ ├── TGBotCommandScopeAllPrivateChatsType.swift │ │ ├── TGBotCommandScopeDefault.swift │ │ ├── TGPaidMediaPhoto.swift │ │ ├── TGStoryArea.swift │ │ ├── TGTransactionPartnerTelegramAds.swift │ │ ├── TGBotCommandScopeDefaultType.swift │ │ ├── TGBackgroundFillFreeformGradientType.swift │ │ ├── TGGiveawayCreated.swift │ │ ├── TGChatBoostUpdated.swift │ │ ├── TGSentWebAppMessage.swift │ │ ├── TGBackgroundTypePatternType.swift │ │ ├── TGInlineQueryResultVenueType.swift │ │ ├── TGStoryAreaTypeSuggestedReactionType.swift │ │ ├── TGTransactionPartnerAffiliateProgramType.swift │ │ ├── TGBotCommandScopeChatAdministratorsType.swift │ │ ├── TGChatMemberLeft.swift │ │ ├── TGDice.swift │ │ ├── TGInlineKeyboardMarkup.swift │ │ ├── TGBotCommandScopeAllChatAdministratorsType.swift │ │ ├── TGReactionCount.swift │ │ ├── TGBotCommandScopeAllChatAdministrators.swift │ │ ├── TGMessageAutoDeleteTimerChanged.swift │ │ ├── TGBusinessLocation.swift │ │ ├── TGInlineQueryResultAudioType.swift │ │ ├── TGInlineQueryResultPhotoType.swift │ │ ├── TGBackgroundFillSolid.swift │ │ ├── TGInlineQueryResultLocationType.swift │ │ ├── TGInlineQueryResultContactType.swift │ │ ├── TGMessageId.swift │ │ ├── TGPaidMediaInfo.swift │ │ ├── TGPaidMediaPurchased.swift │ │ ├── TGInlineQueryResultGifType.swift │ │ ├── TGPaidMessagePriceChanged.swift │ │ ├── TGBirthdate.swift │ │ ├── TGUserProfilePhotos.swift │ │ ├── TGBotCommand.swift │ │ ├── TGChatLocation.swift │ │ ├── TGChatBoostSourcePremium.swift │ │ ├── TGStoryAreaTypeLink.swift │ │ ├── TGUsersShared.swift │ │ ├── TGPassportElementErrorReverseSideType.swift │ │ ├── TGInlineQueryResultVoiceType.swift │ │ ├── TGKeyboardButtonPollType.swift │ │ ├── TGReactionTypeCustomEmoji.swift │ │ ├── TGGameHighScore.swift │ │ ├── TGInlineQueryResultCachedAudioType.swift │ │ ├── TGShippingOption.swift │ │ ├── TGStoryAreaTypeUniqueGift.swift │ │ ├── TGInlineQueryResultCachedStickerType.swift │ │ ├── TGInlineQueryResultCachedPhotoType.swift │ │ ├── TGInlineQueryResultCachedVoiceType.swift │ │ ├── TGBackgroundTypeChatTheme.swift │ │ ├── TGWebAppData.swift │ │ ├── TGInlineQueryResultCachedGifType.swift │ │ ├── TGInlineQueryResultCachedVideoType.swift │ │ ├── TGInlineQueryResultCachedDocumentType.swift │ │ ├── TGPassportElementErrorSelfieType.swift │ │ ├── TGPreparedInlineMessage.swift │ │ ├── TGInlineQueryResultDocumentType.swift │ │ ├── TGInlineQueryResultMpeg4GifType.swift │ │ ├── TGStarAmount.swift │ │ ├── TGPassportElementErrorFrontSideType.swift │ │ ├── TGChatBoostSourceGiftCode.swift │ │ ├── TGPassportData.swift │ │ ├── TGBotCommandScopeChat.swift │ │ ├── TGBusinessOpeningHours.swift │ │ ├── TGForumTopicEdited.swift │ │ ├── TGPassportElementErrorFileType.swift │ │ ├── TGInlineQueryResultCachedMpeg4GifType.swift │ │ ├── TGPassportElementErrorFilesType.swift │ │ ├── TGLabeledPrice.swift │ │ ├── TGTransactionPartnerChat.swift │ │ ├── TGTransactionPartnerTelegramApi.swift │ │ ├── TGMessageOriginUser.swift │ │ ├── TGBackgroundFillFreeformGradient.swift │ │ ├── TGTransactionPartnerFragment.swift │ │ ├── TGChatMemberMember.swift │ │ ├── TGPassportElementErrorDataFieldType.swift │ │ ├── TGBusinessIntro.swift │ │ ├── TGUniqueGiftModel.swift │ │ ├── TGInlineQueryResultVideoType.swift │ │ ├── TGInaccessibleMessage.swift │ │ ├── TGOwnedGifts.swift │ │ ├── TGChecklistTasksAdded.swift │ │ ├── TGRevenueWithdrawalStateSucceeded.swift │ │ ├── TGUniqueGiftSymbol.swift │ │ ├── TGInputProfilePhotoStatic.swift │ │ ├── TGUniqueGiftBackdrop.swift │ │ ├── TGInputPaidMediaPhoto.swift │ │ └── TGChatMemberBanned.swift │ └── Methods │ │ ├── GetMe.swift │ │ ├── GetAvailableGifts.swift │ │ └── GetMyStarBalance.swift │ ├── Filters │ ├── AllFilter.swift │ ├── AudioFilter.swift │ ├── GameFilter.swift │ ├── VenueFilter.swift │ ├── VideoFilter.swift │ ├── VoiceFilter.swift │ ├── GroupFilter.swift │ ├── ContactFilter.swift │ ├── InvoiceFilter.swift │ ├── StickerFilter.swift │ ├── DocumentFilter.swift │ ├── ForwarderFilter.swift │ ├── LocationFilter.swift │ ├── PrivateFilter.swift │ ├── ReplyFilter.swift │ ├── VideoNoteFilter.swift │ ├── PhotoFilter.swift │ ├── SuccesfulPaymentFilter.swift │ ├── TextFilter.swift │ ├── LanguageFilter.swift │ ├── EntityFilter.swift │ ├── CaptionEntityFilter.swift │ └── ChatFilter.swift │ ├── TGClientPrtcl.swift │ ├── Types │ ├── InputFile.swift │ ├── MessageOrBool.swift │ ├── ParseMode.swift │ └── TelegramContainer.swift │ └── Handlers │ ├── TGHandlerPrtcl.swift │ └── BaseHandler.swift ├── Examples ├── Vapor-Telegram-Bot │ ├── README.md │ ├── Sources │ │ └── Vapor-Telegram-Bot │ │ │ ├── routes.swift │ │ │ ├── main.swift │ │ │ ├── TGBot │ │ │ └── BotService.swift │ │ │ └── Controllers │ │ │ └── TelegramController.swift │ └── Package.swift ├── Hummingbird-URLSession-Telegram-Bot │ ├── README.md │ ├── Sources │ │ └── Hummingbird-URLSession-Telegram-Bot │ │ │ ├── TGBot │ │ │ └── TGBotActor.swift │ │ │ ├── main.swift │ │ │ └── Controllers │ │ │ └── TelegramController.swift │ └── Package.swift ├── Smoke-AsyncHttpClient-Telegram-Bot │ ├── README.md │ ├── Sources │ │ └── Smoke-AsyncHttpClient-Telegram-Bot │ │ │ ├── TGBot │ │ │ ├── ApplicationContext.swift │ │ │ ├── TGBotActor.swift │ │ │ └── TelegramBotError.swift │ │ │ ├── Controllers │ │ │ └── TelegramController.swift │ │ │ └── main.swift │ └── Package.swift ├── FlyingFox-AsyncHttpClient-Telegram-Bot │ ├── README.md │ ├── Sources │ │ └── FlyingFox-AsyncHttpClient-Telegram-Bot │ │ │ ├── TGBot │ │ │ └── TGBotActor.swift │ │ │ ├── main.swift │ │ │ └── Controllers │ │ │ └── TelegramController.swift │ └── Package.swift └── Hummingbird-AsyncHttpClient-Telegram-Bot │ ├── README.md │ ├── Sources │ └── Hummingbird-AsyncHttpClient-Telegram-Bot │ │ ├── TGBot │ │ └── TGBotActor.swift │ │ ├── main.swift │ │ └── Controllers │ │ └── TelegramController.swift │ └── Package.swift └── LICENSE /Api/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "nokogiri", ">= 1.10.4" 4 | gem "byebug" 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm 8 | Package.resolved 9 | Api/Gemfile.lock 10 | Api/tg* 11 | .byebug* -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Helpers/Extensions/Array+RemoveHandler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Oleh Hudeichuk on 30.05.2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension Array where Element == Array { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Examples/Vapor-Telegram-Bot/README.md: -------------------------------------------------------------------------------- 1 | # telegram-bot 2 | 3 | Just add your telegram api bot key to **configure.swift**, run this vapor app, send /ping command to your telegram bot and give a star to this library otherwise how will the programmers know it works 🙄 4 | 5 | ```swift 6 | let tgApi: String = "..." 7 | ``` 8 | -------------------------------------------------------------------------------- /Examples/Vapor-Telegram-Bot/Sources/Vapor-Telegram-Bot/routes.swift: -------------------------------------------------------------------------------- 1 | // 2 | // routes.swift 3 | // Vapor-telegram-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 21.05.2021. 6 | // 7 | 8 | import Vapor 9 | 10 | func routes(_ app: Application) throws { 11 | try app.register(collection: TelegramController()) 12 | } 13 | -------------------------------------------------------------------------------- /Examples/Hummingbird-URLSession-Telegram-Bot/README.md: -------------------------------------------------------------------------------- 1 | # telegram-bot 2 | 3 | Just add your telegram api bot key to **configure.swift**, run this hummingbird app, send /ping command to your telegram bot and give a star to this library otherwise how will the programmers know it works 🙄 4 | 5 | ```swift 6 | let tgApi: String = "..." 7 | ``` 8 | -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/README.md: -------------------------------------------------------------------------------- 1 | # telegram-bot 2 | 3 | Just add your telegram api bot key to **configure.swift**, run this hummingbird app, send /ping command to your telegram bot and give a star to this library otherwise how will the programmers know it works 🙄 4 | 5 | ```swift 6 | let tgApi: String = "..." 7 | ``` 8 | -------------------------------------------------------------------------------- /Examples/FlyingFox-AsyncHttpClient-Telegram-Bot/README.md: -------------------------------------------------------------------------------- 1 | # telegram-bot 2 | 3 | Just add your telegram api bot key to **configure.swift**, run this hummingbird app, send /ping command to your telegram bot and give a star to this library otherwise how will the programmers know it works 🙄 4 | 5 | ```swift 6 | let tgApi: String = "..." 7 | ``` 8 | -------------------------------------------------------------------------------- /Examples/Hummingbird-AsyncHttpClient-Telegram-Bot/README.md: -------------------------------------------------------------------------------- 1 | # telegram-bot 2 | 3 | Just add your telegram api bot key to **configure.swift**, run this hummingbird app, send /ping command to your telegram bot and give a star to this library otherwise how will the programmers know it works 🙄 4 | 5 | ```swift 6 | let tgApi: String = "..." 7 | ``` 8 | -------------------------------------------------------------------------------- /Api/start.rb: -------------------------------------------------------------------------------- 1 | #!/bin/env ruby 2 | 3 | script_file_path = File.expand_path(File.dirname(__FILE__)) 4 | system("cd #{script_file_path} && bundle update") 5 | system("cd #{script_file_path} && rm -f tg-api.html || true") 6 | system("cd #{script_file_path} && curl https://core.telegram.org/bots/api > tg-api.html") 7 | system("cd #{script_file_path} && ruby generate_wrappers.rb") -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/Sources/Smoke-AsyncHttpClient-Telegram-Bot/TGBot/ApplicationContext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ApplicationContext.swift 3 | // Smoke-AsyncHttpClient-bot-example 4 | // 5 | // Created by Maxim Lanskoy on 06.07.2024. 6 | // 7 | 8 | import Logging 9 | 10 | struct TelegramApplicationContext { 11 | let logger: Logger 12 | let botActor: TGBotActor 13 | } 14 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGCallbackGame.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | A placeholder, currently holds no information. Use BotFather to set up your game. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [CallbackGame](https://core.telegram.org/bots/api#callbackgame) 8 | **/ 9 | public final class TGCallbackGame: Codable, Sendable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGForumTopicClosed.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a forum topic closed in the chat. Currently holds no information. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ForumTopicClosed](https://core.telegram.org/bots/api#forumtopicclosed) 8 | **/ 9 | public final class TGForumTopicClosed: Codable, Sendable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGVideoChatStarted.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a video chat started in the chat. Currently holds no information. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [VideoChatStarted](https://core.telegram.org/bots/api#videochatstarted) 8 | **/ 9 | public final class TGVideoChatStarted: Codable, Sendable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGForumTopicReopened.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a forum topic reopened in the chat. Currently holds no information. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ForumTopicReopened](https://core.telegram.org/bots/api#forumtopicreopened) 8 | **/ 9 | public final class TGForumTopicReopened: Codable, Sendable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGGeneralForumTopicHidden.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about General forum topic hidden in the chat. Currently holds no information. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [GeneralForumTopicHidden](https://core.telegram.org/bots/api#generalforumtopichidden) 8 | **/ 9 | public final class TGGeneralForumTopicHidden: Codable, Sendable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Examples/Hummingbird-URLSession-Telegram-Bot/Sources/Hummingbird-URLSession-Telegram-Bot/TGBot/TGBotActor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TGBotActor.swift 3 | // Hummingbird-URLSession-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 17.04.2023. 6 | // 7 | 8 | import SwiftTelegramBot 9 | 10 | actor TGBotActor { 11 | private var _bot: TGBot! 12 | 13 | var bot: TGBot { 14 | self._bot 15 | } 16 | 17 | func setBot(_ bot: TGBot) { 18 | self._bot = bot 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGGeneralForumTopicUnhidden.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about General forum topic unhidden in the chat. Currently holds no information. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [GeneralForumTopicUnhidden](https://core.telegram.org/bots/api#generalforumtopicunhidden) 8 | **/ 9 | public final class TGGeneralForumTopicUnhidden: Codable, Sendable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/AllFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filter for any update, said "no filter" 10 | public class AllFilter: TGFilter { 11 | public var name: String = "all" 12 | 13 | override 14 | public func filter(message: TGMessage) -> Bool { 15 | return true 16 | } 17 | } 18 | 19 | public extension TGFilter { 20 | static var all: AllFilter { AllFilter() } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/TGClientPrtcl.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleh Hudeichuk on 21.05.2021. 3 | // 4 | 5 | import Foundation 6 | import Logging 7 | 8 | public protocol TGClientPrtcl: Sendable { 9 | 10 | @discardableResult 11 | func post(_ url: URL, params: Params?, as mediaType: HTTPMediaType?) async throws -> Response 12 | 13 | @discardableResult 14 | func post(_ url: URL) async throws -> Response 15 | } 16 | -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/Sources/Smoke-AsyncHttpClient-Telegram-Bot/TGBot/TGBotActor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TGBotActor.swift 3 | // Smoke-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 17.04.2023. 6 | // 7 | 8 | import Foundation 9 | import SwiftTelegramBot 10 | 11 | actor TGBotActor { 12 | private var _bot: TGBot! 13 | 14 | var bot: TGBot { 15 | self._bot 16 | } 17 | 18 | func setBot(_ bot: TGBot) { 19 | self._bot = bot 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Types/InputFile.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputFile.swift 3 | // 4 | // 5 | // Created by Oleh Hudeichuk on 28.05.2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TGInputFile: Codable, Sendable { 11 | var fileName: String 12 | var data: Data 13 | var mimeType: String? 14 | 15 | public init(filename: String, data: Data, mimeType: String? = nil) { 16 | self.data = data 17 | self.fileName = filename 18 | self.mimeType = mimeType 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/AudioFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Audio` 10 | public class AudioFilter: TGFilter { 11 | public var name: String = "audio" 12 | 13 | override 14 | public func filter(message: TGMessage) -> Bool { 15 | return message.audio != nil 16 | } 17 | } 18 | 19 | public extension TGFilter { 20 | static var audio: AudioFilter { AudioFilter() } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/GameFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Game` 10 | public class GameFilter: TGFilter { 11 | 12 | public var name: String = "forwarded" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.game != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var game: GameFilter { GameFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Examples/FlyingFox-AsyncHttpClient-Telegram-Bot/Sources/FlyingFox-AsyncHttpClient-Telegram-Bot/TGBot/TGBotActor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TGBotActor.swift 3 | // FlyingFox-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 17.04.2023. 6 | // 7 | 8 | import Foundation 9 | import SwiftTelegramBot 10 | 11 | actor TGBotActor { 12 | private var _bot: TGBot! 13 | 14 | var bot: TGBot { 15 | self._bot 16 | } 17 | 18 | func setBot(_ bot: TGBot) { 19 | self._bot = bot 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/Sources/Smoke-AsyncHttpClient-Telegram-Bot/TGBot/TelegramBotError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramBotError.swift 3 | // Smoke-AsyncHttpClient-bot-example 4 | // 5 | // Created by Maxim Lanskoy on 07.07.2024. 6 | // 7 | 8 | enum TelegramBotError: Swift.Error, CustomStringConvertible { 9 | case unknownError 10 | 11 | public var description: String { 12 | switch self { 13 | case .unknownError: 14 | return "UnknownError" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/VenueFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Vanue` 10 | public class VenueFilter: TGFilter { 11 | 12 | public var name: String = "venue" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.venue != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var venue: VenueFilter { VenueFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/VideoFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Video` 10 | public class VideoFilter: TGFilter { 11 | 12 | public var name: String = "video" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.video != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var video: VideoFilter { VideoFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/VoiceFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Voice` 10 | public class VoiceFilter: TGFilter { 11 | 12 | public var name: String = "voice" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.voice != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var voice: VoiceFilter { VoiceFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Examples/Hummingbird-AsyncHttpClient-Telegram-Bot/Sources/Hummingbird-AsyncHttpClient-Telegram-Bot/TGBot/TGBotActor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TGBotActor.swift 3 | // Hummingbird-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 17.04.2023. 6 | // 7 | 8 | import Foundation 9 | import SwiftTelegramBot 10 | 11 | actor TGBotActor { 12 | private var _bot: TGBot! 13 | 14 | var bot: TGBot { 15 | self._bot 16 | } 17 | 18 | func setBot(_ bot: TGBot) { 19 | self._bot = bot 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/GroupFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages sent in a group chat 10 | public class GroupFilter: TGFilter { 11 | 12 | public var name: String = "group" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.chat.type != .private 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var group: GroupFilter { GroupFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/ContactFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Contact` 10 | public class ContactFilter: TGFilter { 11 | 12 | public var name: String = "contact" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.contact != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var contact: ContactFilter { ContactFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/InvoiceFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Invoice` 10 | public class InvoiceFilter: TGFilter { 11 | 12 | public var name: String = "invoice" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.invoice != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var invoice: InvoiceFilter { InvoiceFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/StickerFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Sticker` 10 | public class StickerFilter: TGFilter { 11 | 12 | public var name: String = "sticker" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.sticker != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var sticker: StickerFilter { StickerFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/DocumentFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Document` 10 | public class DocumentFilter: TGFilter { 11 | 12 | public var name: String = "document" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.document != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var document: DocumentFilter { DocumentFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/ForwarderFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that are forwarded. 10 | public class ForwarderFilter: TGFilter { 11 | 12 | public var name: String = "forwarded" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | message.forwardOrigin != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var forwarded: ForwarderFilter { ForwarderFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/LocationFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `Location` 10 | public class LocationFilter: TGFilter { 11 | 12 | public var name: String = "location" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.location != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var location: LocationFilter { LocationFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/PrivateFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages sent in a private chat 10 | public class PrivateFilter: TGFilter { 11 | 12 | public var name: String = "private" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.chat.type == .private 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var `private`: PrivateFilter { PrivateFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/ReplyFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that are a reply to another message 10 | public class ReplyFilter: TGFilter { 11 | 12 | public var name: String = "reply" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.replyToMessage != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var reply: ReplyFilter { ReplyFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/VideoNoteFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `VideoNote` 10 | public class VideoNoteFilter: TGFilter { 11 | 12 | public var name: String = "video_note" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.videoNote != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var videoNote: VideoNoteFilter { VideoNoteFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/PhotoFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Messages that contain `[PhotoSize]` 10 | public class PhotoFilter: TGFilter { 11 | 12 | public var name: String = "photo" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | guard let photos = message.photo else { return false } 17 | return !photos.isEmpty 18 | } 19 | } 20 | 21 | public extension TGFilter { 22 | static var photo: PhotoFilter { PhotoFilter() } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Vapor-Telegram-Bot/Sources/Vapor-Telegram-Bot/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // Vapor-telegram-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 21.05.2021. 6 | // 7 | 8 | import Vapor 9 | 10 | var env = try Environment.detect() 11 | try LoggingSystem.bootstrap(from: &env) 12 | let eventLoop: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount * 4) 13 | let app: Application = try await Application.make(env, Application.EventLoopGroupProvider.shared(eventLoop)) 14 | 15 | try await configure(app) 16 | try await app.execute() 17 | try await app.asyncShutdown() 18 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/SuccesfulPaymentFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filters messages that contains a `SuccessfulPayment`. 10 | public class SuccesfulPaymentFilter: TGFilter { 11 | 12 | public var name: String = "successful_payment" 13 | 14 | override 15 | public func filter(message: TGMessage) -> Bool { 16 | return message.successfulPayment != nil 17 | } 18 | } 19 | 20 | public extension TGFilter { 21 | static var successfulPayment: SuccesfulPaymentFilter { SuccesfulPaymentFilter() } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Handlers/TGHandlerPrtcl.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleh Hudeichuk on 23.05.2021. 3 | // 4 | 5 | import Foundation 6 | 7 | public typealias TGHandlerCallbackAsync = @Sendable (_ update: TGUpdate) async throws -> Void 8 | 9 | public protocol TGHandlerPrtcl: Sendable { 10 | 11 | var id: SendableValue { get } 12 | var name: String { get } 13 | 14 | func check(update: TGUpdate) async -> Bool 15 | func handle(update: TGUpdate) async throws 16 | } 17 | 18 | extension TGHandlerPrtcl { 19 | public var name: String { 20 | return String(describing: Self.self) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotName.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents the bot's name. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotName](https://core.telegram.org/bots/api#botname) 8 | **/ 9 | public final class TGBotName: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotName` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case name = "name" 14 | } 15 | 16 | /// The bot's name 17 | public let name: String 18 | 19 | public init (name: String) { 20 | self.name = name 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGGifts.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represent a list of gifts. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Gifts](https://core.telegram.org/bots/api#gifts) 8 | **/ 9 | public final class TGGifts: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `Gifts` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case gifts = "gifts" 14 | } 15 | 16 | /// The list of gifts 17 | public let gifts: [TGGift] 18 | 19 | public init (gifts: [TGGift]) { 20 | self.gifts = gifts 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/Sources/Smoke-AsyncHttpClient-Telegram-Bot/Controllers/TelegramController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramController.swift 3 | // Smoke-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 10.03.2023. 6 | // 7 | 8 | import Foundation 9 | import SmokeOperations 10 | import SmokeOperationsHTTP1 11 | import SwiftTelegramBot 12 | 13 | struct TelegramController { 14 | static func telegramWebHookHandler(input: TGUpdate, context: TelegramApplicationContext) throws -> Void { 15 | Task { 16 | await context.botActor.bot.processing(updates: [input]) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Examples/Hummingbird-AsyncHttpClient-Telegram-Bot/Sources/Hummingbird-AsyncHttpClient-Telegram-Bot/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // Hummingbird-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 21.05.2021. 6 | // 7 | 8 | import Hummingbird 9 | import Logging 10 | 11 | var logger = Logger(label: "SwiftTelegramBot") 12 | logger.logLevel = .debug 13 | 14 | let router = Router() 15 | router.middlewares.add(LogRequestsMiddleware(.info)) 16 | TelegramController().addRoutes(to: router.group("tgbot")) 17 | 18 | let app = Application(router: router) 19 | let botActor: TGBotActor = .init() 20 | 21 | try await configure(app) 22 | try await app.runService() 23 | -------------------------------------------------------------------------------- /Examples/Hummingbird-URLSession-Telegram-Bot/Sources/Hummingbird-URLSession-Telegram-Bot/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // Hummingbird-URLSession-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 21.05.2021. 6 | // 7 | 8 | import SwiftTelegramBot 9 | import Hummingbird 10 | import Logging 11 | 12 | var logger = Logger(label: "SwiftTelegramBot") 13 | logger.logLevel = .debug 14 | 15 | let router = Router() 16 | router.middlewares.add(LogRequestsMiddleware(.info)) 17 | TelegramController().addRoutes(to: router.group("tgbot")) 18 | 19 | let app = Application(router: router) 20 | let botActor: TGBotActor = .init() 21 | 22 | try await configure(app) 23 | try await app.runService() 24 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatBackground.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a chat background. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatBackground](https://core.telegram.org/bots/api#chatbackground) 8 | **/ 9 | public final class TGChatBackground: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatBackground` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the background 17 | public let type: TGBackgroundType 18 | 19 | public init (type: TGBackgroundType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGWebAppInfo.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a Web App. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [WebAppInfo](https://core.telegram.org/bots/api#webappinfo) 8 | **/ 9 | public final class TGWebAppInfo: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `WebAppInfo` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case url = "url" 14 | } 15 | 16 | /// An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps 17 | public let url: String 18 | 19 | public init (url: String) { 20 | self.url = url 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGReactionTypePaid.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The reaction is paid. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ReactionTypePaid](https://core.telegram.org/bots/api#reactiontypepaid) 8 | **/ 9 | public final class TGReactionTypePaid: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ReactionTypePaid` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the reaction, always “paid” 17 | public let type: TGReactionTypePaidType 18 | 19 | public init (type: TGReactionTypePaidType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaPhotoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media is a photo. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaPhoto](https://core.telegram.org/bots/api#paidmediaphoto) 8 | */ 9 | 10 | public enum TGPaidMediaPhotoType: String, Codable, Sendable { 11 | case photo = "photo" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGPaidMediaPhotoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaVideoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media is a video. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaVideo](https://core.telegram.org/bots/api#paidmediavideo) 8 | */ 9 | 10 | public enum TGPaidMediaVideoType: String, Codable, Sendable { 11 | case video = "video" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGPaidMediaVideoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPollType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object contains information about a poll. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Poll](https://core.telegram.org/bots/api#poll) 8 | */ 9 | 10 | public enum TGPollType: String, Codable, Sendable { 11 | case regular = "regular" 12 | case quiz = "quiz" 13 | case undefined 14 | 15 | public init(from decoder: Decoder) throws { 16 | let value = try decoder.singleValueContainer().decode(String.self) 17 | guard let type = TGPollType(rawValue: value) else { 18 | self = .undefined 19 | return 20 | } 21 | self = type 22 | } 23 | } -------------------------------------------------------------------------------- /Examples/FlyingFox-AsyncHttpClient-Telegram-Bot/Sources/FlyingFox-AsyncHttpClient-Telegram-Bot/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // FlyingFox-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 21.05.2021. 6 | // 7 | 8 | import FlyingFox 9 | import Logging 10 | import Foundation 11 | 12 | struct TelegramApplicationContext { 13 | let logger: Logger 14 | let botActor: TGBotActor 15 | } 16 | 17 | var logger = Logger(label: "SwiftTelegramBot") 18 | logger.logLevel = .debug 19 | let botActor = TGBotActor() 20 | let appContext = TelegramApplicationContext(logger: logger, botActor: botActor) 21 | try await configure(appContext: appContext) 22 | let server = HTTPServer(port: 8080) 23 | try await server.start() 24 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotDescription.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents the bot's description. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotDescription](https://core.telegram.org/bots/api#botdescription) 8 | **/ 9 | public final class TGBotDescription: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotDescription` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case description = "description" 14 | } 15 | 16 | /// The bot's description 17 | public let description: String 18 | 19 | public init (description: String) { 20 | self.description = description 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGReactionTypePaidType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The reaction is paid. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ReactionTypePaid](https://core.telegram.org/bots/api#reactiontypepaid) 8 | */ 9 | 10 | public enum TGReactionTypePaidType: String, Codable, Sendable { 11 | case paid = "paid" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGReactionTypePaidType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Examples/Hummingbird-URLSession-Telegram-Bot/Sources/Hummingbird-URLSession-Telegram-Bot/Controllers/TelegramController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramController.swift 3 | // Hummingbird-URLSession-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 10.03.2023. 6 | // 7 | 8 | import Hummingbird 9 | import SwiftTelegramBot 10 | 11 | final class TelegramController { 12 | func addRoutes(to group: RouterGroup) { 13 | group.post("telegramWebHook") { req, context in 14 | let update: TGUpdate = try await req.decode(as: TGUpdate.self, context: context) 15 | Task { await botActor.bot.processing(updates: [update]) } 16 | return Response(status: 200) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputMediaPhotoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a photo to be sent. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputMediaPhoto](https://core.telegram.org/bots/api#inputmediaphoto) 8 | */ 9 | 10 | public enum TGInputMediaPhotoType: String, Codable, Sendable { 11 | case photo = "photo" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputMediaPhotoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputMediaVideoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a video to be sent. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputMediaVideo](https://core.telegram.org/bots/api#inputmediavideo) 8 | */ 9 | 10 | public enum TGInputMediaVideoType: String, Codable, Sendable { 11 | case video = "video" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputMediaVideoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultGameType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a Game. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame) 8 | */ 9 | 10 | public enum TGInlineQueryResultGameType: String, Codable, Sendable { 11 | case game = "game" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultGameType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGReactionTypeEmojiType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The reaction is based on an emoji. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ReactionTypeEmoji](https://core.telegram.org/bots/api#reactiontypeemoji) 8 | */ 9 | 10 | public enum TGReactionTypeEmojiType: String, Codable, Sendable { 11 | case emoji = "emoji" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGReactionTypeEmojiType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGVideoChatEnded.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a video chat ended in the chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [VideoChatEnded](https://core.telegram.org/bots/api#videochatended) 8 | **/ 9 | public final class TGVideoChatEnded: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `VideoChatEnded` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case duration = "duration" 14 | } 15 | 16 | /// Video chat duration in seconds 17 | public let duration: Int 18 | 19 | public init (duration: Int) { 20 | self.duration = duration 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Examples/Vapor-Telegram-Bot/Sources/Vapor-Telegram-Bot/TGBot/BotService.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BotService.swift 3 | // Vapor-Telegram-Bot 4 | // 5 | // Created by Oleh Hudeichuk on 05.09.2025. 6 | // 7 | 8 | import Vapor 9 | import SwiftTelegramBot 10 | 11 | extension Application { 12 | private struct TGServiceServiceKey: StorageKey { 13 | typealias Value = TGBot 14 | } 15 | 16 | var bot: TGBot { 17 | get { 18 | guard let service = storage[TGServiceServiceKey.self] else { 19 | fatalError("TGBot not configured. Use app.bot = ...") 20 | } 21 | return service 22 | } 23 | set { 24 | storage[TGServiceServiceKey.self] = newValue 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatBoostAdded.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a user boosting a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatBoostAdded](https://core.telegram.org/bots/api#chatboostadded) 8 | **/ 9 | public final class TGChatBoostAdded: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatBoostAdded` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case boostCount = "boost_count" 14 | } 15 | 16 | /// Number of boosts added by the user 17 | public let boostCount: Int 18 | 19 | public init (boostCount: Int) { 20 | self.boostCount = boostCount 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputMediaDocumentType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a general file to be sent. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputMediaDocument](https://core.telegram.org/bots/api#inputmediadocument) 8 | */ 9 | 10 | public enum TGInputMediaDocumentType: String, Codable, Sendable { 11 | case document = "document" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputMediaDocumentType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputPaidMediaPhotoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media to send is a photo. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputPaidMediaPhoto](https://core.telegram.org/bots/api#inputpaidmediaphoto) 8 | */ 9 | 10 | public enum TGInputPaidMediaPhotoType: String, Codable, Sendable { 11 | case photo = "photo" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputPaidMediaPhotoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputPaidMediaVideoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media to send is a video. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputPaidMediaVideo](https://core.telegram.org/bots/api#inputpaidmediavideo) 8 | */ 9 | 10 | public enum TGInputPaidMediaVideoType: String, Codable, Sendable { 11 | case video = "video" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputPaidMediaVideoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageOriginUserType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The message was originally sent by a known user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageOriginUser](https://core.telegram.org/bots/api#messageoriginuser) 8 | */ 9 | 10 | public enum TGMessageOriginUserType: String, Codable, Sendable { 11 | case user = "user" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMessageOriginUserType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGUserChatBoosts.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a list of boosts added to a chat by a user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [UserChatBoosts](https://core.telegram.org/bots/api#userchatboosts) 8 | **/ 9 | public final class TGUserChatBoosts: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `UserChatBoosts` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case boosts = "boosts" 14 | } 15 | 16 | /// The list of boosts added to the chat by the user 17 | public let boosts: [TGChatBoost] 18 | 19 | public init (boosts: [TGChatBoost]) { 20 | self.boosts = boosts 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputMediaAudioType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an audio file to be treated as music to be sent. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputMediaAudio](https://core.telegram.org/bots/api#inputmediaaudio) 8 | */ 9 | 10 | public enum TGInputMediaAudioType: String, Codable, Sendable { 11 | case audio = "audio" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputMediaAudioType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMenuButtonDefault.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes that no specific value for the menu button was set. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MenuButtonDefault](https://core.telegram.org/bots/api#menubuttondefault) 8 | **/ 9 | public final class TGMenuButtonDefault: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `MenuButtonDefault` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the button, must be default 17 | public let type: TGMenuButtonDefaultType 18 | 19 | public init (type: TGMenuButtonDefaultType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMenuButtonWebAppType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a menu button, which launches a Web App. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MenuButtonWebApp](https://core.telegram.org/bots/api#menubuttonwebapp) 8 | */ 9 | 10 | public enum TGMenuButtonWebAppType: String, Codable, Sendable { 11 | case webApp = "web_app" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMenuButtonWebAppType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGOwnedGiftRegularType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a regular gift owned by a user or a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [OwnedGiftRegular](https://core.telegram.org/bots/api#ownedgiftregular) 8 | */ 9 | 10 | public enum TGOwnedGiftRegularType: String, Codable, Sendable { 11 | case regular = "regular" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGOwnedGiftRegularType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaPreviewType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media isn't available before the payment. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaPreview](https://core.telegram.org/bots/api#paidmediapreview) 8 | */ 9 | 10 | public enum TGPaidMediaPreviewType: String, Codable, Sendable { 11 | case preview = "preview" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGPaidMediaPreviewType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGCopyTextButton.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents an inline keyboard button that copies specified text to the clipboard. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [CopyTextButton](https://core.telegram.org/bots/api#copytextbutton) 8 | **/ 9 | public final class TGCopyTextButton: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `CopyTextButton` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case text = "text" 14 | } 15 | 16 | /// The text to be copied to the clipboard; 1-256 characters 17 | public let text: String 18 | 19 | public init (text: String) { 20 | self.text = text 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGOwnedGiftUniqueType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a unique gift received and owned by a user or a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [OwnedGiftUnique](https://core.telegram.org/bots/api#ownedgiftunique) 8 | */ 9 | 10 | public enum TGOwnedGiftUniqueType: String, Codable, Sendable { 11 | case unique = "unique" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGOwnedGiftUniqueType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStickerType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a sticker. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Sticker](https://core.telegram.org/bots/api#sticker) 8 | */ 9 | 10 | public enum TGStickerType: String, Codable, Sendable { 11 | case regular = "regular" 12 | case mask = "mask" 13 | case customEmoji = "custom_emoji" 14 | case undefined 15 | 16 | public init(from decoder: Decoder) throws { 17 | let value = try decoder.singleValueContainer().decode(String.self) 18 | guard let type = TGStickerType(rawValue: value) else { 19 | self = .undefined 20 | return 21 | } 22 | self = type 23 | } 24 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundFillSolidType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is filled using the selected color. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundFillSolid](https://core.telegram.org/bots/api#backgroundfillsolid) 8 | */ 9 | 10 | public enum TGBackgroundFillSolidType: String, Codable, Sendable { 11 | case solid = "solid" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundFillSolidType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputStoryContentPhotoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a photo to post as a story. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputStoryContentPhoto](https://core.telegram.org/bots/api#inputstorycontentphoto) 8 | */ 9 | 10 | public enum TGInputStoryContentPhotoType: String, Codable, Sendable { 11 | case photo = "photo" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputStoryContentPhotoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputStoryContentVideoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a video to post as a story. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputStoryContentVideo](https://core.telegram.org/bots/api#inputstorycontentvideo) 8 | */ 9 | 10 | public enum TGInputStoryContentVideoType: String, Codable, Sendable { 11 | case video = "video" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputStoryContentVideoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStarTransactions.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Contains a list of Telegram Star transactions. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StarTransactions](https://core.telegram.org/bots/api#startransactions) 8 | **/ 9 | public final class TGStarTransactions: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `StarTransactions` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case transactions = "transactions" 14 | } 15 | 16 | /// The list of transactions 17 | public let transactions: [TGStarTransaction] 18 | 19 | public init (transactions: [TGStarTransaction]) { 20 | self.transactions = transactions 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerChatType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerChat](https://core.telegram.org/bots/api#transactionpartnerchat) 8 | */ 9 | 10 | public enum TGTransactionPartnerChatType: String, Codable, Sendable { 11 | case chat = "chat" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerChatType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerUserType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with a user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerUser](https://core.telegram.org/bots/api#transactionpartneruser) 8 | */ 9 | 10 | public enum TGTransactionPartnerUserType: String, Codable, Sendable { 11 | case user = "user" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerUserType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundFillGradientType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is a gradient fill. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundFillGradient](https://core.telegram.org/bots/api#backgroundfillgradient) 8 | */ 9 | 10 | public enum TGBackgroundFillGradientType: String, Codable, Sendable { 11 | case gradient = "gradient" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundFillGradientType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMenuButtonCommands.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a menu button, which opens the bot's list of commands. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MenuButtonCommands](https://core.telegram.org/bots/api#menubuttoncommands) 8 | **/ 9 | public final class TGMenuButtonCommands: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `MenuButtonCommands` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the button, must be commands 17 | public let type: TGMenuButtonCommandsType 18 | 19 | public init (type: TGMenuButtonCommandsType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMenuButtonDefaultType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes that no specific value for the menu button was set. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MenuButtonDefault](https://core.telegram.org/bots/api#menubuttondefault) 8 | */ 9 | 10 | public enum TGMenuButtonDefaultType: String, Codable, Sendable { 11 | case `default` = "default" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMenuButtonDefaultType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageOriginChatType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The message was originally sent on behalf of a chat to a group chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageOriginChat](https://core.telegram.org/bots/api#messageoriginchat) 8 | */ 9 | 10 | public enum TGMessageOriginChatType: String, Codable, Sendable { 11 | case chat = "chat" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMessageOriginChatType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundTypeFillType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is automatically filled based on the selected colors. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundTypeFill](https://core.telegram.org/bots/api#backgroundtypefill) 8 | */ 9 | 10 | public enum TGBackgroundTypeFillType: String, Codable, Sendable { 11 | case fill = "fill" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundTypeFillType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeChatType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering a specific chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeChat](https://core.telegram.org/bots/api#botcommandscopechat) 8 | */ 9 | 10 | public enum TGBotCommandScopeChatType: String, Codable, Sendable { 11 | case chat = "chat" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeChatType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageOriginChannelType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The message was originally sent to a channel chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageOriginChannel](https://core.telegram.org/bots/api#messageoriginchannel) 8 | */ 9 | 10 | public enum TGMessageOriginChannelType: String, Codable, Sendable { 11 | case channel = "channel" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMessageOriginChannelType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Examples/Vapor-Telegram-Bot/Sources/Vapor-Telegram-Bot/Controllers/TelegramController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramController.swift 3 | // Vapor-telegram-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 10.03.2023. 6 | // 7 | 8 | import Foundation 9 | import Vapor 10 | import SwiftTelegramBot 11 | 12 | final class TelegramController: RouteCollection { 13 | 14 | func boot(routes: Vapor.RoutesBuilder) throws { 15 | routes.post("telegramWebHook", use: telegramWebHook) 16 | } 17 | } 18 | 19 | extension TelegramController { 20 | 21 | func telegramWebHook(_ req: Request) async throws -> Bool { 22 | let update: TGUpdate = try req.content.decode(TGUpdate.self) 23 | await app.bot.processing(updates: [update]) 24 | return true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Chat](https://core.telegram.org/bots/api#chat) 8 | */ 9 | 10 | public enum TGChatType: String, Codable, Sendable { 11 | case `private` = "private" 12 | case group = "group" 13 | case supergroup = "supergroup" 14 | case channel = "channel" 15 | case undefined 16 | 17 | public init(from decoder: Decoder) throws { 18 | let value = try decoder.singleValueContainer().decode(String.self) 19 | guard let type = TGChatType(rawValue: value) else { 20 | self = .undefined 21 | return 22 | } 23 | self = type 24 | } 25 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputProfilePhotoStaticType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | A static profile photo in the .JPG format. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputProfilePhotoStatic](https://core.telegram.org/bots/api#inputprofilephotostatic) 8 | */ 9 | 10 | public enum TGInputProfilePhotoStaticType: String, Codable, Sendable { 11 | case `static` = "static" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputProfilePhotoStaticType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMenuButtonCommandsType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a menu button, which opens the bot's list of commands. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MenuButtonCommands](https://core.telegram.org/bots/api#menubuttoncommands) 8 | */ 9 | 10 | public enum TGMenuButtonCommandsType: String, Codable, Sendable { 11 | case commands = "commands" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMenuButtonCommandsType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStory.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a story. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Story](https://core.telegram.org/bots/api#story) 8 | **/ 9 | public final class TGStory: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `Story` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case chat = "chat" 14 | case id = "id" 15 | } 16 | 17 | /// Chat that posted the story 18 | public let chat: TGChat 19 | 20 | /// Unique identifier for the story in the chat 21 | public let id: Int 22 | 23 | public init (chat: TGChat, id: Int) { 24 | self.chat = chat 25 | self.id = id 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultArticleType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to an article or web page. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultArticle](https://core.telegram.org/bots/api#inlinequeryresultarticle) 8 | */ 9 | 10 | public enum TGInlineQueryResultArticleType: String, Codable, Sendable { 11 | case article = "article" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultArticleType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGReactionTypeCustomEmojiType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The reaction is based on a custom emoji. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ReactionTypeCustomEmoji](https://core.telegram.org/bots/api#reactiontypecustomemoji) 8 | */ 9 | 10 | public enum TGReactionTypeCustomEmojiType: String, Codable, Sendable { 11 | case customEmoji = "custom_emoji" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGReactionTypeCustomEmojiType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundTypeWallpaperType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is a wallpaper in the JPEG format. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundTypeWallpaper](https://core.telegram.org/bots/api#backgroundtypewallpaper) 8 | */ 9 | 10 | public enum TGBackgroundTypeWallpaperType: String, Codable, Sendable { 11 | case wallpaper = "wallpaper" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundTypeWallpaperType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotShortDescription.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents the bot's short description. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription) 8 | **/ 9 | public final class TGBotShortDescription: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotShortDescription` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case shortDescription = "short_description" 14 | } 15 | 16 | /// The bot's short description 17 | public let shortDescription: String 18 | 19 | public init (shortDescription: String) { 20 | self.shortDescription = shortDescription 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputProfilePhotoAnimatedType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | An animated profile photo in the MPEG4 format. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputProfilePhotoAnimated](https://core.telegram.org/bots/api#inputprofilephotoanimated) 8 | */ 9 | 10 | public enum TGInputProfilePhotoAnimatedType: String, Codable, Sendable { 11 | case animated = "animated" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputProfilePhotoAnimatedType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageOriginHiddenUserType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The message was originally sent by an unknown user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageOriginHiddenUser](https://core.telegram.org/bots/api#messageoriginhiddenuser) 8 | */ 9 | 10 | public enum TGMessageOriginHiddenUserType: String, Codable, Sendable { 11 | case hiddenUser = "hidden_user" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGMessageOriginHiddenUserType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerOtherType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with an unknown source or recipient. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerOther](https://core.telegram.org/bots/api#transactionpartnerother) 8 | */ 9 | 10 | public enum TGTransactionPartnerOtherType: String, Codable, Sendable { 11 | case other = "other" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerOtherType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Examples/Hummingbird-AsyncHttpClient-Telegram-Bot/Sources/Hummingbird-AsyncHttpClient-Telegram-Bot/Controllers/TelegramController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramController.swift 3 | // Hummingbird-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 10.03.2023. 6 | // 7 | 8 | import Foundation 9 | import Hummingbird 10 | import SwiftTelegramBot 11 | 12 | final class TelegramController { 13 | func addRoutes(to group: RouterGroup) { 14 | group.post("telegramWebHook") { req, context in 15 | let update: TGUpdate = try await req.decode(as: TGUpdate.self, context: context) 16 | Task { 17 | await botActor.bot.processing(updates: [update]) 18 | } 19 | return Response(status: 200) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGRevenueWithdrawalStatePendingType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The withdrawal is in progress. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [RevenueWithdrawalStatePending](https://core.telegram.org/bots/api#revenuewithdrawalstatepending) 8 | */ 9 | 10 | public enum TGRevenueWithdrawalStatePendingType: String, Codable, Sendable { 11 | case pending = "pending" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGRevenueWithdrawalStatePendingType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundTypeChatThemeType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is taken directly from a built-in chat theme. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundTypeChatTheme](https://core.telegram.org/bots/api#backgroundtypechattheme) 8 | */ 9 | 10 | public enum TGBackgroundTypeChatThemeType: String, Codable, Sendable { 11 | case chatTheme = "chat_theme" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundTypeChatThemeType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGRevenueWithdrawalStateSucceededType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The withdrawal succeeded. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [RevenueWithdrawalStateSucceeded](https://core.telegram.org/bots/api#revenuewithdrawalstatesucceeded) 8 | */ 9 | 10 | public enum TGRevenueWithdrawalStateSucceededType: String, Codable, Sendable { 11 | case succeeded = "succeeded" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGRevenueWithdrawalStateSucceededType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeLinkType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area pointing to an HTTP or tg:// link. Currently, a story can have up to 3 link areas. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeLink](https://core.telegram.org/bots/api#storyareatypelink) 8 | */ 9 | 10 | public enum TGStoryAreaTypeLinkType: String, Codable, Sendable { 11 | case link = "link" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGStoryAreaTypeLinkType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerFragmentType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a withdrawal transaction with Fragment. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerFragment](https://core.telegram.org/bots/api#transactionpartnerfragment) 8 | */ 9 | 10 | public enum TGTransactionPartnerFragmentType: String, Codable, Sendable { 11 | case fragment = "fragment" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerFragmentType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Handlers/BaseHandler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleh Hudeichuk on 13.04.2023. 3 | // 4 | 5 | import Foundation 6 | 7 | public final class TGBaseHandler: TGHandlerPrtcl { 8 | 9 | public let id: SendableValue = .init(0) 10 | public let name: String 11 | let callbackAsync: TGHandlerCallbackAsync 12 | 13 | public init( 14 | name: String = String(describing: TGBaseHandler.self), 15 | _ callback: @escaping TGHandlerCallbackAsync 16 | ) { 17 | self.name = name 18 | self.callbackAsync = callback 19 | } 20 | 21 | public func check(update: TGUpdate) async -> Bool { 22 | true 23 | } 24 | 25 | public func handle(update: TGUpdate) async throws { 26 | try await callbackAsync(update) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputMediaAnimationType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputMediaAnimation](https://core.telegram.org/bots/api#inputmediaanimation) 8 | */ 9 | 10 | public enum TGInputMediaAnimationType: String, Codable, Sendable { 11 | case animation = "animation" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInputMediaAnimationType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGRevenueWithdrawalStatePending.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The withdrawal is in progress. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [RevenueWithdrawalStatePending](https://core.telegram.org/bots/api#revenuewithdrawalstatepending) 8 | **/ 9 | public final class TGRevenueWithdrawalStatePending: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `RevenueWithdrawalStatePending` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the state, always “pending” 17 | public let type: TGRevenueWithdrawalStatePendingType 18 | 19 | public init (type: TGRevenueWithdrawalStatePendingType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerOther.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with an unknown source or recipient. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerOther](https://core.telegram.org/bots/api#transactionpartnerother) 8 | **/ 9 | public final class TGTransactionPartnerOther: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `TransactionPartnerOther` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the transaction partner, always “other” 17 | public let type: TGTransactionPartnerOtherType 18 | 19 | public init (type: TGTransactionPartnerOtherType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGRevenueWithdrawalStateFailedType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The withdrawal failed and the transaction was refunded. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [RevenueWithdrawalStateFailed](https://core.telegram.org/bots/api#revenuewithdrawalstatefailed) 8 | */ 9 | 10 | public enum TGRevenueWithdrawalStateFailedType: String, Codable, Sendable { 11 | case failed = "failed" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGRevenueWithdrawalStateFailedType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGVideoChatParticipantsInvited.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about new members invited to a video chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [VideoChatParticipantsInvited](https://core.telegram.org/bots/api#videochatparticipantsinvited) 8 | **/ 9 | public final class TGVideoChatParticipantsInvited: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `VideoChatParticipantsInvited` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case users = "users" 14 | } 15 | 16 | /// New members that were invited to the video chat 17 | public let users: [TGUser] 18 | 19 | public init (users: [TGUser]) { 20 | self.users = users 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGRevenueWithdrawalStateFailed.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The withdrawal failed and the transaction was refunded. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [RevenueWithdrawalStateFailed](https://core.telegram.org/bots/api#revenuewithdrawalstatefailed) 8 | **/ 9 | public final class TGRevenueWithdrawalStateFailed: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `RevenueWithdrawalStateFailed` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the state, always “failed” 17 | public let type: TGRevenueWithdrawalStateFailedType 18 | 19 | public init (type: TGRevenueWithdrawalStateFailedType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeLocationType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area pointing to a location. Currently, a story can have up to 10 location areas. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeLocation](https://core.telegram.org/bots/api#storyareatypelocation) 8 | */ 9 | 10 | public enum TGStoryAreaTypeLocationType: String, Codable, Sendable { 11 | case location = "location" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGStoryAreaTypeLocationType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeWeatherType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area containing weather information. Currently, a story can have up to 3 weather areas. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeWeather](https://core.telegram.org/bots/api#storyareatypeweather) 8 | */ 9 | 10 | public enum TGStoryAreaTypeWeatherType: String, Codable, Sendable { 11 | case weather = "weather" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGStoryAreaTypeWeatherType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerTelegramApiType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with payment for paid broadcasting. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerTelegramApi](https://core.telegram.org/bots/api#transactionpartnertelegramapi) 8 | */ 9 | 10 | public enum TGTransactionPartnerTelegramApiType: String, Codable, Sendable { 11 | case telegramApi = "telegram_api" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerTelegramApiType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatFullInfoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object contains full information about a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatFullInfo](https://core.telegram.org/bots/api#chatfullinfo) 8 | */ 9 | 10 | public enum TGChatFullInfoType: String, Codable, Sendable { 11 | case `private` = "private" 12 | case group = "group" 13 | case supergroup = "supergroup" 14 | case channel = "channel" 15 | case undefined 16 | 17 | public init(from decoder: Decoder) throws { 18 | let value = try decoder.singleValueContainer().decode(String.self) 19 | guard let type = TGChatFullInfoType(rawValue: value) else { 20 | self = .undefined 21 | return 22 | } 23 | self = type 24 | } 25 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerTelegramAdsType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a withdrawal transaction to the Telegram Ads platform. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerTelegramAds](https://core.telegram.org/bots/api#transactionpartnertelegramads) 8 | */ 9 | 10 | public enum TGTransactionPartnerTelegramAdsType: String, Codable, Sendable { 11 | case telegramAds = "telegram_ads" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerTelegramAdsType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGVideoChatScheduled.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a video chat scheduled in the chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [VideoChatScheduled](https://core.telegram.org/bots/api#videochatscheduled) 8 | **/ 9 | public final class TGVideoChatScheduled: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `VideoChatScheduled` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case startDate = "start_date" 14 | } 15 | 16 | /// Point in time (Unix timestamp) when the video chat is supposed to be started by a chat administrator 17 | public let startDate: Int 18 | 19 | public init (startDate: Int) { 20 | self.startDate = startDate 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/TextFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filters messages to allow only those which contains text 10 | public class TextFilter: TGFilter { 11 | 12 | public var name: String = "text" 13 | private var value: String? = nil 14 | 15 | override 16 | public func filter(message: TGMessage) -> Bool { 17 | guard let text = message.text else { return false } 18 | if let value = value { 19 | return text == value 20 | } 21 | return !text.isEmpty 22 | } 23 | 24 | public func value(_ value: String) -> Self { 25 | self.value = value 26 | return self 27 | } 28 | } 29 | 30 | public extension TGFilter { 31 | static var text: TextFilter { TextFilter() } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeAllGroupChats.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all group and supergroup chats. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeAllGroupChats](https://core.telegram.org/bots/api#botcommandscopeallgroupchats) 8 | **/ 9 | public final class TGBotCommandScopeAllGroupChats: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotCommandScopeAllGroupChats` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Scope type, must be all_group_chats 17 | public let type: TGBotCommandScopeAllGroupChatsType 18 | 19 | public init (type: TGBotCommandScopeAllGroupChatsType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeChatMemberType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering a specific member of a group or supergroup chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeChatMember](https://core.telegram.org/bots/api#botcommandscopechatmember) 8 | */ 9 | 10 | public enum TGBotCommandScopeChatMemberType: String, Codable, Sendable { 11 | case chatMember = "chat_member" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeChatMemberType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaVideo.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media is a video. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaVideo](https://core.telegram.org/bots/api#paidmediavideo) 8 | **/ 9 | public final class TGPaidMediaVideo: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PaidMediaVideo` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case video = "video" 15 | } 16 | 17 | /// Type of the paid media, always “video” 18 | public let type: TGPaidMediaVideoType 19 | 20 | /// The video 21 | public let video: TGVideo 22 | 23 | public init (type: TGPaidMediaVideoType, video: TGVideo) { 24 | self.type = type 25 | self.video = video 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeUniqueGiftType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area pointing to a unique gift. Currently, a story can have at most 1 unique gift area. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeUniqueGift](https://core.telegram.org/bots/api#storyareatypeuniquegift) 8 | */ 9 | 10 | public enum TGStoryAreaTypeUniqueGiftType: String, Codable, Sendable { 11 | case uniqueGift = "unique_gift" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGStoryAreaTypeUniqueGiftType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeAllGroupChatsType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all group and supergroup chats. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeAllGroupChats](https://core.telegram.org/bots/api#botcommandscopeallgroupchats) 8 | */ 9 | 10 | public enum TGBotCommandScopeAllGroupChatsType: String, Codable, Sendable { 11 | case allGroupChats = "all_group_chats" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeAllGroupChatsType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeAllPrivateChats.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all private chats. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeAllPrivateChats](https://core.telegram.org/bots/api#botcommandscopeallprivatechats) 8 | **/ 9 | public final class TGBotCommandScopeAllPrivateChats: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotCommandScopeAllPrivateChats` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Scope type, must be all_private_chats 17 | public let type: TGBotCommandScopeAllPrivateChatsType 18 | 19 | public init (type: TGBotCommandScopeAllPrivateChatsType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeAllPrivateChatsType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all private chats. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeAllPrivateChats](https://core.telegram.org/bots/api#botcommandscopeallprivatechats) 8 | */ 9 | 10 | public enum TGBotCommandScopeAllPrivateChatsType: String, Codable, Sendable { 11 | case allPrivateChats = "all_private_chats" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeAllPrivateChatsType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeDefault.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the default scope of bot commands. Default commands are used if no commands with a narrower scope are specified for the user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeDefault](https://core.telegram.org/bots/api#botcommandscopedefault) 8 | **/ 9 | public final class TGBotCommandScopeDefault: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotCommandScopeDefault` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Scope type, must be default 17 | public let type: TGBotCommandScopeDefaultType 18 | 19 | public init (type: TGBotCommandScopeDefaultType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaPhoto.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media is a photo. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaPhoto](https://core.telegram.org/bots/api#paidmediaphoto) 8 | **/ 9 | public final class TGPaidMediaPhoto: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PaidMediaPhoto` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case photo = "photo" 15 | } 16 | 17 | /// Type of the paid media, always “photo” 18 | public let type: TGPaidMediaPhotoType 19 | 20 | /// The photo 21 | public let photo: [TGPhotoSize] 22 | 23 | public init (type: TGPaidMediaPhotoType, photo: [TGPhotoSize]) { 24 | self.type = type 25 | self.photo = photo 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryArea.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a clickable area on a story media. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryArea](https://core.telegram.org/bots/api#storyarea) 8 | **/ 9 | public final class TGStoryArea: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `StoryArea` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case position = "position" 14 | case type = "type" 15 | } 16 | 17 | /// Position of the area 18 | public let position: TGStoryAreaPosition 19 | 20 | /// Type of the area 21 | public let type: TGStoryAreaType 22 | 23 | public init (position: TGStoryAreaPosition, type: TGStoryAreaType) { 24 | self.position = position 25 | self.type = type 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerTelegramAds.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a withdrawal transaction to the Telegram Ads platform. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerTelegramAds](https://core.telegram.org/bots/api#transactionpartnertelegramads) 8 | **/ 9 | public final class TGTransactionPartnerTelegramAds: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `TransactionPartnerTelegramAds` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Type of the transaction partner, always “telegram_ads” 17 | public let type: TGTransactionPartnerTelegramAdsType 18 | 19 | public init (type: TGTransactionPartnerTelegramAdsType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeDefaultType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the default scope of bot commands. Default commands are used if no commands with a narrower scope are specified for the user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeDefault](https://core.telegram.org/bots/api#botcommandscopedefault) 8 | */ 9 | 10 | public enum TGBotCommandScopeDefaultType: String, Codable, Sendable { 11 | case `default` = "default" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeDefaultType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundFillFreeformGradientType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is a freeform gradient that rotates after every message in the chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundFillFreeformGradient](https://core.telegram.org/bots/api#backgroundfillfreeformgradient) 8 | */ 9 | 10 | public enum TGBackgroundFillFreeformGradientType: String, Codable, Sendable { 11 | case freeformGradient = "freeform_gradient" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundFillFreeformGradientType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGGiveawayCreated.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about the creation of a scheduled giveaway. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [GiveawayCreated](https://core.telegram.org/bots/api#giveawaycreated) 8 | **/ 9 | public final class TGGiveawayCreated: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `GiveawayCreated` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case prizeStarCount = "prize_star_count" 14 | } 15 | 16 | /// Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only 17 | public let prizeStarCount: Int? 18 | 19 | public init (prizeStarCount: Int? = nil) { 20 | self.prizeStarCount = prizeStarCount 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatBoostUpdated.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a boost added to a chat or changed. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatBoostUpdated](https://core.telegram.org/bots/api#chatboostupdated) 8 | **/ 9 | public final class TGChatBoostUpdated: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatBoostUpdated` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case chat = "chat" 14 | case boost = "boost" 15 | } 16 | 17 | /// Chat which was boosted 18 | public let chat: TGChat 19 | 20 | /// Information about the chat boost 21 | public let boost: TGChatBoost 22 | 23 | public init (chat: TGChat, boost: TGChatBoost) { 24 | self.chat = chat 25 | self.boost = boost 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGSentWebAppMessage.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes an inline message sent by a Web App on behalf of a user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [SentWebAppMessage](https://core.telegram.org/bots/api#sentwebappmessage) 8 | **/ 9 | public final class TGSentWebAppMessage: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `SentWebAppMessage` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case inlineMessageId = "inline_message_id" 14 | } 15 | 16 | /// Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. 17 | public let inlineMessageId: String? 18 | 19 | public init (inlineMessageId: String? = nil) { 20 | self.inlineMessageId = inlineMessageId 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundTypePatternType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is a .PNG or .TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundTypePattern](https://core.telegram.org/bots/api#backgroundtypepattern) 8 | */ 9 | 10 | public enum TGBackgroundTypePatternType: String, Codable, Sendable { 11 | case pattern = "pattern" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBackgroundTypePatternType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultVenueType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue) 8 | */ 9 | 10 | public enum TGInlineQueryResultVenueType: String, Codable, Sendable { 11 | case venue = "venue" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultVenueType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeSuggestedReactionType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area pointing to a suggested reaction. Currently, a story can have up to 5 suggested reaction areas. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeSuggestedReaction](https://core.telegram.org/bots/api#storyareatypesuggestedreaction) 8 | */ 9 | 10 | public enum TGStoryAreaTypeSuggestedReactionType: String, Codable, Sendable { 11 | case suggestedReaction = "suggested_reaction" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGStoryAreaTypeSuggestedReactionType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerAffiliateProgramType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes the affiliate program that issued the affiliate commission received via this transaction. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerAffiliateProgram](https://core.telegram.org/bots/api#transactionpartneraffiliateprogram) 8 | */ 9 | 10 | public enum TGTransactionPartnerAffiliateProgramType: String, Codable, Sendable { 11 | case affiliateProgram = "affiliate_program" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGTransactionPartnerAffiliateProgramType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeChatAdministratorsType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeChatAdministrators](https://core.telegram.org/bots/api#botcommandscopechatadministrators) 8 | */ 9 | 10 | public enum TGBotCommandScopeChatAdministratorsType: String, Codable, Sendable { 11 | case chatAdministrators = "chat_administrators" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeChatAdministratorsType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatMemberLeft.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a chat member that isn't currently a member of the chat, but may join it themselves. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatMemberLeft](https://core.telegram.org/bots/api#chatmemberleft) 8 | **/ 9 | public final class TGChatMemberLeft: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatMemberLeft` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case status = "status" 14 | case user = "user" 15 | } 16 | 17 | /// The member's status in the chat, always “left” 18 | public let status: String 19 | 20 | /// Information about the user 21 | public let user: TGUser 22 | 23 | public init (status: String, user: TGUser) { 24 | self.status = status 25 | self.user = user 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGDice.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents an animated emoji that displays a random value. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Dice](https://core.telegram.org/bots/api#dice) 8 | **/ 9 | public final class TGDice: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `Dice` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case emoji = "emoji" 14 | case value = "value" 15 | } 16 | 17 | /// Emoji on which the dice throw animation is based 18 | public let emoji: String 19 | 20 | /// Value of the dice, 1-6 for “”, “” and “” base emoji, 1-5 for “” and “” base emoji, 1-64 for “” base emoji 21 | public let value: Int 22 | 23 | public init (emoji: String, value: Int) { 24 | self.emoji = emoji 25 | self.value = value 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineKeyboardMarkup.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents an inline keyboard that appears right next to the message it belongs to. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) 8 | **/ 9 | public final class TGInlineKeyboardMarkup: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `InlineKeyboardMarkup` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case inlineKeyboard = "inline_keyboard" 14 | } 15 | 16 | /// Array of button rows, each represented by an Array of InlineKeyboardButton objects 17 | public let inlineKeyboard: [[TGInlineKeyboardButton]] 18 | 19 | public init (inlineKeyboard: [[TGInlineKeyboardButton]]) { 20 | self.inlineKeyboard = inlineKeyboard 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Helpers/SendableValue.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SendableValue.swift 3 | // SwiftTelegramSdk 4 | // 5 | // Created by Oleh Hudeichuk on 26.08.2025. 6 | // 7 | 8 | import Foundation 9 | 10 | public actor SendableValue { 11 | private var data: Value 12 | public init(_ val: Value) { 13 | self.data = val 14 | } 15 | 16 | public var value: Value { 17 | get { 18 | self.data 19 | } 20 | } 21 | 22 | @discardableResult 23 | public func change( 24 | _ block: @escaping @Sendable (inout Value) -> Void 25 | ) async -> Value { 26 | block(&data) 27 | return data 28 | } 29 | 30 | @discardableResult 31 | public func change( 32 | _ block: @escaping @Sendable (inout Value) throws -> Void 33 | ) async throws -> Value { 34 | try block(&data) 35 | return data 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeAllChatAdministratorsType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all group and supergroup chat administrators. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeAllChatAdministrators](https://core.telegram.org/bots/api#botcommandscopeallchatadministrators) 8 | */ 9 | 10 | public enum TGBotCommandScopeAllChatAdministratorsType: String, Codable, Sendable { 11 | case allChatAdministrators = "all_chat_administrators" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGBotCommandScopeAllChatAdministratorsType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGReactionCount.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a reaction added to a message along with the number of times it was added. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ReactionCount](https://core.telegram.org/bots/api#reactioncount) 8 | **/ 9 | public final class TGReactionCount: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ReactionCount` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case totalCount = "total_count" 15 | } 16 | 17 | /// Type of the reaction 18 | public let type: TGReactionType 19 | 20 | /// Number of times the reaction was added 21 | public let totalCount: Int 22 | 23 | public init (type: TGReactionType, totalCount: Int) { 24 | self.type = type 25 | self.totalCount = totalCount 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeAllChatAdministrators.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering all group and supergroup chat administrators. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeAllChatAdministrators](https://core.telegram.org/bots/api#botcommandscopeallchatadministrators) 8 | **/ 9 | public final class TGBotCommandScopeAllChatAdministrators: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotCommandScopeAllChatAdministrators` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Scope type, must be all_chat_administrators 17 | public let type: TGBotCommandScopeAllChatAdministratorsType 18 | 19 | public init (type: TGBotCommandScopeAllChatAdministratorsType) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageAutoDeleteTimerChanged.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about a change in auto-delete timer settings. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageAutoDeleteTimerChanged](https://core.telegram.org/bots/api#messageautodeletetimerchanged) 8 | **/ 9 | public final class TGMessageAutoDeleteTimerChanged: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `MessageAutoDeleteTimerChanged` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case messageAutoDeleteTime = "message_auto_delete_time" 14 | } 15 | 16 | /// New auto-delete time for messages in the chat; in seconds 17 | public let messageAutoDeleteTime: Int 18 | 19 | public init (messageAutoDeleteTime: Int) { 20 | self.messageAutoDeleteTime = messageAutoDeleteTime 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBusinessLocation.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Contains information about the location of a Telegram Business account. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BusinessLocation](https://core.telegram.org/bots/api#businesslocation) 8 | **/ 9 | public final class TGBusinessLocation: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BusinessLocation` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case address = "address" 14 | case location = "location" 15 | } 16 | 17 | /// Address of the business 18 | public let address: String 19 | 20 | /// Optional. Location of the business 21 | public let location: TGLocation? 22 | 23 | public init (address: String, location: TGLocation? = nil) { 24 | self.address = address 25 | self.location = location 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultAudioType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to an MP3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultAudio](https://core.telegram.org/bots/api#inlinequeryresultaudio) 8 | */ 9 | 10 | public enum TGInlineQueryResultAudioType: String, Codable, Sendable { 11 | case audio = "audio" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultAudioType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultPhotoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultPhoto](https://core.telegram.org/bots/api#inlinequeryresultphoto) 8 | */ 9 | 10 | public enum TGInlineQueryResultPhotoType: String, Codable, Sendable { 11 | case photo = "photo" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultPhotoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundFillSolid.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is filled using the selected color. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundFillSolid](https://core.telegram.org/bots/api#backgroundfillsolid) 8 | **/ 9 | public final class TGBackgroundFillSolid: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BackgroundFillSolid` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case color = "color" 15 | } 16 | 17 | /// Type of the background fill, always “solid” 18 | public let type: TGBackgroundFillSolidType 19 | 20 | /// The color of the background fill in the RGB24 format 21 | public let color: Int 22 | 23 | public init (type: TGBackgroundFillSolidType, color: Int) { 24 | self.type = type 25 | self.color = color 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultLocationType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation) 8 | */ 9 | 10 | public enum TGInlineQueryResultLocationType: String, Codable, Sendable { 11 | case location = "location" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultLocationType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultContactType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) 8 | */ 9 | 10 | public enum TGInlineQueryResultContactType: String, Codable, Sendable { 11 | case contact = "contact" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultContactType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageId.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a unique message identifier. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageId](https://core.telegram.org/bots/api#messageid) 8 | **/ 9 | public final class TGMessageId: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `MessageId` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case messageId = "message_id" 14 | } 15 | 16 | /// Unique message identifier. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent 17 | public let messageId: Int 18 | 19 | public init (messageId: Int) { 20 | self.messageId = messageId 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaInfo.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes the paid media added to a message. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaInfo](https://core.telegram.org/bots/api#paidmediainfo) 8 | **/ 9 | public final class TGPaidMediaInfo: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PaidMediaInfo` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case starCount = "star_count" 14 | case paidMedia = "paid_media" 15 | } 16 | 17 | /// The number of Telegram Stars that must be paid to buy access to the media 18 | public let starCount: Int 19 | 20 | /// Information about the paid media 21 | public let paidMedia: [TGPaidMedia] 22 | 23 | public init (starCount: Int, paidMedia: [TGPaidMedia]) { 24 | self.starCount = starCount 25 | self.paidMedia = paidMedia 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMediaPurchased.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object contains information about a paid media purchase. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMediaPurchased](https://core.telegram.org/bots/api#paidmediapurchased) 8 | **/ 9 | public final class TGPaidMediaPurchased: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PaidMediaPurchased` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case from = "from" 14 | case paidMediaPayload = "paid_media_payload" 15 | } 16 | 17 | /// User who purchased the media 18 | public let from: TGUser 19 | 20 | /// Bot-specified paid media payload 21 | public let paidMediaPayload: String 22 | 23 | public init (from: TGUser, paidMediaPayload: String) { 24 | self.from = from 25 | self.paidMediaPayload = paidMediaPayload 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultGifType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultGif](https://core.telegram.org/bots/api#inlinequeryresultgif) 8 | */ 9 | 10 | public enum TGInlineQueryResultGifType: String, Codable, Sendable { 11 | case gif = "gif" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultGifType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPaidMessagePriceChanged.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a service message about a change in the price of paid messages within a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PaidMessagePriceChanged](https://core.telegram.org/bots/api#paidmessagepricechanged) 8 | **/ 9 | public final class TGPaidMessagePriceChanged: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PaidMessagePriceChanged` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case paidMessageStarCount = "paid_message_star_count" 14 | } 15 | 16 | /// The new number of Telegram Stars that must be paid by non-administrator users of the supergroup chat for each sent message 17 | public let paidMessageStarCount: Int 18 | 19 | public init (paidMessageStarCount: Int) { 20 | self.paidMessageStarCount = paidMessageStarCount 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBirthdate.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes the birthdate of a user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [Birthdate](https://core.telegram.org/bots/api#birthdate) 8 | **/ 9 | public final class TGBirthdate: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `Birthdate` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case day = "day" 14 | case month = "month" 15 | case year = "year" 16 | } 17 | 18 | /// Day of the user's birth; 1-31 19 | public let day: Int 20 | 21 | /// Month of the user's birth; 1-12 22 | public let month: Int 23 | 24 | /// Optional. Year of the user's birth 25 | public let year: Int? 26 | 27 | public init (day: Int, month: Int, year: Int? = nil) { 28 | self.day = day 29 | self.month = month 30 | self.year = year 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGUserProfilePhotos.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represent a user's profile pictures. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [UserProfilePhotos](https://core.telegram.org/bots/api#userprofilephotos) 8 | **/ 9 | public final class TGUserProfilePhotos: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `UserProfilePhotos` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case totalCount = "total_count" 14 | case photos = "photos" 15 | } 16 | 17 | /// Total number of profile pictures the target user has 18 | public let totalCount: Int 19 | 20 | /// Requested profile pictures (in up to 4 sizes each) 21 | public let photos: [[TGPhotoSize]] 22 | 23 | public init (totalCount: Int, photos: [[TGPhotoSize]]) { 24 | self.totalCount = totalCount 25 | self.photos = photos 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommand.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a bot command. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommand](https://core.telegram.org/bots/api#botcommand) 8 | **/ 9 | public final class TGBotCommand: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotCommand` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case command = "command" 14 | case description = "description" 15 | } 16 | 17 | /// Text of the command; 1-32 characters. Can contain only lowercase English letters, digits and underscores. 18 | public let command: String 19 | 20 | /// Description of the command; 1-256 characters. 21 | public let description: String 22 | 23 | public init (command: String, description: String) { 24 | self.command = command 25 | self.description = description 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatLocation.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a location to which a chat is connected. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatLocation](https://core.telegram.org/bots/api#chatlocation) 8 | **/ 9 | public final class TGChatLocation: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatLocation` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case location = "location" 14 | case address = "address" 15 | } 16 | 17 | /// The location to which the supergroup is connected. Can't be a live location. 18 | public let location: TGLocation 19 | 20 | /// Location address; 1-64 characters, as defined by the chat owner 21 | public let address: String 22 | 23 | public init (location: TGLocation, address: String) { 24 | self.location = location 25 | self.address = address 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatBoostSourcePremium.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The boost was obtained by subscribing to Telegram Premium or by gifting a Telegram Premium subscription to another user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatBoostSourcePremium](https://core.telegram.org/bots/api#chatboostsourcepremium) 8 | **/ 9 | public final class TGChatBoostSourcePremium: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatBoostSourcePremium` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case source = "source" 14 | case user = "user" 15 | } 16 | 17 | /// Source of the boost, always “premium” 18 | public let source: String 19 | 20 | /// User that boosted the chat 21 | public let user: TGUser 22 | 23 | public init (source: String, user: TGUser) { 24 | self.source = source 25 | self.user = user 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeLink.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area pointing to an HTTP or tg:// link. Currently, a story can have up to 3 link areas. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeLink](https://core.telegram.org/bots/api#storyareatypelink) 8 | **/ 9 | public final class TGStoryAreaTypeLink: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `StoryAreaTypeLink` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case url = "url" 15 | } 16 | 17 | /// Type of the area, always “link” 18 | public let type: TGStoryAreaTypeLinkType 19 | 20 | /// HTTP or tg:// URL to be opened when the area is clicked 21 | public let url: String 22 | 23 | public init (type: TGStoryAreaTypeLinkType, url: String) { 24 | self.type = type 25 | self.url = url 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGUsersShared.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object contains information about the users whose identifiers were shared with the bot using a KeyboardButtonRequestUsers button. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [UsersShared](https://core.telegram.org/bots/api#usersshared) 8 | **/ 9 | public final class TGUsersShared: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `UsersShared` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case requestId = "request_id" 14 | case users = "users" 15 | } 16 | 17 | /// Identifier of the request 18 | public let requestId: Int 19 | 20 | /// Information about users shared with the bot. 21 | public let users: [TGSharedUser] 22 | 23 | public init (requestId: Int, users: [TGSharedUser]) { 24 | self.requestId = requestId 25 | self.users = users 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Examples/Hummingbird-URLSession-Telegram-Bot/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:6.0 2 | 3 | import PackageDescription 4 | 5 | let packageDependencies: [Package.Dependency] = [ 6 | .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-alpha.1"), 7 | .package(url: "https://github.com/nerzh/swift-telegram-bot.git", .upToNextMajor(from: "4.2.0")) 8 | ] 9 | 10 | let targetDependencies: [PackageDescription.Target.Dependency] = [ 11 | .product(name: "Hummingbird", package: "hummingbird"), 12 | .product(name: "SwiftTelegramBot", package: "swift-telegram-bot") 13 | ] 14 | 15 | let package = Package( 16 | name: "Hummingbird-URLSession-Telegram-Bot", 17 | platforms: [ 18 | .macOS(.v14) 19 | ], 20 | dependencies: packageDependencies, 21 | targets: [ 22 | .executableTarget( 23 | name: "Hummingbird-URLSession-Telegram-Bot", 24 | dependencies: targetDependencies 25 | ) 26 | ] 27 | ) 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportElementErrorReverseSideType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an issue with the reverse side of a document. The error is considered resolved when the file with reverse side of the document changes. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportElementErrorReverseSide](https://core.telegram.org/bots/api#passportelementerrorreverseside) 8 | */ 9 | 10 | public enum TGPassportElementErrorReverseSideType: String, Codable, Sendable { 11 | case driverLicense = "driver_license" 12 | case identityCard = "identity_card" 13 | case undefined 14 | 15 | public init(from decoder: Decoder) throws { 16 | let value = try decoder.singleValueContainer().decode(String.self) 17 | guard let type = TGPassportElementErrorReverseSideType(rawValue: value) else { 18 | self = .undefined 19 | return 20 | } 21 | self = type 22 | } 23 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultVoiceType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a voice recording in an .OGG container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) 8 | */ 9 | 10 | public enum TGInlineQueryResultVoiceType: String, Codable, Sendable { 11 | case voice = "voice" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultVoiceType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGKeyboardButtonPollType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [KeyboardButtonPollType](https://core.telegram.org/bots/api#keyboardbuttonpolltype) 8 | **/ 9 | public final class TGKeyboardButtonPollType: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `KeyboardButtonPollType` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | } 15 | 16 | /// Optional. If quiz is passed, the user will be allowed to create only polls in the quiz mode. If regular is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type. 17 | public let type: String? 18 | 19 | public init (type: String? = nil) { 20 | self.type = type 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGReactionTypeCustomEmoji.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The reaction is based on a custom emoji. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ReactionTypeCustomEmoji](https://core.telegram.org/bots/api#reactiontypecustomemoji) 8 | **/ 9 | public final class TGReactionTypeCustomEmoji: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ReactionTypeCustomEmoji` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case customEmojiId = "custom_emoji_id" 15 | } 16 | 17 | /// Type of the reaction, always “custom_emoji” 18 | public let type: TGReactionTypeCustomEmojiType 19 | 20 | /// Custom emoji identifier 21 | public let customEmojiId: String 22 | 23 | public init (type: TGReactionTypeCustomEmojiType, customEmojiId: String) { 24 | self.type = type 25 | self.customEmojiId = customEmojiId 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/LanguageFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filters messages to only allow those which are from users with a certain language code. 10 | /// 11 | /// Note: According to telegrams documentation, every single user does not have the language_code attribute. 12 | public class LanguageFilter: TGFilter { 13 | 14 | var lang: String 15 | 16 | public init(lang: String) { 17 | self.lang = lang 18 | super.init() 19 | } 20 | 21 | public var name: String = "language" 22 | 23 | override 24 | public func filter(message: TGMessage) -> Bool { 25 | guard let languageCode = message.from?.languageCode else { return true } 26 | return languageCode.starts(with: lang) 27 | } 28 | } 29 | 30 | public extension TGFilter { 31 | static func language(_ lang: String) -> LanguageFilter { 32 | return LanguageFilter(lang: lang) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGGameHighScore.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents one row of the high scores table for a game. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [GameHighScore](https://core.telegram.org/bots/api#gamehighscore) 8 | **/ 9 | public final class TGGameHighScore: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `GameHighScore` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case position = "position" 14 | case user = "user" 15 | case score = "score" 16 | } 17 | 18 | /// Position in high score table for the game 19 | public let position: Int 20 | 21 | /// User 22 | public let user: TGUser 23 | 24 | /// Score 25 | public let score: Int 26 | 27 | public init (position: Int, user: TGUser, score: Int) { 28 | self.position = position 29 | self.user = user 30 | self.score = score 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedAudioType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to an MP3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedAudio](https://core.telegram.org/bots/api#inlinequeryresultcachedaudio) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedAudioType: String, Codable, Sendable { 11 | case audio = "audio" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedAudioType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGShippingOption.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents one shipping option. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ShippingOption](https://core.telegram.org/bots/api#shippingoption) 8 | **/ 9 | public final class TGShippingOption: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ShippingOption` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case id = "id" 14 | case title = "title" 15 | case prices = "prices" 16 | } 17 | 18 | /// Shipping option identifier 19 | public let id: String 20 | 21 | /// Option title 22 | public let title: String 23 | 24 | /// List of price portions 25 | public let prices: [TGLabeledPrice] 26 | 27 | public init (id: String, title: String, prices: [TGLabeledPrice]) { 28 | self.id = id 29 | self.title = title 30 | self.prices = prices 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStoryAreaTypeUniqueGift.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a story area pointing to a unique gift. Currently, a story can have at most 1 unique gift area. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StoryAreaTypeUniqueGift](https://core.telegram.org/bots/api#storyareatypeuniquegift) 8 | **/ 9 | public final class TGStoryAreaTypeUniqueGift: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `StoryAreaTypeUniqueGift` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case name = "name" 15 | } 16 | 17 | /// Type of the area, always “unique_gift” 18 | public let type: TGStoryAreaTypeUniqueGiftType 19 | 20 | /// Unique name of the gift 21 | public let name: String 22 | 23 | public init (type: TGStoryAreaTypeUniqueGiftType, name: String) { 24 | self.type = type 25 | self.name = name 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Examples/FlyingFox-AsyncHttpClient-Telegram-Bot/Sources/FlyingFox-AsyncHttpClient-Telegram-Bot/Controllers/TelegramController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramController.swift 3 | // FlyingFox-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 10.03.2023. 6 | // 7 | 8 | import Foundation 9 | import FlyingFox 10 | import SwiftTelegramBot 11 | 12 | final class TelegramController { 13 | func addRoutes(to group: FlyingFox.HTTPRoute) async { 14 | await server.appendRoute("/telegramWebHook") { request in 15 | do { 16 | let body = try await request.bodyData 17 | let update = try JSONDecoder().decode(TGUpdate.self, from: body) 18 | Task { 19 | await appContext.botActor.bot.processing(updates: [update]) 20 | } 21 | } catch { 22 | return HTTPResponse(statusCode: .badRequest) 23 | } 24 | return HTTPResponse(statusCode: .ok) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/EntityFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filters messages to only allow those which have a `MessageEntity` where their type matches `type`. 10 | public class EntityFilter: TGFilter { 11 | 12 | let entityTypes: Set 13 | 14 | public init(types: [TGMessageEntityType]) { 15 | self.entityTypes = Set(types) 16 | super.init() 17 | } 18 | 19 | public var name: String = "entity" 20 | 21 | override 22 | public func filter(message: TGMessage) -> Bool { 23 | guard let entities = message.entities else { return false } 24 | let incomingTypes = entities.map { $0.type } 25 | return !entityTypes.isDisjoint(with: incomingTypes) 26 | } 27 | } 28 | 29 | public extension TGFilter { 30 | static func entity(types: [TGMessageEntityType]) -> EntityFilter { 31 | return EntityFilter(types: types) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedStickerType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedSticker](https://core.telegram.org/bots/api#inlinequeryresultcachedsticker) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedStickerType: String, Codable, Sendable { 11 | case sticker = "sticker" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedStickerType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedPhotoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedPhoto](https://core.telegram.org/bots/api#inlinequeryresultcachedphoto) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedPhotoType: String, Codable, Sendable { 11 | case photo = "photo" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedPhotoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedVoiceType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedVoice](https://core.telegram.org/bots/api#inlinequeryresultcachedvoice) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedVoiceType: String, Codable, Sendable { 11 | case voice = "voice" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedVoiceType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundTypeChatTheme.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is taken directly from a built-in chat theme. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundTypeChatTheme](https://core.telegram.org/bots/api#backgroundtypechattheme) 8 | **/ 9 | public final class TGBackgroundTypeChatTheme: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BackgroundTypeChatTheme` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case themeName = "theme_name" 15 | } 16 | 17 | /// Type of the background, always “chat_theme” 18 | public let type: TGBackgroundTypeChatThemeType 19 | 20 | /// Name of the chat theme, which is usually an emoji 21 | public let themeName: String 22 | 23 | public init (type: TGBackgroundTypeChatThemeType, themeName: String) { 24 | self.type = type 25 | self.themeName = themeName 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGWebAppData.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes data sent from a Web App to the bot. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [WebAppData](https://core.telegram.org/bots/api#webappdata) 8 | **/ 9 | public final class TGWebAppData: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `WebAppData` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case data = "data" 14 | case buttonText = "button_text" 15 | } 16 | 17 | /// The data. Be aware that a bad client can send arbitrary data in this field. 18 | public let data: String 19 | 20 | /// Text of the web_app keyboard button from which the Web App was opened. Be aware that a bad client can send arbitrary data in this field. 21 | public let buttonText: String 22 | 23 | public init (data: String, buttonText: String) { 24 | self.data = data 25 | self.buttonText = buttonText 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedGifType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedGif](https://core.telegram.org/bots/api#inlinequeryresultcachedgif) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedGifType: String, Codable, Sendable { 11 | case gif = "gif" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedGifType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedVideoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedVideo](https://core.telegram.org/bots/api#inlinequeryresultcachedvideo) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedVideoType: String, Codable, Sendable { 11 | case video = "video" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedVideoType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedDocumentType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedDocument](https://core.telegram.org/bots/api#inlinequeryresultcacheddocument) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedDocumentType: String, Codable, Sendable { 11 | case document = "document" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedDocumentType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportElementErrorSelfieType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportElementErrorSelfie](https://core.telegram.org/bots/api#passportelementerrorselfie) 8 | */ 9 | 10 | public enum TGPassportElementErrorSelfieType: String, Codable, Sendable { 11 | case passport = "passport" 12 | case driverLicense = "driver_license" 13 | case identityCard = "identity_card" 14 | case internalPassport = "internal_passport" 15 | case undefined 16 | 17 | public init(from decoder: Decoder) throws { 18 | let value = try decoder.singleValueContainer().decode(String.self) 19 | guard let type = TGPassportElementErrorSelfieType(rawValue: value) else { 20 | self = .undefined 21 | return 22 | } 23 | self = type 24 | } 25 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPreparedInlineMessage.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes an inline message to be sent by a user of a Mini App. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PreparedInlineMessage](https://core.telegram.org/bots/api#preparedinlinemessage) 8 | **/ 9 | public final class TGPreparedInlineMessage: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PreparedInlineMessage` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case id = "id" 14 | case expirationDate = "expiration_date" 15 | } 16 | 17 | /// Unique identifier of the prepared message 18 | public let id: String 19 | 20 | /// Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used 21 | public let expirationDate: Int 22 | 23 | public init (id: String, expirationDate: Int) { 24 | self.id = id 25 | self.expirationDate = expirationDate 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultDocumentType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) 8 | */ 9 | 10 | public enum TGInlineQueryResultDocumentType: String, Codable, Sendable { 11 | case document = "document" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultDocumentType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultMpeg4GifType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif) 8 | */ 9 | 10 | public enum TGInlineQueryResultMpeg4GifType: String, Codable, Sendable { 11 | case mpeg4Gif = "mpeg4_gif" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultMpeg4GifType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGStarAmount.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes an amount of Telegram Stars. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [StarAmount](https://core.telegram.org/bots/api#staramount) 8 | **/ 9 | public final class TGStarAmount: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `StarAmount` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case amount = "amount" 14 | case nanostarAmount = "nanostar_amount" 15 | } 16 | 17 | /// Integer amount of Telegram Stars, rounded to 0; can be negative 18 | public let amount: Int 19 | 20 | /// Optional. The number of 1/1000000000 shares of Telegram Stars; from -999999999 to 999999999; can be negative if and only if amount is non-positive 21 | public let nanostarAmount: Int? 22 | 23 | public init (amount: Int, nanostarAmount: Int? = nil) { 24 | self.amount = amount 25 | self.nanostarAmount = nanostarAmount 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/CaptionEntityFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filters media messages to only allow those which have a `MessageEntity` where their type matches `type`. 10 | public class CaptionEntityFilter: TGFilter { 11 | 12 | var entityType: TGMessageEntityType 13 | 14 | public init(type: TGMessageEntityType) { 15 | self.entityType = type 16 | super.init() 17 | } 18 | 19 | public var name: String = "caption_entity" 20 | 21 | override 22 | public func filter(message: TGMessage) -> Bool { 23 | guard let entities = message.entities else { return false } 24 | return entities.contains(where: { (entity) -> Bool in 25 | return entity.type == entityType 26 | }) 27 | } 28 | } 29 | 30 | public extension TGFilter { 31 | static func captionEntity(type: TGMessageEntityType) -> CaptionEntityFilter { 32 | return CaptionEntityFilter(type: type) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Types/MessageOrBool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MessageOrBool.swift 3 | // App 4 | // 5 | // Created by Givi Pataridze on 28.02.2018. 6 | // 7 | 8 | /// Sometimes bot methods returns objects On success, otherwise returns False 9 | public enum TGMessageOrBool: Codable, Sendable { 10 | case message(TGMessage) 11 | case bool(Bool) 12 | 13 | public func encode(to encoder: Encoder) throws { 14 | var container = encoder.singleValueContainer() 15 | switch self { 16 | case .bool(let value): 17 | try container.encode(value) 18 | case .message(let message): 19 | try container.encode(message) 20 | } 21 | } 22 | 23 | public init(from decoder: Decoder) throws { 24 | if let value = try? decoder.singleValueContainer().decode(Bool.self) { 25 | self = .bool(value) 26 | } else { 27 | let message = try decoder.singleValueContainer().decode(TGMessage.self) 28 | self = .message(message) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportElementErrorFrontSideType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an issue with the front side of a document. The error is considered resolved when the file with the front side of the document changes. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportElementErrorFrontSide](https://core.telegram.org/bots/api#passportelementerrorfrontside) 8 | */ 9 | 10 | public enum TGPassportElementErrorFrontSideType: String, Codable, Sendable { 11 | case passport = "passport" 12 | case driverLicense = "driver_license" 13 | case identityCard = "identity_card" 14 | case internalPassport = "internal_passport" 15 | case undefined 16 | 17 | public init(from decoder: Decoder) throws { 18 | let value = try decoder.singleValueContainer().decode(String.self) 19 | guard let type = TGPassportElementErrorFrontSideType(rawValue: value) else { 20 | self = .undefined 21 | return 22 | } 23 | self = type 24 | } 25 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatBoostSourceGiftCode.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The boost was obtained by the creation of Telegram Premium gift codes to boost a chat. Each such code boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatBoostSourceGiftCode](https://core.telegram.org/bots/api#chatboostsourcegiftcode) 8 | **/ 9 | public final class TGChatBoostSourceGiftCode: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatBoostSourceGiftCode` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case source = "source" 14 | case user = "user" 15 | } 16 | 17 | /// Source of the boost, always “gift_code” 18 | public let source: String 19 | 20 | /// User for which the gift code was created 21 | public let user: TGUser 22 | 23 | public init (source: String, user: TGUser) { 24 | self.source = source 25 | self.user = user 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportData.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes Telegram Passport data shared with the bot by the user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportData](https://core.telegram.org/bots/api#passportdata) 8 | **/ 9 | public final class TGPassportData: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `PassportData` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case data = "data" 14 | case credentials = "credentials" 15 | } 16 | 17 | /// Array with information about documents and other Telegram Passport elements that was shared with the bot 18 | public let data: [TGEncryptedPassportElement] 19 | 20 | /// Encrypted credentials required to decrypt the data 21 | public let credentials: TGEncryptedCredentials 22 | 23 | public init (data: [TGEncryptedPassportElement], credentials: TGEncryptedCredentials) { 24 | self.data = data 25 | self.credentials = credentials 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBotCommandScopeChat.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents the scope of bot commands, covering a specific chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BotCommandScopeChat](https://core.telegram.org/bots/api#botcommandscopechat) 8 | **/ 9 | public final class TGBotCommandScopeChat: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BotCommandScopeChat` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case chatId = "chat_id" 15 | } 16 | 17 | /// Scope type, must be chat 18 | public let type: TGBotCommandScopeChatType 19 | 20 | /// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername). Channel direct messages chats and channel chats aren't supported. 21 | public let chatId: TGChatId 22 | 23 | public init (type: TGBotCommandScopeChatType, chatId: TGChatId) { 24 | self.type = type 25 | self.chatId = chatId 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Types/ParseMode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ParseMode.swift 3 | // Telegrammer 4 | // 5 | // Created by Givi Pataridze on 17/06/2018. 6 | // 7 | 8 | import Foundation 9 | 10 | /** Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. 11 | 12 | SeeAlso Telegram TGBot API Reference: 13 | [Formatting Options](https://core.telegram.org/bots/api#formatting-options) 14 | */ 15 | public enum TGParseMode: String, Codable, Sendable { 16 | case markdownV2 = "MarkdownV2" 17 | @available(*, deprecated, message: "This is a legacy mode, retained for backward compatibility.", renamed: "markdownV2") 18 | case markdown = "Markdown" 19 | case html = "HTML" 20 | case undefined 21 | 22 | public init(from decoder: Decoder) throws { 23 | let value = try decoder.singleValueContainer().decode(String.self) 24 | guard let type = TGParseMode(rawValue: value) else { 25 | self = .undefined 26 | return 27 | } 28 | self = type 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Types/TelegramContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TelegramContainer.swift 3 | // App 4 | // 5 | // Created by Givi Pataridze on 25.02.2018. 6 | // 7 | import Foundation 8 | /// This object represents a Telegram server response container. 9 | public struct TGTelegramContainer: Decodable { 10 | 11 | enum CodingKeys: String, CodingKey { 12 | case ok = "ok" 13 | case result = "result" 14 | case description = "description" 15 | case errorCode = "error_code" 16 | case parameters = "parameters" 17 | } 18 | 19 | public let ok: Bool 20 | public let result: T? 21 | public let description: String? 22 | public let errorCode: Int? 23 | public let parameters: TGResponseParameters? 24 | 25 | public init (ok: Bool, result: T?, description: String?, errorCode: Int?, parameters: TGResponseParameters?) { 26 | self.ok = ok 27 | self.result = result 28 | self.description = description 29 | self.errorCode = errorCode 30 | self.parameters = parameters 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBusinessOpeningHours.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes the opening hours of a business. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BusinessOpeningHours](https://core.telegram.org/bots/api#businessopeninghours) 8 | **/ 9 | public final class TGBusinessOpeningHours: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BusinessOpeningHours` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case timeZoneName = "time_zone_name" 14 | case openingHours = "opening_hours" 15 | } 16 | 17 | /// Unique name of the time zone for which the opening hours are defined 18 | public let timeZoneName: String 19 | 20 | /// List of time intervals describing business opening hours 21 | public let openingHours: [TGBusinessOpeningHoursInterval] 22 | 23 | public init (timeZoneName: String, openingHours: [TGBusinessOpeningHoursInterval]) { 24 | self.timeZoneName = timeZoneName 25 | self.openingHours = openingHours 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGForumTopicEdited.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a service message about an edited forum topic. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ForumTopicEdited](https://core.telegram.org/bots/api#forumtopicedited) 8 | **/ 9 | public final class TGForumTopicEdited: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ForumTopicEdited` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case name = "name" 14 | case iconCustomEmojiId = "icon_custom_emoji_id" 15 | } 16 | 17 | /// Optional. New name of the topic, if it was edited 18 | public let name: String? 19 | 20 | /// Optional. New identifier of the custom emoji shown as the topic icon, if it was edited; an empty string if the icon was removed 21 | public let iconCustomEmojiId: String? 22 | 23 | public init (name: String? = nil, iconCustomEmojiId: String? = nil) { 24 | self.name = name 25 | self.iconCustomEmojiId = iconCustomEmojiId 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportElementErrorFileType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportElementErrorFile](https://core.telegram.org/bots/api#passportelementerrorfile) 8 | */ 9 | 10 | public enum TGPassportElementErrorFileType: String, Codable, Sendable { 11 | case utilityBill = "utility_bill" 12 | case bankStatement = "bank_statement" 13 | case rentalAgreement = "rental_agreement" 14 | case passportRegistration = "passport_registration" 15 | case temporaryRegistration = "temporary_registration" 16 | case undefined 17 | 18 | public init(from decoder: Decoder) throws { 19 | let value = try decoder.singleValueContainer().decode(String.self) 20 | guard let type = TGPassportElementErrorFileType(rawValue: value) else { 21 | self = .undefined 22 | return 23 | } 24 | self = type 25 | } 26 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultCachedMpeg4GifType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InlineQueryResultCachedMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif) 8 | */ 9 | 10 | public enum TGInlineQueryResultCachedMpeg4GifType: String, Codable, Sendable { 11 | case mpeg4Gif = "mpeg4_gif" 12 | case undefined 13 | 14 | public init(from decoder: Decoder) throws { 15 | let value = try decoder.singleValueContainer().decode(String.self) 16 | guard let type = TGInlineQueryResultCachedMpeg4GifType(rawValue: value) else { 17 | self = .undefined 18 | return 19 | } 20 | self = type 21 | } 22 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportElementErrorFilesType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportElementErrorFiles](https://core.telegram.org/bots/api#passportelementerrorfiles) 8 | */ 9 | 10 | public enum TGPassportElementErrorFilesType: String, Codable, Sendable { 11 | case utilityBill = "utility_bill" 12 | case bankStatement = "bank_statement" 13 | case rentalAgreement = "rental_agreement" 14 | case passportRegistration = "passport_registration" 15 | case temporaryRegistration = "temporary_registration" 16 | case undefined 17 | 18 | public init(from decoder: Decoder) throws { 19 | let value = try decoder.singleValueContainer().decode(String.self) 20 | guard let type = TGPassportElementErrorFilesType(rawValue: value) else { 21 | self = .undefined 22 | return 23 | } 24 | self = type 25 | } 26 | } -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/Sources/Smoke-AsyncHttpClient-Telegram-Bot/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // Smoke-AsyncHttpClient-bot-example 4 | // 5 | // Created by Oleh Hudeichuk on 21.05.2021. 6 | // 7 | 8 | import SmokeOperationsHTTP1Server 9 | import Foundation 10 | import Logging 11 | import NIO 12 | import SmokeHTTP1 13 | 14 | do { 15 | let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) 16 | let initializer = try TelegramPerInvocationContextInitializer(eventLoopGroup: eventLoopGroup) 17 | let logger = Logger(label: "SmokeServer") 18 | let traceContext = SmokeInvocationTraceContext() 19 | let reporting = SmokeServerInvocationReporting(logger: logger, internalRequestId: UUID().uuidString, traceContext: traceContext) 20 | let context = initializer.getInvocationContext(invocationReporting: reporting) 21 | 22 | try await configure(appContext: context) 23 | 24 | SmokeHTTP1Server.runAsOperationServer(TelegramPerInvocationContextInitializer.init) 25 | } catch { 26 | print("Error starting server: \(error)") 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGLabeledPrice.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object represents a portion of the price for goods or services. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [LabeledPrice](https://core.telegram.org/bots/api#labeledprice) 8 | **/ 9 | public final class TGLabeledPrice: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `LabeledPrice` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case label = "label" 14 | case amount = "amount" 15 | } 16 | 17 | /// Portion label 18 | public let label: String 19 | 20 | /// Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). 21 | public let amount: Int 22 | 23 | public init (label: String, amount: Int) { 24 | self.label = label 25 | self.amount = amount 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerChat.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerChat](https://core.telegram.org/bots/api#transactionpartnerchat) 8 | **/ 9 | public final class TGTransactionPartnerChat: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `TransactionPartnerChat` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case chat = "chat" 15 | case gift = "gift" 16 | } 17 | 18 | /// Type of the transaction partner, always “chat” 19 | public let type: TGTransactionPartnerChatType 20 | 21 | /// Information about the chat 22 | public let chat: TGChat 23 | 24 | /// Optional. The gift sent to the chat by the bot 25 | public let gift: TGGift? 26 | 27 | public init (type: TGTransactionPartnerChatType, chat: TGChat, gift: TGGift? = nil) { 28 | self.type = type 29 | self.chat = chat 30 | self.gift = gift 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerTelegramApi.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a transaction with payment for paid broadcasting. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerTelegramApi](https://core.telegram.org/bots/api#transactionpartnertelegramapi) 8 | **/ 9 | public final class TGTransactionPartnerTelegramApi: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `TransactionPartnerTelegramApi` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case requestCount = "request_count" 15 | } 16 | 17 | /// Type of the transaction partner, always “telegram_api” 18 | public let type: TGTransactionPartnerTelegramApiType 19 | 20 | /// The number of successful requests that exceeded regular limits and were therefore billed 21 | public let requestCount: Int 22 | 23 | public init (type: TGTransactionPartnerTelegramApiType, requestCount: Int) { 24 | self.type = type 25 | self.requestCount = requestCount 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Filters/ChatFilter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by Oleh Hudeichuk on 02.06.2021. 5 | // 6 | 7 | import Foundation 8 | 9 | /// Filters messages to allow only those which are from specified chat ID. 10 | public class ChatFilter: TGFilter { 11 | 12 | var chatId: Int64 13 | var username: String? 14 | 15 | public init(chatId: Int64, username: String? = nil) { 16 | self.chatId = chatId 17 | self.username = username 18 | super.init() 19 | } 20 | 21 | public var name: String = "chat" 22 | 23 | override 24 | public func filter(message: TGMessage) -> Bool { 25 | guard message.chat.id == chatId else { return false } 26 | guard let desiredUsername = username else { return true } 27 | guard let incomingUsername = message.chat.username else { return true } 28 | return desiredUsername == incomingUsername 29 | } 30 | } 31 | 32 | public extension TGFilter { 33 | static func chat(chatId: Int64, username: String? = nil) -> ChatFilter { 34 | return ChatFilter(chatId: chatId, username: username) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGMessageOriginUser.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The message was originally sent by a known user. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [MessageOriginUser](https://core.telegram.org/bots/api#messageoriginuser) 8 | **/ 9 | public final class TGMessageOriginUser: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `MessageOriginUser` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case date = "date" 15 | case senderUser = "sender_user" 16 | } 17 | 18 | /// Type of the message origin, always “user” 19 | public let type: TGMessageOriginUserType 20 | 21 | /// Date the message was sent originally in Unix time 22 | public let date: Int 23 | 24 | /// User that sent the message originally 25 | public let senderUser: TGUser 26 | 27 | public init (type: TGMessageOriginUserType, date: Int, senderUser: TGUser) { 28 | self.type = type 29 | self.date = date 30 | self.senderUser = senderUser 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBackgroundFillFreeformGradient.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The background is a freeform gradient that rotates after every message in the chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BackgroundFillFreeformGradient](https://core.telegram.org/bots/api#backgroundfillfreeformgradient) 8 | **/ 9 | public final class TGBackgroundFillFreeformGradient: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BackgroundFillFreeformGradient` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case colors = "colors" 15 | } 16 | 17 | /// Type of the background fill, always “freeform_gradient” 18 | public let type: TGBackgroundFillFreeformGradientType 19 | 20 | /// A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format 21 | public let colors: [Int] 22 | 23 | public init (type: TGBackgroundFillFreeformGradientType, colors: [Int]) { 24 | self.type = type 25 | self.colors = colors 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGTransactionPartnerFragment.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a withdrawal transaction with Fragment. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [TransactionPartnerFragment](https://core.telegram.org/bots/api#transactionpartnerfragment) 8 | **/ 9 | public final class TGTransactionPartnerFragment: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `TransactionPartnerFragment` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case withdrawalState = "withdrawal_state" 15 | } 16 | 17 | /// Type of the transaction partner, always “fragment” 18 | public let type: TGTransactionPartnerFragmentType 19 | 20 | /// Optional. State of the transaction if the transaction is outgoing 21 | public let withdrawalState: TGRevenueWithdrawalState? 22 | 23 | public init (type: TGTransactionPartnerFragmentType, withdrawalState: TGRevenueWithdrawalState? = nil) { 24 | self.type = type 25 | self.withdrawalState = withdrawalState 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Methods/GetMe.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | import Foundation 4 | 5 | /// DESCRIPTION: 6 | /// A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object. 7 | 8 | 9 | 10 | public extension TGBot { 11 | /** 12 | A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object. 13 | 14 | SeeAlso Telegram Bot API Reference: 15 | [GetMeParams](https://core.telegram.org/bots/api#getme) 16 | 17 | - Parameters: 18 | - params: Parameters container, see `GetMeParams` struct 19 | - Throws: Throws on errors 20 | - Returns: `TGUser` 21 | */ 22 | 23 | @discardableResult 24 | func getMe() async throws -> TGUser { 25 | guard let methodURL: URL = .init(string: getMethodURL("getMe")) else { 26 | throw BotError("Bad URL: \(getMethodURL("getMe"))") 27 | } 28 | let result: TGUser = try await tgClient.post(methodURL) 29 | return result 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Examples/Smoke-AsyncHttpClient-Telegram-Bot/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:6.0 2 | 3 | import PackageDescription 4 | 5 | let packageDependencies: [Package.Dependency] = [ 6 | .package(url: "https://github.com/amzn/smoke-framework.git", from: "2.0.0"), 7 | .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.6.0"), 8 | .package(url: "https://github.com/nerzh/swift-telegram-bot", .upToNextMajor(from: "4.2.0")) 9 | ] 10 | 11 | let targetDependencies: [PackageDescription.Target.Dependency] = [ 12 | .product(name: "SmokeOperationsHTTP1Server", package: "smoke-framework"), 13 | .product(name: "AsyncHTTPClient", package: "async-http-client"), 14 | .product(name: "SwiftTelegramBot", package: "swift-telegram-bot") 15 | ] 16 | 17 | let package = Package( 18 | name: "Smoke-AsyncHttpClient-Telegram-Bot", 19 | platforms: [ 20 | .macOS(.v14) 21 | ], 22 | dependencies: packageDependencies, 23 | targets: [ 24 | .executableTarget( 25 | name: "Smoke-AsyncHttpClient-Telegram-Bot", 26 | dependencies: targetDependencies 27 | ) 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatMemberMember.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a chat member that has no additional privileges or restrictions. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatMemberMember](https://core.telegram.org/bots/api#chatmembermember) 8 | **/ 9 | public final class TGChatMemberMember: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatMemberMember` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case status = "status" 14 | case user = "user" 15 | case untilDate = "until_date" 16 | } 17 | 18 | /// The member's status in the chat, always “member” 19 | public let status: String 20 | 21 | /// Information about the user 22 | public let user: TGUser 23 | 24 | /// Optional. Date when the user's subscription will expire; Unix time 25 | public let untilDate: Int? 26 | 27 | public init (status: String, user: TGUser, untilDate: Int? = nil) { 28 | self.status = status 29 | self.user = user 30 | self.untilDate = untilDate 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGPassportElementErrorDataFieldType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [PassportElementErrorDataField](https://core.telegram.org/bots/api#passportelementerrordatafield) 8 | */ 9 | 10 | public enum TGPassportElementErrorDataFieldType: String, Codable, Sendable { 11 | case personalDetails = "personal_details" 12 | case passport = "passport" 13 | case driverLicense = "driver_license" 14 | case identityCard = "identity_card" 15 | case internalPassport = "internal_passport" 16 | case address = "address" 17 | case undefined 18 | 19 | public init(from decoder: Decoder) throws { 20 | let value = try decoder.singleValueContainer().decode(String.self) 21 | guard let type = TGPassportElementErrorDataFieldType(rawValue: value) else { 22 | self = .undefined 23 | return 24 | } 25 | self = type 26 | } 27 | } -------------------------------------------------------------------------------- /Examples/FlyingFox-AsyncHttpClient-Telegram-Bot/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:6.0 2 | 3 | import PackageDescription 4 | 5 | let packageDependencies: [Package.Dependency] = [ 6 | .package(url: "https://github.com/swhitty/FlyingFox.git", .upToNextMajor(from: "0.14.0")), 7 | .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.6.0"), 8 | .package(url: "https://github.com/nerzh/swift-telegram-bot", .upToNextMajor(from: "4.2.0")), 9 | ] 10 | 11 | let targetDependencies: [PackageDescription.Target.Dependency] = [ 12 | .product(name: "FlyingFox", package: "FlyingFox"), 13 | .product(name: "AsyncHTTPClient", package: "async-http-client"), 14 | .product(name: "SwiftTelegramBot", package: "swift-telegram-bot") 15 | ] 16 | 17 | let package = Package( 18 | name: "FlyingFox-AsyncHttpClient-Telegram-Bot", 19 | platforms: [ 20 | .macOS(.v14) 21 | ], 22 | dependencies: packageDependencies, 23 | targets: [ 24 | .executableTarget( 25 | name: "FlyingFox-AsyncHttpClient-Telegram-Bot", 26 | dependencies: targetDependencies 27 | ) 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Hudeichuk Oleh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGBusinessIntro.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Contains information about the start page settings of a Telegram Business account. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [BusinessIntro](https://core.telegram.org/bots/api#businessintro) 8 | **/ 9 | public final class TGBusinessIntro: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `BusinessIntro` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case title = "title" 14 | case message = "message" 15 | case sticker = "sticker" 16 | } 17 | 18 | /// Optional. Title text of the business intro 19 | public let title: String? 20 | 21 | /// Optional. Message text of the business intro 22 | public let message: String? 23 | 24 | /// Optional. Sticker of the business intro 25 | public let sticker: TGSticker? 26 | 27 | public init (title: String? = nil, message: String? = nil, sticker: TGSticker? = nil) { 28 | self.title = title 29 | self.message = message 30 | self.sticker = sticker 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGUniqueGiftModel.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object describes the model of a unique gift. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [UniqueGiftModel](https://core.telegram.org/bots/api#uniquegiftmodel) 8 | **/ 9 | public final class TGUniqueGiftModel: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `UniqueGiftModel` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case name = "name" 14 | case sticker = "sticker" 15 | case rarityPerMille = "rarity_per_mille" 16 | } 17 | 18 | /// Name of the model 19 | public let name: String 20 | 21 | /// The sticker that represents the unique gift 22 | public let sticker: TGSticker 23 | 24 | /// The number of unique gifts that receive this model for every 1000 gifts upgraded 25 | public let rarityPerMille: Int 26 | 27 | public init (name: String, sticker: TGSticker, rarityPerMille: Int) { 28 | self.name = name 29 | self.sticker = sticker 30 | self.rarityPerMille = rarityPerMille 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInlineQueryResultVideoType.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video. 5 | If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must replace its content using input_message_content. 6 | 7 | SeeAlso Telegram Bot API Reference: 8 | [InlineQueryResultVideo](https://core.telegram.org/bots/api#inlinequeryresultvideo) 9 | */ 10 | 11 | public enum TGInlineQueryResultVideoType: String, Codable, Sendable { 12 | case video = "video" 13 | case undefined 14 | 15 | public init(from decoder: Decoder) throws { 16 | let value = try decoder.singleValueContainer().decode(String.self) 17 | guard let type = TGInlineQueryResultVideoType(rawValue: value) else { 18 | self = .undefined 19 | return 20 | } 21 | self = type 22 | } 23 | } -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInaccessibleMessage.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object describes a message that was deleted or is otherwise inaccessible to the bot. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InaccessibleMessage](https://core.telegram.org/bots/api#inaccessiblemessage) 8 | **/ 9 | public final class TGInaccessibleMessage: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `InaccessibleMessage` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case chat = "chat" 14 | case messageId = "message_id" 15 | case date = "date" 16 | } 17 | 18 | /// Chat the message belonged to 19 | public let chat: TGChat 20 | 21 | /// Unique message identifier inside the chat 22 | public let messageId: Int 23 | 24 | /// Always 0. The field can be used to differentiate regular and inaccessible messages. 25 | public let date: Int 26 | 27 | public init (chat: TGChat, messageId: Int, date: Int) { 28 | self.chat = chat 29 | self.messageId = messageId 30 | self.date = date 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Examples/Hummingbird-AsyncHttpClient-Telegram-Bot/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:6.0 2 | 3 | import PackageDescription 4 | 5 | let packageDependencies: [Package.Dependency] = [ 6 | .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-alpha.1"), 7 | .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.6.0"), 8 | .package(url: "https://github.com/nerzh/swift-telegram-bot", .upToNextMajor(from: "4.2.0")) 9 | ] 10 | 11 | let targetDependencies: [PackageDescription.Target.Dependency] = [ 12 | .product(name: "Hummingbird", package: "hummingbird"), 13 | .product(name: "AsyncHTTPClient", package: "async-http-client"), 14 | .product(name: "SwiftTelegramBot", package: "swift-telegram-bot") 15 | ] 16 | 17 | let package = Package( 18 | name: "Hummingbird-AsyncHttpClient-Telegram-Bot", 19 | platforms: [ 20 | .macOS(.v14) 21 | ], 22 | dependencies: packageDependencies, 23 | targets: [ 24 | .executableTarget( 25 | name: "Hummingbird-AsyncHttpClient-Telegram-Bot", 26 | dependencies: targetDependencies 27 | ) 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /Examples/Vapor-Telegram-Bot/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:6.0 2 | 3 | import PackageDescription 4 | 5 | var packageDependencies: [Package.Dependency] = [ 6 | .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.57.0")), 7 | ] 8 | 9 | var targetDependencies: [PackageDescription.Target.Dependency] = [ 10 | .product(name: "Vapor", package: "vapor"), 11 | ] 12 | 13 | packageDependencies.append(.package(url: "https://github.com/nerzh/swift-telegram-bot", .upToNextMajor(from: "4.2.0"))) 14 | targetDependencies.append(.product(name: "SwiftTelegramBot", package: "swift-telegram-bot")) 15 | 16 | //packageDependencies.append(.package(path: "/Users/nerzh/mydata/swift_projects/SwiftTelegramSdk")) 17 | //targetDependencies.append(.product(name: "SwiftTelegramSdk", package: "SwiftTelegramSdk")) 18 | 19 | let package = Package( 20 | name: "Vapor-Telegram-Bot", 21 | platforms: [ 22 | .macOS(.v12) 23 | ], 24 | dependencies: packageDependencies, 25 | targets: [ 26 | .executableTarget( 27 | name: "Vapor-Telegram-Bot", 28 | dependencies: targetDependencies 29 | ) 30 | ] 31 | ) 32 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGOwnedGifts.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Contains the list of gifts received and owned by a user or a chat. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [OwnedGifts](https://core.telegram.org/bots/api#ownedgifts) 8 | **/ 9 | public final class TGOwnedGifts: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `OwnedGifts` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case totalCount = "total_count" 14 | case gifts = "gifts" 15 | case nextOffset = "next_offset" 16 | } 17 | 18 | /// The total number of gifts owned by the user or the chat 19 | public let totalCount: Int 20 | 21 | /// The list of gifts 22 | public let gifts: [TGOwnedGift] 23 | 24 | /// Optional. Offset for the next request. If empty, then there are no more results 25 | public let nextOffset: String? 26 | 27 | public init (totalCount: Int, gifts: [TGOwnedGift], nextOffset: String? = nil) { 28 | self.totalCount = totalCount 29 | self.gifts = gifts 30 | self.nextOffset = nextOffset 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChecklistTasksAdded.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Describes a service message about tasks added to a checklist. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChecklistTasksAdded](https://core.telegram.org/bots/api#checklisttasksadded) 8 | **/ 9 | public final class TGChecklistTasksAdded: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChecklistTasksAdded` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case checklistMessage = "checklist_message" 14 | case tasks = "tasks" 15 | } 16 | 17 | /// Optional. Message containing the checklist to which the tasks were added. Note that the Message object in this field will not contain the reply_to_message field even if it itself is a reply. 18 | public let checklistMessage: TGMessage? 19 | 20 | /// List of tasks added to the checklist 21 | public let tasks: [TGChecklistTask] 22 | 23 | public init (checklistMessage: TGMessage? = nil, tasks: [TGChecklistTask]) { 24 | self.checklistMessage = checklistMessage 25 | self.tasks = tasks 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGRevenueWithdrawalStateSucceeded.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The withdrawal succeeded. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [RevenueWithdrawalStateSucceeded](https://core.telegram.org/bots/api#revenuewithdrawalstatesucceeded) 8 | **/ 9 | public final class TGRevenueWithdrawalStateSucceeded: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `RevenueWithdrawalStateSucceeded` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case date = "date" 15 | case url = "url" 16 | } 17 | 18 | /// Type of the state, always “succeeded” 19 | public let type: TGRevenueWithdrawalStateSucceededType 20 | 21 | /// Date the withdrawal was completed in Unix time 22 | public let date: Int 23 | 24 | /// An HTTPS URL that can be used to see transaction details 25 | public let url: String 26 | 27 | public init (type: TGRevenueWithdrawalStateSucceededType, date: Int, url: String) { 28 | self.type = type 29 | self.date = date 30 | self.url = url 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGUniqueGiftSymbol.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object describes the symbol shown on the pattern of a unique gift. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [UniqueGiftSymbol](https://core.telegram.org/bots/api#uniquegiftsymbol) 8 | **/ 9 | public final class TGUniqueGiftSymbol: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `UniqueGiftSymbol` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case name = "name" 14 | case sticker = "sticker" 15 | case rarityPerMille = "rarity_per_mille" 16 | } 17 | 18 | /// Name of the symbol 19 | public let name: String 20 | 21 | /// The sticker that represents the unique gift 22 | public let sticker: TGSticker 23 | 24 | /// The number of unique gifts that receive this model for every 1000 gifts upgraded 25 | public let rarityPerMille: Int 26 | 27 | public init (name: String, sticker: TGSticker, rarityPerMille: Int) { 28 | self.name = name 29 | self.sticker = sticker 30 | self.rarityPerMille = rarityPerMille 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputProfilePhotoStatic.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | A static profile photo in the .JPG format. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputProfilePhotoStatic](https://core.telegram.org/bots/api#inputprofilephotostatic) 8 | **/ 9 | public final class TGInputProfilePhotoStatic: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `InputProfilePhotoStatic` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case photo = "photo" 15 | } 16 | 17 | /// Type of the profile photo, must be static 18 | public let type: TGInputProfilePhotoStaticType 19 | 20 | /// The static profile photo. Profile photos can't be reused and can only be uploaded as a new file, so you can pass “attach://” if the photo was uploaded using multipart/form-data under . More information on Sending Files » 21 | public let photo: String 22 | 23 | public init (type: TGInputProfilePhotoStaticType, photo: String) { 24 | self.type = type 25 | self.photo = photo 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGUniqueGiftBackdrop.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | This object describes the backdrop of a unique gift. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [UniqueGiftBackdrop](https://core.telegram.org/bots/api#uniquegiftbackdrop) 8 | **/ 9 | public final class TGUniqueGiftBackdrop: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `UniqueGiftBackdrop` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case name = "name" 14 | case colors = "colors" 15 | case rarityPerMille = "rarity_per_mille" 16 | } 17 | 18 | /// Name of the backdrop 19 | public let name: String 20 | 21 | /// Colors of the backdrop 22 | public let colors: TGUniqueGiftBackdropColors 23 | 24 | /// The number of unique gifts that receive this backdrop for every 1000 gifts upgraded 25 | public let rarityPerMille: Int 26 | 27 | public init (name: String, colors: TGUniqueGiftBackdropColors, rarityPerMille: Int) { 28 | self.name = name 29 | self.colors = colors 30 | self.rarityPerMille = rarityPerMille 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Methods/GetAvailableGifts.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | import Foundation 4 | 5 | /// DESCRIPTION: 6 | /// Returns the list of gifts that can be sent by the bot to users and channel chats. Requires no parameters. Returns a Gifts object. 7 | 8 | 9 | 10 | public extension TGBot { 11 | /** 12 | Returns the list of gifts that can be sent by the bot to users and channel chats. Requires no parameters. Returns a Gifts object. 13 | 14 | SeeAlso Telegram Bot API Reference: 15 | [GetAvailableGiftsParams](https://core.telegram.org/bots/api#getavailablegifts) 16 | 17 | - Parameters: 18 | - params: Parameters container, see `GetAvailableGiftsParams` struct 19 | - Throws: Throws on errors 20 | - Returns: `TGGifts` 21 | */ 22 | 23 | @discardableResult 24 | func getAvailableGifts() async throws -> TGGifts { 25 | guard let methodURL: URL = .init(string: getMethodURL("getAvailableGifts")) else { 26 | throw BotError("Bad URL: \(getMethodURL("getAvailableGifts"))") 27 | } 28 | let result: TGGifts = try await tgClient.post(methodURL) 29 | return result 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Methods/GetMyStarBalance.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | import Foundation 4 | 5 | /// DESCRIPTION: 6 | /// A method to get the current Telegram Stars balance of the bot. Requires no parameters. On success, returns a StarAmount object. 7 | 8 | 9 | 10 | public extension TGBot { 11 | /** 12 | A method to get the current Telegram Stars balance of the bot. Requires no parameters. On success, returns a StarAmount object. 13 | 14 | SeeAlso Telegram Bot API Reference: 15 | [GetMyStarBalanceParams](https://core.telegram.org/bots/api#getmystarbalance) 16 | 17 | - Parameters: 18 | - params: Parameters container, see `GetMyStarBalanceParams` struct 19 | - Throws: Throws on errors 20 | - Returns: `TGStarAmount` 21 | */ 22 | 23 | @discardableResult 24 | func getMyStarBalance() async throws -> TGStarAmount { 25 | guard let methodURL: URL = .init(string: getMethodURL("getMyStarBalance")) else { 26 | throw BotError("Bad URL: \(getMethodURL("getMyStarBalance"))") 27 | } 28 | let result: TGStarAmount = try await tgClient.post(methodURL) 29 | return result 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGInputPaidMediaPhoto.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | The paid media to send is a photo. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [InputPaidMediaPhoto](https://core.telegram.org/bots/api#inputpaidmediaphoto) 8 | **/ 9 | public final class TGInputPaidMediaPhoto: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `InputPaidMediaPhoto` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case type = "type" 14 | case media = "media" 15 | } 16 | 17 | /// Type of the media, must be photo 18 | public let type: TGInputPaidMediaPhotoType 19 | 20 | /// File 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 pass “attach://” to upload a new one using multipart/form-data under name. More information on Sending Files » 21 | public let media: String 22 | 23 | public init (type: TGInputPaidMediaPhotoType, media: String) { 24 | self.type = type 25 | self.media = media 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftTelegramBot/Bot/Telegram/Models/TGChatMemberBanned.swift: -------------------------------------------------------------------------------- 1 | // Swift Telegram SDK - Telegram Bot Swift SDK. 2 | 3 | /** 4 | Represents a chat member that was banned in the chat and can't return to the chat or view chat messages. 5 | 6 | SeeAlso Telegram Bot API Reference: 7 | [ChatMemberBanned](https://core.telegram.org/bots/api#chatmemberbanned) 8 | **/ 9 | public final class TGChatMemberBanned: Codable, Sendable { 10 | 11 | /// Custom keys for coding/decoding `ChatMemberBanned` struct 12 | public enum CodingKeys: String, CodingKey { 13 | case status = "status" 14 | case user = "user" 15 | case untilDate = "until_date" 16 | } 17 | 18 | /// The member's status in the chat, always “kicked” 19 | public let status: String 20 | 21 | /// Information about the user 22 | public let user: TGUser 23 | 24 | /// Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever 25 | public let untilDate: Int 26 | 27 | public init (status: String, user: TGUser, untilDate: Int) { 28 | self.status = status 29 | self.user = user 30 | self.untilDate = untilDate 31 | } 32 | } 33 | --------------------------------------------------------------------------------