abdfnx-cemetery / botway-swift

Swift Client Package For Botway.

Home Page:https://github.com/abdfnx/botway

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Botway-Swift

Swift client package for Botway

Usage

after creating a new swift botway project, you need to use your tokens to connect with your bot.

import Foundation
import TelegramBotSDK

let bot = TelegramBot(token: GetToken())
let router = Router(bot: bot)

router["greet"] = { context in
    guard let from = context.message?.from else { return false }
    context.respondAsync("Hello, \(from.firstName)!")

    return true
}

router[.newChatMembers] = { context in
    guard let users = context.message?.newChatMembers else { return false }

    for user in users {
        guard user.id != bot.user.id else { continue }
        context.respondAsync("Welcome, \(user.firstName)!")
    }

    return true
}

while let update = bot.nextUpdateSync() {
	try router.process(update: update)
}

fatalError("Server stopped due to error: \(bot.lastError)")

About

Swift Client Package For Botway.

https://github.com/abdfnx/botway

License:MIT License


Languages

Language:Swift 100.0%