21 lines
949 B
Swift
21 lines
949 B
Swift
|
import Foundation
|
||
|
import Vapor
|
||
|
import SwiftTelegramSdk
|
||
|
|
||
|
public func configure(_ app: Application) async throws {
|
||
|
guard let tgApi: String = Environment.get("TG_BOT_API") else { throw Errors.notVariable("Telegram key is not defined")}
|
||
|
app.logger.logLevel = .debug
|
||
|
let bot: TGBot = try await .init(connectionType: .longpolling(limit: nil,
|
||
|
timeout: nil,
|
||
|
allowedUpdates: nil),
|
||
|
dispatcher: nil,
|
||
|
tgClient: VaporTGClient(client: app.client),
|
||
|
tgURI: TGBot.standardTGURL,
|
||
|
botId: tgApi,
|
||
|
log: app.logger)
|
||
|
await botActor.setBot(bot)
|
||
|
await DefaultBotHandlers.addHandlers()
|
||
|
try await botActor.bot.start()
|
||
|
// try routes(app)
|
||
|
}
|