From e1875d3a75303c2a224edfa92892bd25ba8a25de Mon Sep 17 00:00:00 2001 From: Matteo Piccina Date: Wed, 3 Jun 2020 10:00:09 +0200 Subject: [PATCH] Update to API v4.8 --- API/TelegramAPIDefinition.yml | 57 +++++++- .../TelegramBotSDK/Generated/Methods.swift | 136 +++++++++++++++++- Sources/TelegramBotSDK/Generated/Types.swift | 40 +++++- 3 files changed, 224 insertions(+), 9 deletions(-) diff --git a/API/TelegramAPIDefinition.yml b/API/TelegramAPIDefinition.yml index 667162b..43a92f1 100644 --- a/API/TelegramAPIDefinition.yml +++ b/API/TelegramAPIDefinition.yml @@ -93,6 +93,7 @@ fields: - video_note: VideoNote? - caption: String? - contact: Contact? + - dice: Dice? - location: Location? - venue: Venue? - poll: Poll? @@ -207,6 +208,12 @@ fields: - user_id: Int64? - vcard: String? +--- +type: Dice +fields: + - emoji: String + - value: Int + --- type: Location fields: @@ -247,6 +254,10 @@ fields: - type: PollType - allows_multiple_answers: Bool - correct_option_id: Int? + - explanation: String + - explanation_entities: MessageEntity[]? + - open_period: Int? + - close_date: Date? --- type: UserProfilePhotos @@ -374,6 +385,12 @@ fields: - can_invite_users: Bool? - can_pin_messages: Bool? +--- +type: BotCommand +fields: + - command: String + - description: String + --- type: ResponseParameters fields: @@ -456,6 +473,7 @@ fields: - is_animated: Bool - contains_masks: Bool - stickers: Sticker[] + - thumb: PhotoSize? --- type: MaskPosition @@ -1107,13 +1125,28 @@ parameters: - options: String[] - is_anonymous: Bool? - type: PollType? + - allow_multiple_answers: Bool? - correct_option_id: Int? + - explanation: String? + - explanation_parse_mode: ParseMode? + - open_period: Int? + - close_date: Date? - is_closed: Bool? - disable_notification: Bool? - reply_to_message_id: Int? - reply_markup: ReplyMarkup? result: Message? +--- +method: sendDice +parameters: + - chat_id: ChatId + - emoji: String? + - disable_notification: Bool? + - reply_to_message_id: Int? + - reply_markup: ReplyMarkup? +result: Message? + --- method: sendChatAction parameters: @@ -1290,6 +1323,16 @@ parameters: - cache_time: Int? result: Bool? +--- +method: setMyCommands +parameters: + - commands: BotCommand[] +result: Bool? + +--- +method: getMyCommands +result: BotCommand[]? + --- method: editMessageText parameters: @@ -1376,7 +1419,8 @@ parameters: - user_id: Int64 - name: String - title: String - - png_sticker: FileInfo + - png_sticker: FileInfo? + - tgs_sticker: InputFile? - emojis: String - contains_masks: Bool? - mask_position: Bool? @@ -1387,7 +1431,8 @@ method: addStickerToSet parameters: - user_id: Int - name: String - - png_sticker: FileInfo + - png_sticker: FileInfo? + - tgs_sticker: InputFile? - emojis: String - mask_position: MaskPosition? result: Bool? @@ -1405,6 +1450,14 @@ parameters: - sticker: String result: Bool? +--- +method: setStickerSetThumb +parameters: + - name: String + - user_id: Int + - thumb: FileInfo? +result: Bool? + --- method: answerInlineQuery parameters: diff --git a/Sources/TelegramBotSDK/Generated/Methods.swift b/Sources/TelegramBotSDK/Generated/Methods.swift index 0a2ea60..38f3caf 100644 --- a/Sources/TelegramBotSDK/Generated/Methods.swift +++ b/Sources/TelegramBotSDK/Generated/Methods.swift @@ -819,7 +819,12 @@ public extension TelegramBot { options: [String], isAnonymous: Bool? = nil, type: PollType? = nil, + allowMultipleAnswers: Bool? = nil, correctOptionId: Int? = nil, + explanation: String? = nil, + explanationParseMode: ParseMode? = nil, + openPeriod: Int? = nil, + closeDate: Date? = nil, isClosed: Bool? = nil, disableNotification: Bool? = nil, replyToMessageId: Int? = nil, @@ -831,7 +836,12 @@ public extension TelegramBot { "options": options, "is_anonymous": isAnonymous, "type": type, +"allow_multiple_answers": allowMultipleAnswers, "correct_option_id": correctOptionId, +"explanation": explanation, +"explanation_parse_mode": explanationParseMode, +"open_period": openPeriod, +"close_date": closeDate, "is_closed": isClosed, "disable_notification": disableNotification, "reply_to_message_id": replyToMessageId, @@ -844,7 +854,12 @@ public extension TelegramBot { options: [String], isAnonymous: Bool? = nil, type: PollType? = nil, + allowMultipleAnswers: Bool? = nil, correctOptionId: Int? = nil, + explanation: String? = nil, + explanationParseMode: ParseMode? = nil, + openPeriod: Int? = nil, + closeDate: Date? = nil, isClosed: Bool? = nil, disableNotification: Bool? = nil, replyToMessageId: Int? = nil, @@ -858,10 +873,50 @@ public extension TelegramBot { "options": options, "is_anonymous": isAnonymous, "type": type, +"allow_multiple_answers": allowMultipleAnswers, "correct_option_id": correctOptionId, +"explanation": explanation, +"explanation_parse_mode": explanationParseMode, +"open_period": openPeriod, +"close_date": closeDate, "is_closed": isClosed, "disable_notification": disableNotification, "reply_to_message_id": replyToMessageId, +"reply_markup": replyMarkup], + queue: queue, completion: completion) + } + typealias SendDiceCompletion = (_ result: Message?, _ error: DataTaskError?) -> () + + @discardableResult + func sendDiceSync( + chatId: ChatId, + emoji: String? = nil, + disableNotification: Bool? = nil, + replyToMessageId: Int? = nil, + replyMarkup: ReplyMarkup? = nil, + _ parameters: [String: Encodable?] = [:]) -> Message? { + return requestSync("sendDice", defaultParameters["sendDice"], parameters, [ + "chat_id": chatId, +"emoji": emoji, +"disable_notification": disableNotification, +"reply_to_message_id": replyToMessageId, +"reply_markup": replyMarkup]) + } + + func sendDiceAsync( + chatId: ChatId, + emoji: String? = nil, + disableNotification: Bool? = nil, + replyToMessageId: Int? = nil, + replyMarkup: ReplyMarkup? = nil, + _ parameters: [String: Encodable?] = [:], + queue: DispatchQueue = .main, + completion: SendDiceCompletion? = nil) { + return requestAsync("sendDice", defaultParameters["sendDice"], parameters, [ + "chat_id": chatId, +"emoji": emoji, +"disable_notification": disableNotification, +"reply_to_message_id": replyToMessageId, "reply_markup": replyMarkup], queue: queue, completion: completion) } @@ -1441,6 +1496,44 @@ public extension TelegramBot { "cache_time": cacheTime], queue: queue, completion: completion) } + typealias SetMyCommandsCompletion = (_ result: Bool?, _ error: DataTaskError?) -> () + + @discardableResult + func setMyCommandsSync( + commands: [BotCommand], + _ parameters: [String: Encodable?] = [:]) -> Bool? { + return requestSync("setMyCommands", defaultParameters["setMyCommands"], parameters, [ + "commands": commands]) + } + + func setMyCommandsAsync( + commands: [BotCommand], + _ parameters: [String: Encodable?] = [:], + queue: DispatchQueue = .main, + completion: SetMyCommandsCompletion? = nil) { + return requestAsync("setMyCommands", defaultParameters["setMyCommands"], parameters, [ + "commands": commands], + queue: queue, completion: completion) + } + typealias GetMyCommandsCompletion = (_ result: [BotCommand]?, _ error: DataTaskError?) -> () + + @discardableResult + func getMyCommandsSync( + + _ parameters: [String: Encodable?] = [:]) -> [BotCommand]? { + return requestSync("getMyCommands", defaultParameters["getMyCommands"], parameters, [ + :]) + } + + func getMyCommandsAsync( + + _ parameters: [String: Encodable?] = [:], + queue: DispatchQueue = .main, + completion: GetMyCommandsCompletion? = nil) { + return requestAsync("getMyCommands", defaultParameters["getMyCommands"], parameters, [ + :], + queue: queue, completion: completion) + } typealias EditMessageTextCompletion = (_ result: MessageOrBool?, _ error: DataTaskError?) -> () @discardableResult @@ -1723,7 +1816,8 @@ public extension TelegramBot { userId: Int64, name: String, title: String, - pngSticker: FileInfo, + pngSticker: FileInfo? = nil, + tgsSticker: InputFile? = nil, emojis: String, containsMasks: Bool? = nil, maskPosition: Bool? = nil, @@ -1733,6 +1827,7 @@ public extension TelegramBot { "name": name, "title": title, "png_sticker": pngSticker, +"tgs_sticker": tgsSticker, "emojis": emojis, "contains_masks": containsMasks, "mask_position": maskPosition]) @@ -1742,7 +1837,8 @@ public extension TelegramBot { userId: Int64, name: String, title: String, - pngSticker: FileInfo, + pngSticker: FileInfo? = nil, + tgsSticker: InputFile? = nil, emojis: String, containsMasks: Bool? = nil, maskPosition: Bool? = nil, @@ -1754,6 +1850,7 @@ public extension TelegramBot { "name": name, "title": title, "png_sticker": pngSticker, +"tgs_sticker": tgsSticker, "emojis": emojis, "contains_masks": containsMasks, "mask_position": maskPosition], @@ -1765,7 +1862,8 @@ public extension TelegramBot { func addStickerToSetSync( userId: Int, name: String, - pngSticker: FileInfo, + pngSticker: FileInfo? = nil, + tgsSticker: InputFile? = nil, emojis: String, maskPosition: MaskPosition? = nil, _ parameters: [String: Encodable?] = [:]) -> Bool? { @@ -1773,6 +1871,7 @@ public extension TelegramBot { "user_id": userId, "name": name, "png_sticker": pngSticker, +"tgs_sticker": tgsSticker, "emojis": emojis, "mask_position": maskPosition]) } @@ -1780,7 +1879,8 @@ public extension TelegramBot { func addStickerToSetAsync( userId: Int, name: String, - pngSticker: FileInfo, + pngSticker: FileInfo? = nil, + tgsSticker: InputFile? = nil, emojis: String, maskPosition: MaskPosition? = nil, _ parameters: [String: Encodable?] = [:], @@ -1790,6 +1890,7 @@ public extension TelegramBot { "user_id": userId, "name": name, "png_sticker": pngSticker, +"tgs_sticker": tgsSticker, "emojis": emojis, "mask_position": maskPosition], queue: queue, completion: completion) @@ -1836,6 +1937,33 @@ public extension TelegramBot { "sticker": sticker], queue: queue, completion: completion) } + typealias SetStickerSetThumbCompletion = (_ result: Bool?, _ error: DataTaskError?) -> () + + @discardableResult + func setStickerSetThumbSync( + name: String, + userId: Int, + thumb: FileInfo? = nil, + _ parameters: [String: Encodable?] = [:]) -> Bool? { + return requestSync("setStickerSetThumb", defaultParameters["setStickerSetThumb"], parameters, [ + "name": name, +"user_id": userId, +"thumb": thumb]) + } + + func setStickerSetThumbAsync( + name: String, + userId: Int, + thumb: FileInfo? = nil, + _ parameters: [String: Encodable?] = [:], + queue: DispatchQueue = .main, + completion: SetStickerSetThumbCompletion? = nil) { + return requestAsync("setStickerSetThumb", defaultParameters["setStickerSetThumb"], parameters, [ + "name": name, +"user_id": userId, +"thumb": thumb], + queue: queue, completion: completion) + } typealias AnswerInlineQueryCompletion = (_ result: Bool?, _ error: DataTaskError?) -> () @discardableResult diff --git a/Sources/TelegramBotSDK/Generated/Types.swift b/Sources/TelegramBotSDK/Generated/Types.swift index 387c7b6..d459e50 100644 --- a/Sources/TelegramBotSDK/Generated/Types.swift +++ b/Sources/TelegramBotSDK/Generated/Types.swift @@ -143,6 +143,7 @@ public class Message: Codable { public var videoNote: VideoNote? public var caption: String? public var contact: Contact? + public var dice: Dice? public var location: Location? public var venue: Venue? public var poll: Poll? @@ -161,7 +162,7 @@ public class Message: Codable { public var successfulPayment: SuccessfulPayment? public var connectedWebsite: String? public var replyMarkup: InlineKeyboardMarkup? - public init(messageId: Int, from: User? = nil, date: Date, chat: Chat, forwardFrom: User? = nil, forwardFromChat: Chat? = nil, forwardFromMessageId: Int? = nil, forwardSignature: String? = nil, forwardSenderName: String? = nil, forwardDate: Date? = nil, replyToMessage: Message? = nil, editDate: Date? = nil, mediaGroupId: String? = nil, authorSignature: String? = nil, text: String? = nil, entities: [MessageEntity]? = nil, captionEntities: [MessageEntity]? = nil, audio: Audio? = nil, document: Document? = nil, animation: Animation? = nil, game: Game? = nil, photo: [PhotoSize]? = nil, sticker: Sticker? = nil, video: Video? = nil, voice: Voice? = nil, videoNote: VideoNote? = nil, caption: String? = nil, contact: Contact? = nil, location: Location? = nil, venue: Venue? = nil, poll: Poll? = nil, newChatMembers: [User]? = nil, leftChatMember: User? = nil, newChatTitle: String? = nil, newChatPhoto: [PhotoSize]? = nil, deleteChatPhoto: Bool? = nil, groupChatCreated: Bool? = nil, supergroupChatCreated: Bool? = nil, channelChatCreated: Bool? = nil, migrateToChatId: Int64? = nil, migrateFromChatId: Int64? = nil, pinnedMessage: Message? = nil, invoice: Invoice? = nil, successfulPayment: SuccessfulPayment? = nil, connectedWebsite: String? = nil, replyMarkup: InlineKeyboardMarkup? = nil) { + public init(messageId: Int, from: User? = nil, date: Date, chat: Chat, forwardFrom: User? = nil, forwardFromChat: Chat? = nil, forwardFromMessageId: Int? = nil, forwardSignature: String? = nil, forwardSenderName: String? = nil, forwardDate: Date? = nil, replyToMessage: Message? = nil, editDate: Date? = nil, mediaGroupId: String? = nil, authorSignature: String? = nil, text: String? = nil, entities: [MessageEntity]? = nil, captionEntities: [MessageEntity]? = nil, audio: Audio? = nil, document: Document? = nil, animation: Animation? = nil, game: Game? = nil, photo: [PhotoSize]? = nil, sticker: Sticker? = nil, video: Video? = nil, voice: Voice? = nil, videoNote: VideoNote? = nil, caption: String? = nil, contact: Contact? = nil, dice: Dice? = nil, location: Location? = nil, venue: Venue? = nil, poll: Poll? = nil, newChatMembers: [User]? = nil, leftChatMember: User? = nil, newChatTitle: String? = nil, newChatPhoto: [PhotoSize]? = nil, deleteChatPhoto: Bool? = nil, groupChatCreated: Bool? = nil, supergroupChatCreated: Bool? = nil, channelChatCreated: Bool? = nil, migrateToChatId: Int64? = nil, migrateFromChatId: Int64? = nil, pinnedMessage: Message? = nil, invoice: Invoice? = nil, successfulPayment: SuccessfulPayment? = nil, connectedWebsite: String? = nil, replyMarkup: InlineKeyboardMarkup? = nil) { self.messageId = messageId self.from = from self.date = date @@ -190,6 +191,7 @@ public class Message: Codable { self.videoNote = videoNote self.caption = caption self.contact = contact + self.dice = dice self.location = location self.venue = venue self.poll = poll @@ -392,6 +394,17 @@ public class Contact: Codable { } +public class Dice: Codable { + public var emoji: String + public var value: Int + public init(emoji: String, value: Int) { + self.emoji = emoji + self.value = value + } + +} + + public class Location: Codable { public var longitude: Float public var latitude: Float @@ -454,7 +467,11 @@ public class Poll: Codable { public var type: PollType public var allowsMultipleAnswers: Bool public var correctOptionId: Int? - public init(id: String, question: String, options: [PollOption], totalVoterCount: Int, isClosed: Bool, isAnonymous: Bool, type: PollType, allowsMultipleAnswers: Bool, correctOptionId: Int? = nil) { + public var explanation: String + public var explanationEntities: [MessageEntity]? = [] + public var openPeriod: Int? + public var closeDate: Date? + public init(id: String, question: String, options: [PollOption], totalVoterCount: Int, isClosed: Bool, isAnonymous: Bool, type: PollType, allowsMultipleAnswers: Bool, correctOptionId: Int? = nil, explanation: String, explanationEntities: [MessageEntity]? = nil, openPeriod: Int? = nil, closeDate: Date? = nil) { self.id = id self.question = question self.options = options @@ -464,6 +481,10 @@ public class Poll: Codable { self.type = type self.allowsMultipleAnswers = allowsMultipleAnswers self.correctOptionId = correctOptionId + self.explanation = explanation + self.explanationEntities = explanationEntities + self.openPeriod = openPeriod + self.closeDate = closeDate } } @@ -699,6 +720,17 @@ public class ChatPermissions: Codable { } +public class BotCommand: Codable { + public var command: String + public var description: String + public init(command: String, description: String) { + self.command = command + self.description = description + } + +} + + public class ResponseParameters: Codable { public var migrateToChatId: Int64? public var retryAfter: Int? @@ -846,12 +878,14 @@ public class StickerSet: Codable { public var isAnimated: Bool public var containsMasks: Bool public var stickers: [Sticker] = [] - public init(name: String, title: String, isAnimated: Bool, containsMasks: Bool, stickers: [Sticker]) { + public var thumb: PhotoSize? + public init(name: String, title: String, isAnimated: Bool, containsMasks: Bool, stickers: [Sticker], thumb: PhotoSize? = nil) { self.name = name self.title = title self.isAnimated = isAnimated self.containsMasks = containsMasks self.stickers = stickers + self.thumb = thumb } }