telegram-auth-bot/Sources/TelegramModeratorBot/configure.swift

23 lines
977 B
Swift
Raw Normal View History

2024-10-19 17:39:04 +03:00
import Foundation
import Vapor
@preconcurrency import SwiftTelegramSdk
2024-10-19 17:39:04 +03:00
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")
}
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)
await DefaultBotHandlers.addHandlers(bot)
2024-10-19 17:39:04 +03:00
try await botActor.bot.start()
// try routes(app)
}