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

21 lines
949 B
Swift
Raw Normal View History

2024-10-19 17:39:04 +03:00
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)
}