2024-10-19 17:39:04 +03:00
|
|
|
import Foundation
|
|
|
|
import Vapor
|
2024-10-19 18:14:11 +03:00
|
|
|
@preconcurrency import SwiftTelegramSdk
|
2024-10-19 17:39:04 +03:00
|
|
|
|
|
|
|
public func configure(_ app: Application) async throws {
|
2024-10-20 18:42:00 +03:00
|
|
|
guard let tgApi: String = Environment.get("TG_BOT_API") else {
|
|
|
|
throw Errors.notVariable("Telegram key is not defined")
|
|
|
|
}
|
2024-10-19 17:39:04 +03:00
|
|
|
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)
|
2024-10-20 18:42:00 +03:00
|
|
|
await DefaultBotHandlers.addHandlers(bot)
|
2024-10-19 17:39:04 +03:00
|
|
|
try await botActor.bot.start()
|
|
|
|
// try routes(app)
|
|
|
|
}
|