• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🤖 Crossplatform chatbot framework for Swift supporting Telegram & VK

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

[email protected] @cooloneofficial