From d5ba1fd0f635cba085b85f23f5e54391c9b5a435 Mon Sep 17 00:00:00 2001 From: Koray Koska Date: Tue, 29 Jan 2019 01:07:02 +0100 Subject: [PATCH] Remove vapor dependency, rename library --- LICENSE | 2 +- Package.swift | 13 ++-- README.md | 43 ++++-------- .../Keyboard/TelegramCallbackGame.swift | 2 +- .../Keyboard/TelegramForceReply.swift | 2 +- .../TelegramInlineKeyboardButton.swift | 2 +- .../TelegramInlineKeyboardMarkup.swift | 2 +- .../Keyboard/TelegramKeyboardButton.swift | 2 +- .../TelegramReplyKeyboardMarkup.swift | 2 +- .../TelegramReplyKeyboardRemove.swift | 2 +- .../Json/CallbackApi/TelegramAnimation.swift | 2 +- .../Json/CallbackApi/TelegramAudio.swift | 2 +- .../CallbackApi/TelegramCallbackQuery.swift | 2 +- .../Json/CallbackApi/TelegramChat.swift | 2 +- .../Json/CallbackApi/TelegramChatPhoto.swift | 2 +- .../TelegramChosenInlineResult.swift | 2 +- .../Json/CallbackApi/TelegramContact.swift | 2 +- .../Json/CallbackApi/TelegramDocument.swift | 2 +- .../TelegramEncryptedCredentials.swift | 2 +- .../TelegramEncryptedPassportElement.swift | 2 +- .../Json/CallbackApi/TelegramFile.swift | 2 +- .../Json/CallbackApi/TelegramGame.swift | 2 +- .../CallbackApi/TelegramInlineQuery.swift | 2 +- .../Json/CallbackApi/TelegramInvoice.swift | 2 +- .../Json/CallbackApi/TelegramLocation.swift | 2 +- .../CallbackApi/TelegramMaskPosition.swift | 2 +- .../Json/CallbackApi/TelegramMessage.swift | 2 +- .../CallbackApi/TelegramMessageEntity.swift | 2 +- .../Json/CallbackApi/TelegramOrderInfo.swift | 2 +- .../CallbackApi/TelegramPassportData.swift | 2 +- .../CallbackApi/TelegramPassportFile.swift | 2 +- .../Json/CallbackApi/TelegramPhotoSize.swift | 2 +- .../TelegramPreCheckoutQuery.swift | 2 +- .../CallbackApi/TelegramShippingAddress.swift | 2 +- .../CallbackApi/TelegramShippingQuery.swift | 2 +- .../Json/CallbackApi/TelegramSticker.swift | 2 +- .../TelegramSuccessfulPayment.swift | 2 +- .../Json/CallbackApi/TelegramUpdate.swift | 2 +- .../Json/CallbackApi/TelegramUser.swift | 2 +- .../TelegramUserProfilePhotos.swift | 2 +- .../Json/CallbackApi/TelegramVenue.swift | 2 +- .../Json/CallbackApi/TelegramVideo.swift | 2 +- .../Json/CallbackApi/TelegramVideoNote.swift | 2 +- .../Json/CallbackApi/TelegramVoice.swift | 2 +- .../SendApi/TelegramSendChatIdentifier.swift | 2 +- .../Json/SendApi/TelegramSendMessage.swift | 2 +- .../TelegramReceiveApi.swift} | 40 +++++++---- .../TelegramSendApi.swift | 2 +- Sources/TelegramBot/Toolbox/Router.swift | 66 +++++++++++++++++++ .../AppTests.swift | 2 +- 50 files changed, 157 insertions(+), 97 deletions(-) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift (89%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramForceReply.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift (99%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift (96%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift (99%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramAnimation.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramAudio.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramCallbackQuery.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramChat.swift (99%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramChatPhoto.swift (96%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramChosenInlineResult.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramContact.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramDocument.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramEncryptedCredentials.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramEncryptedPassportElement.swift (99%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramFile.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramGame.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramInlineQuery.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramInvoice.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramLocation.swift (95%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramMaskPosition.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramMessage.swift (99%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramMessageEntity.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramOrderInfo.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramPassportData.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramPassportFile.swift (96%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramPhotoSize.swift (96%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramPreCheckoutQuery.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramShippingAddress.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramShippingQuery.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramSticker.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramSuccessfulPayment.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramUpdate.swift (99%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramUser.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramUserProfilePhotos.swift (96%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramVenue.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramVideo.swift (98%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramVideoNote.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/CallbackApi/TelegramVoice.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/SendApi/TelegramSendChatIdentifier.swift (97%) rename Sources/{VaporTelegramBot => TelegramBot}/Json/SendApi/TelegramSendMessage.swift (99%) rename Sources/{VaporTelegramBot/VaporTelegramBot.swift => TelegramBot/TelegramReceiveApi.swift} (77%) rename Sources/{VaporTelegramBot => TelegramBot}/TelegramSendApi.swift (93%) create mode 100644 Sources/TelegramBot/Toolbox/Router.swift rename Tests/{VaporTelegramBotTests => TelegramBotTests}/AppTests.swift (90%) diff --git a/LICENSE b/LICENSE index 5010099..22e06c1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Boilertalk +Copyright (c) 2019 Volkn, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Package.swift b/Package.swift index 9bb97ee..57f6d6c 100644 --- a/Package.swift +++ b/Package.swift @@ -2,22 +2,19 @@ import PackageDescription let package = Package( - name: "VaporTelegramBot", + name: "TelegramBot", products: [ .library( - name: "VaporTelegramBot", - targets: ["VaporTelegramBot"]), + name: "TelegramBot", + targets: ["TelegramBot"]), ], dependencies: [ - // Vapor for vapor related requests - .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"), - // Test dependencies .package(url: "https://github.com/Quick/Quick.git", from: "1.2.0"), .package(url: "https://github.com/Quick/Nimble.git", from: "7.0.3") ], targets: [ - .target(name: "VaporTelegramBot", dependencies: ["Vapor"]), - .testTarget(name: "VaporTelegramBotTests", dependencies: ["VaporTelegramBot", "Quick", "Nimble"]) + .target(name: "TelegramBot", dependencies: []), + .testTarget(name: "TelegramBotTests", dependencies: ["TelegramBot", "Quick", "Nimble"]) ] ) diff --git a/README.md b/README.md index 3061d48..41027a2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ - +

- - Build Status + + Build Status - + license @@ -17,13 +17,15 @@

-# :alembic: VaporTelegramBot +# :alembic: TelegramBot.swift -This library provides helpers for [Vapor 2](https://github.com/vapor/vapor) to interact with the [Telegram bot api](https://core.telegram.org/bots/api). It simplifies the requests to the Telegram API as well as parses incoming [updates](https://core.telegram.org/bots/api#getting-updates) for you. +This library provides helpers for Swift to interact with the [Telegram bot api](https://core.telegram.org/bots/api). It simplifies the requests to the Telegram API as well as parses incoming [updates](https://core.telegram.org/bots/api#getting-updates) for you. + +This library can be used with [Vapor 3](https://github.com/vapor/vapor) and with any other web libraries. ## :sparkles: Supported features -The following is a list with all features of the facebook Send API and webhooks as of May 2017 together with a note whether it is supported or not. If you find something that's not listed there please open an [issue](https://github.com/Boilertalk/VaporFacebookBot/issues). +The following is a list with all features of the facebook Send API and webhooks as of May 2017 together with a note whether it is supported or not. If you find something that's not listed there please open an [issue](https://github.com/Boilertalk/TelegramBot.swift/issues). ### Webhooks @@ -35,37 +37,16 @@ The following is a list with all features of the facebook Send API and webhooks ## :package: Installation -This Swift package is intended to be used together with Vapor 2.0. Add the following line to your dependencies in the `Package.swift` file: ```Swift -.Package(url: "https://github.com/Boilertalk/VaporTelegramBot.git", majorVersion: 0) +.package(url: "https://github.com/Boilertalk/TelegramBot.swift.git", from: "0.3.0") ``` -Your `Package.swift` file should now look a little bit like the following: +Then you can start importing `TelegramBot`. ```Swift -import PackageDescription - -let package = Package( - name: "MyAwesomeBot", - targets: [ - Target(name: "App"), - Target(name: "Run", dependencies: ["App"]), - ], - dependencies: [ - .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2), - .Package(url: "https://github.com/vapor/fluent-provider.git", majorVersion: 1), - .Package(url: "https://github.com/Boilertalk/VaporTelegramBot.git", majorVersion: 0) - ], - exclude: [ - "Config", - "Database", - "Localization", - "Public", - "Resources", - ] -) +import TelegramBot ``` ## :book: Documentation diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift similarity index 89% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift index e7ef067..2336a48 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramCallbackGame.swift @@ -1,6 +1,6 @@ // // TelegramCallbackGame.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramForceReply.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramForceReply.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramForceReply.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramForceReply.swift index e966238..1375fc5 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramForceReply.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramForceReply.swift @@ -1,6 +1,6 @@ // // TelegramForceReply.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift index 53eeafc..4aae461 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardButton.swift @@ -1,6 +1,6 @@ // // TelegramInlineKeyboardButton.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift similarity index 96% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift index a42622b..a6d3421 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramInlineKeyboardMarkup.swift @@ -1,6 +1,6 @@ // // TelegramInlineKeyboardMarkup.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift index 87597ab..7aeff0d 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramKeyboardButton.swift @@ -1,6 +1,6 @@ // // TelegramKeyboardButton.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift index c37e15f..1908714 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardMarkup.swift @@ -1,6 +1,6 @@ // // TelegramReplyKeyboardMarkup.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift rename to Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift index 2671a70..82aa2ac 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift +++ b/Sources/TelegramBot/Json/CallbackApi/Keyboard/TelegramReplyKeyboardRemove.swift @@ -1,6 +1,6 @@ // // TelegramReplyKeyboardRemove.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramAnimation.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramAnimation.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramAnimation.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramAnimation.swift index eac2327..0eb5394 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramAnimation.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramAnimation.swift @@ -1,6 +1,6 @@ // // TelegramAnimation.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramAudio.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramAudio.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramAudio.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramAudio.swift index 7e24466..9ca896e 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramAudio.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramAudio.swift @@ -1,6 +1,6 @@ // // TelegramAudio.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramCallbackQuery.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramCallbackQuery.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramCallbackQuery.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramCallbackQuery.swift index 82984b0..7700efb 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramCallbackQuery.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramCallbackQuery.swift @@ -1,6 +1,6 @@ // // TelegramCallbackQuery.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramChat.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramChat.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramChat.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramChat.swift index cfd2294..02c19c7 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramChat.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramChat.swift @@ -1,6 +1,6 @@ // // TelegramChat.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramChatPhoto.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramChatPhoto.swift similarity index 96% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramChatPhoto.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramChatPhoto.swift index 0af7e4c..a14efb3 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramChatPhoto.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramChatPhoto.swift @@ -1,6 +1,6 @@ // // TelegramChatPhoto.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramChosenInlineResult.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramChosenInlineResult.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramChosenInlineResult.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramChosenInlineResult.swift index 8c7e4f0..d292d90 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramChosenInlineResult.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramChosenInlineResult.swift @@ -1,6 +1,6 @@ // // TelegramChosenInlineResult.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramContact.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramContact.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramContact.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramContact.swift index f526dca..d97dd4a 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramContact.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramContact.swift @@ -1,6 +1,6 @@ // // TelegramContact.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramDocument.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramDocument.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramDocument.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramDocument.swift index b299fe8..2ce9bb5 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramDocument.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramDocument.swift @@ -1,6 +1,6 @@ // // TelegramDocument.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramEncryptedCredentials.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramEncryptedCredentials.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramEncryptedCredentials.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramEncryptedCredentials.swift index 8afa504..2951fb4 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramEncryptedCredentials.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramEncryptedCredentials.swift @@ -1,6 +1,6 @@ // // TelegramEncryptedCredentials.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramEncryptedPassportElement.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramEncryptedPassportElement.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramEncryptedPassportElement.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramEncryptedPassportElement.swift index 81dcacd..cf9aff0 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramEncryptedPassportElement.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramEncryptedPassportElement.swift @@ -1,6 +1,6 @@ // // TelegramEncryptedPassportElement.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramFile.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramFile.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramFile.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramFile.swift index 5a5c6b0..301af70 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramFile.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramFile.swift @@ -1,6 +1,6 @@ // // TelegramFile.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramGame.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramGame.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramGame.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramGame.swift index 63ec903..0bed92d 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramGame.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramGame.swift @@ -1,6 +1,6 @@ // // TelegramGame.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramInlineQuery.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramInlineQuery.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramInlineQuery.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramInlineQuery.swift index 82c3d3b..70ff8c5 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramInlineQuery.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramInlineQuery.swift @@ -1,6 +1,6 @@ // // TelegramInlineQuery.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramInvoice.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramInvoice.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramInvoice.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramInvoice.swift index 0b524c6..536c46a 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramInvoice.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramInvoice.swift @@ -1,6 +1,6 @@ // // TelegramInvoice.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramLocation.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramLocation.swift similarity index 95% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramLocation.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramLocation.swift index 28b1d86..5c2cbb8 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramLocation.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramLocation.swift @@ -1,6 +1,6 @@ // // TelegramLocation.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramMaskPosition.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramMaskPosition.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramMaskPosition.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramMaskPosition.swift index 775632d..df6338c 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramMaskPosition.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramMaskPosition.swift @@ -1,6 +1,6 @@ // // TelegramMaskPosition.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramMessage.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramMessage.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramMessage.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramMessage.swift index 2c82e6a..a066c23 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramMessage.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramMessage.swift @@ -1,6 +1,6 @@ // // TelegramMessage.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramMessageEntity.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramMessageEntity.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramMessageEntity.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramMessageEntity.swift index b90f84c..0d40720 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramMessageEntity.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramMessageEntity.swift @@ -1,6 +1,6 @@ // // TelegramMessageEntity.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramOrderInfo.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramOrderInfo.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramOrderInfo.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramOrderInfo.swift index 4b64641..7773d5f 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramOrderInfo.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramOrderInfo.swift @@ -1,6 +1,6 @@ // // TelegramOrderInfo.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPassportData.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramPassportData.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramPassportData.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramPassportData.swift index 361c8a7..c021d1b 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPassportData.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramPassportData.swift @@ -1,6 +1,6 @@ // // TelegramPassportData.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPassportFile.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramPassportFile.swift similarity index 96% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramPassportFile.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramPassportFile.swift index 68de60e..081bd77 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPassportFile.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramPassportFile.swift @@ -1,6 +1,6 @@ // // TelegramPassportFile.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPhotoSize.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramPhotoSize.swift similarity index 96% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramPhotoSize.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramPhotoSize.swift index f94cf40..cb75639 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPhotoSize.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramPhotoSize.swift @@ -1,6 +1,6 @@ // // TelegramPhotoSize.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPreCheckoutQuery.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramPreCheckoutQuery.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramPreCheckoutQuery.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramPreCheckoutQuery.swift index 2887d40..aec37e5 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramPreCheckoutQuery.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramPreCheckoutQuery.swift @@ -1,6 +1,6 @@ // // TelegramPreCheckoutQuery.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramShippingAddress.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramShippingAddress.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramShippingAddress.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramShippingAddress.swift index 05aa348..718c7b9 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramShippingAddress.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramShippingAddress.swift @@ -1,6 +1,6 @@ // // TelegramShippingAddress.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramShippingQuery.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramShippingQuery.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramShippingQuery.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramShippingQuery.swift index bcd4483..b49b837 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramShippingQuery.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramShippingQuery.swift @@ -1,6 +1,6 @@ // // TelegramShippingQuery.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramSticker.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramSticker.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramSticker.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramSticker.swift index e030fdf..de262a1 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramSticker.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramSticker.swift @@ -1,6 +1,6 @@ // // TelegramSticker.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramSuccessfulPayment.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramSuccessfulPayment.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramSuccessfulPayment.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramSuccessfulPayment.swift index e182a65..d0e5144 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramSuccessfulPayment.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramSuccessfulPayment.swift @@ -1,6 +1,6 @@ // // TelegramSuccessfulPayment.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramUpdate.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramUpdate.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramUpdate.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramUpdate.swift index 08f4f85..0d3a1b3 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramUpdate.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramUpdate.swift @@ -1,6 +1,6 @@ // // TelegramUpdate.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramUser.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramUser.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramUser.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramUser.swift index cd406a0..65daf9a 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramUser.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramUser.swift @@ -1,6 +1,6 @@ // // TelegramUser.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 14.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramUserProfilePhotos.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramUserProfilePhotos.swift similarity index 96% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramUserProfilePhotos.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramUserProfilePhotos.swift index b59023b..aeb3f7b 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramUserProfilePhotos.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramUserProfilePhotos.swift @@ -1,6 +1,6 @@ // // TelegramUserProfilePhotos.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 17.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVenue.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramVenue.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramVenue.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramVenue.swift index 1be8b47..ab04006 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVenue.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramVenue.swift @@ -1,6 +1,6 @@ // // TelegramVenue.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVideo.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramVideo.swift similarity index 98% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramVideo.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramVideo.swift index ffb8e47..f975a8a 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVideo.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramVideo.swift @@ -1,6 +1,6 @@ // // TelegramVideo.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVideoNote.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramVideoNote.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramVideoNote.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramVideoNote.swift index 448c7db..e0f60f5 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVideoNote.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramVideoNote.swift @@ -1,6 +1,6 @@ // // TelegramVideoNote.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVoice.swift b/Sources/TelegramBot/Json/CallbackApi/TelegramVoice.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/CallbackApi/TelegramVoice.swift rename to Sources/TelegramBot/Json/CallbackApi/TelegramVoice.swift index e688759..e7f0103 100644 --- a/Sources/VaporTelegramBot/Json/CallbackApi/TelegramVoice.swift +++ b/Sources/TelegramBot/Json/CallbackApi/TelegramVoice.swift @@ -1,6 +1,6 @@ // // TelegramVoice.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 15.01.19. // diff --git a/Sources/VaporTelegramBot/Json/SendApi/TelegramSendChatIdentifier.swift b/Sources/TelegramBot/Json/SendApi/TelegramSendChatIdentifier.swift similarity index 97% rename from Sources/VaporTelegramBot/Json/SendApi/TelegramSendChatIdentifier.swift rename to Sources/TelegramBot/Json/SendApi/TelegramSendChatIdentifier.swift index c453940..77f06e4 100644 --- a/Sources/VaporTelegramBot/Json/SendApi/TelegramSendChatIdentifier.swift +++ b/Sources/TelegramBot/Json/SendApi/TelegramSendChatIdentifier.swift @@ -1,6 +1,6 @@ // // TelegramSendChatIdentifier.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/Json/SendApi/TelegramSendMessage.swift b/Sources/TelegramBot/Json/SendApi/TelegramSendMessage.swift similarity index 99% rename from Sources/VaporTelegramBot/Json/SendApi/TelegramSendMessage.swift rename to Sources/TelegramBot/Json/SendApi/TelegramSendMessage.swift index 73cf7d0..f6fc6d3 100644 --- a/Sources/VaporTelegramBot/Json/SendApi/TelegramSendMessage.swift +++ b/Sources/TelegramBot/Json/SendApi/TelegramSendMessage.swift @@ -1,6 +1,6 @@ // // TelegramSendMessage.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/VaporTelegramBot/VaporTelegramBot.swift b/Sources/TelegramBot/TelegramReceiveApi.swift similarity index 77% rename from Sources/VaporTelegramBot/VaporTelegramBot.swift rename to Sources/TelegramBot/TelegramReceiveApi.swift index d00b7a6..207a70c 100644 --- a/Sources/VaporTelegramBot/VaporTelegramBot.swift +++ b/Sources/TelegramBot/TelegramReceiveApi.swift @@ -1,14 +1,13 @@ // -// VaporTelegramBot.swift -// VaporTelegramBot +// TelegramReceiveApi.swift +// TelegramBot // // Created by Koray Koska on 17.01.19. // import Foundation -import Vapor -public final class VaporTelegramBot { +public final class TelegramReceiveApi { public typealias Update = (_ id: Int, _ update: UpdateType) -> () @@ -64,20 +63,35 @@ public final class VaporTelegramBot { * Setup a Telegram bot webhook for the given path. * * Updates will call their corresponding update callbacks - * as defined in this instance of `VaporTelegramBot` + * as defined in this instance of `TelegramReceiveApi` * * - parameter path: The path this webhook should be setup on. * May be something like the bot token as * defined in the best practices of the * official bot api. - * - parameter router: The vapor router to be used for setting + * - parameter router: The router to be used for setting * up the route. */ - public func setupWebhook(path: String, router: Router) { - router.post(path) { req -> Future in - // defaultDecoder.decode(TelegramUpdate.self, from: req.json) + public func setupWebhook(path: String, router: TelegramHTTPRouter) { + setupWebhook(path: path, routerFunction: router.register) + } - return try req.content.decode(TelegramUpdate.self, using: self.defaultDecoder).map { update in + /** + * Setup a Telegram bot webhook for the given path. + * + * Updates will call their corresponding update callbacks + * as defined in this instance of `TelegramReceiveApi` + * + * - parameter path: The path this webhook should be setup on. + * May be something like the bot token as + * defined in the best practices of the + * official bot api. + * - parameter routerFunction: The router function to be used for setting + * up the route. + */ + public func setupWebhook(path: String, routerFunction: (_ path: String, _ callback: @escaping (_ req: TelegramHTTPRequest, _ cb: @escaping (TelegramHTTPStatus) -> ()) throws -> ()) -> ()) { + routerFunction(path) { req, cb in + try req.json(TelegramUpdate.self, decoder: self.defaultDecoder) { update in let updates: [Any?] = [ update.message, update.editedMessage, @@ -93,7 +107,8 @@ public final class VaporTelegramBot { // At most one of the optional parameters can be present in any given update. // Return unsuccessful if more are present. if updates.filter({ $0 == nil }).count < updates.count - 1 { - return HTTPStatus.badRequest + cb(.badRequest) + return } if let messageUpdate = update.message { @@ -116,7 +131,8 @@ public final class VaporTelegramBot { self.preCheckoutQueryUpdate?(update.updateId, preCheckoutQueryUpdate) } - return HTTPStatus.ok + // Callback and return ok + cb(.ok) } } } diff --git a/Sources/VaporTelegramBot/TelegramSendApi.swift b/Sources/TelegramBot/TelegramSendApi.swift similarity index 93% rename from Sources/VaporTelegramBot/TelegramSendApi.swift rename to Sources/TelegramBot/TelegramSendApi.swift index 286fd96..23a8c65 100644 --- a/Sources/VaporTelegramBot/TelegramSendApi.swift +++ b/Sources/TelegramBot/TelegramSendApi.swift @@ -1,6 +1,6 @@ // // TelegramSendApi.swift -// VaporTelegramBot +// TelegramBot // // Created by Koray Koska on 24.01.19. // diff --git a/Sources/TelegramBot/Toolbox/Router.swift b/Sources/TelegramBot/Toolbox/Router.swift new file mode 100644 index 0000000..8485900 --- /dev/null +++ b/Sources/TelegramBot/Toolbox/Router.swift @@ -0,0 +1,66 @@ +// +// Router.swift +// TelegramBot +// +// Created by Koray Koska on 28.01.19. +// + +import Foundation + +public protocol TelegramHTTPRouter { + + func register(path: String, callback: @escaping (_ req: TelegramHTTPRequest, _ cb: @escaping (TelegramHTTPStatus) -> ()) throws -> ()) +} + +public protocol TelegramHTTPRequest { + + func json(_ type: Type.Type, decoder: JSONDecoder, callback: @escaping (_ json: Type) -> ()) throws +} + +public enum TelegramHTTPStatus { + + case ok + case badRequest + case internalServerError +} + +// MARK: - Default Vapor implementation + +#if canImport(Vapor) + +import Vapor + +extension Router { + + public func register(path: String, callback: @escaping (_ req: TelegramHTTPRequest, _ cb: @escaping (TelegramHTTPStatus) -> ()) throws -> ()) { + post(path) { reqInternal -> Future in + let promiseStatus = reqInternal.eventLoop.newPromise(HTTPStatus.self) + + try callback(reqInternal) { status in + switch status { + case .ok: + promiseStatus.succeed(result: .ok) + case .badRequest: + promiseStatus.succeed(result: .badRequest) + case .internalServerError: + promiseStatus.succeed(result: .internalServerError) + } + } + + return promiseStatus.futureResult + } + } +} + +extension Request: TelegramHTTPRequest { + + public func json(_ type: Type.Type, decoder: JSONDecoder, callback: @escaping (Type) -> ()) throws { + _ = try content.decode(json: Type.self, using: decoder).map { decoded -> () in + callback(decoded) + + return () + } + } +} + +#endif diff --git a/Tests/VaporTelegramBotTests/AppTests.swift b/Tests/TelegramBotTests/AppTests.swift similarity index 90% rename from Tests/VaporTelegramBotTests/AppTests.swift rename to Tests/TelegramBotTests/AppTests.swift index b978550..5cc03b1 100644 --- a/Tests/VaporTelegramBotTests/AppTests.swift +++ b/Tests/TelegramBotTests/AppTests.swift @@ -1,4 +1,4 @@ -import VaporTelegramBot +import TelegramBot import XCTest final class AppTests: XCTestCase {