Botter
Crossplatform Bot Framework written in Swift 5.3 with Vapor framework unifying Telegrammer and Vkontakter
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
- Read our wiki
- Read An official documentation of Vapor
Requirements
- Ubuntu 16.04 or later with Swift 5.1 or later / macOS with Xcode 11 or later
- Vk account and a Vk App for mobile platform or online (desktop client does not support some chatbot features)
- Swift Package Manager (SPM) for dependencies
- Vapor 4
Contributing
See CONTRIBUTING.md file.
Author
Nikolai Trukhin
[email protected] @cooloneofficial