Swiftpack.co -  CoolONEOfficial/Botter as Swift Package
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.2")

Vkontakter logo

Botter

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

MacOS Ubuntu Version Language Platform License

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)
let vkPort = Int(Enviroment.get("VK_PORT") ?? "1213")!

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

var tgSettings = Telegrammer.Bot.Settings(token: tgToken)
let tgPort = Int(Enviroment.get("TG_PORT") ?? "1212")!
 
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: 1
Last commit: 5 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.1.2
2 weeks ago

Update deps Minor changes

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