Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

abdfnx-cemetery/botway-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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)")