Skip to content

rapierorg/telegram-bot-swift-vapor-provider

Repository files navigation

Swift Chat Platform License

TelegramBotSDK Vapor Provider

This package is part of TelegramBotSDK

You need just to add these lines to your Vapor app:

File: Package.swift

  • Add .package(url: "https://github.com/rapierorg/telegram-bot-swift-vapor-provider.git", from: "0.2.1"),
  • Add TelegramBotSDKVaporProvider to your App target dependencies

File: configure.swift

Add the following lines to your configure function:

services.register(TelegramBotConfig(apiToken: "your-api-token-here", routerConfiguration: { (router) in
    // Configure TelegramBotSDK router here
}))
try services.register(TelegramBotProvider())

File: routes.swift

router.post("change", "me") { (request) -> HTTPStatus in // Change route
    let telegramClient = try request.make(TelegramBotClient.self)
    try telegramClient.handleRequest(request)
    return .ok
}

Optional: boot.swift

let telegramClient = try app.make(TelegramBotClient.self)
telegramClient.bot.setWebhookSync(url: "your-webhook-url-here")