Swiftpack.co -  Package - CoolONEOfficial/Botter
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
CoolONEOfficial/Botter
Crossplatform chatbot framework for Swift supporting Telegram & VK
.package(url: "https://github.com/CoolONEOfficial/Botter.git", from: "0.1.1")

Vkontakter logo

Botter

Crossplatform Bot Framework written in Swift 5.3 with Vapor framework unifying Telegrammer and Vkontakter

Build StatusVersionLanguagePlatformLicense

What does it do

Botter is open-source framework for crossplatform bots developers. It was built on top of Vapor framework

The simplest code of Echo Bot looks like this:


main.swift

import Foundation
import Botter
import Vkontakter
import Telegrammer

var vkSettings = Vkontakter.Bot.Settings(token: vkToken)

vkSettings.webhooksConfig = .init(
    ip: "0.0.0.0",
    url: Enviroment.get("VK_BOT_WEBHOOK_URL")!, // or use openUrl(80)
    groupId: UInt64(Enviroment.get("VK_GROUP_ID")!)!
)

var tgSettings = Telegrammer.Bot.Settings(token: tgToken)

let tgPort = Int(Enviroment.get("TG_PORT") ?? "8443")!
 
tgSettings.webhooksConfig = .init(
    ip: "0.0.0.0",
    url: Enviroment.get("TG_WEBHOOK_URL")!, // or use openUrl(tgPort)
    port: tgPort
)

var settings = Bot.Settings(vk: vkSettings, tg: tgSettings)

let bot = try Bot(settings: settings)

let echoHandler = MessageHandler { (update, context) in
    guard case let .message(message) = update.content,
          let text = message.text else { return }

    _ = try bot.getUser(from: update, app: context.app)?.throwingFlatMap { user in
        try message.reply(.init(text: "Hello, \(user.firstName ?? "anonymous")"), context: context)
    }
}

let dispatcher = Dispatcher(bot: bot)
dispatcher.add(handler: echoHandler)

_ = try Updater(bot: bot, dispatcher: dispatcher).startWebhooks(serverName: "testserver")

Documentation

Requirements

Contributing

See CONTRIBUTING.md file.

Author

Nikolai Trukhin

coolone.official@gmail.com @cooloneofficial

GitHub

link
Stars: 0
Last commit: 2 days ago

Release Notes

0.1.1
2 days ago

Updated Vkontakter

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco