Coder Social home page Coder Social logo

telegrammer's Introduction

SwiftyBot Banner

Telegrammer

Telegram Bot Framework written in Swift 4.1 with SwiftNIO network framework

Build Version Language Platform License


What does it doDocumentationHOWTO GuidesUsage without VaporUsage with VaporDemo botsRequirementsContributingAuthor


What does it do

Telegrammer is open-source framework for Telegram Bots developers. It was built on top of Apple/SwiftNIO which help to demonstrate excellent performance.

SwiftNIO is a cross-platform asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers and clients.

Also Telegrammer use some submodules of Vapor 3 server side swift framework

Join to our Telegram developers chat

Join to our Telegrammer channel on Vapor Discord server

It's easy, from scratch

main.swift

import Telegrammer

let bot = try! Bot(token: "BOT_TOKEN_HERE")

let commandHandler = CommandHandler(commands: ["/hello"], callback: { (update, _) in
    guard let message = update.message, let user = message.from else { return }
    try! message.reply("Hello \(user.firstName)", from: bot)
})

let dispatcher = Dispatcher(bot: bot)
dispatcher.add(handler: commandHandler)

_ = try! Updater(bot: bot, dispatcher: dispatcher).startLongpolling().wait()

Documentation

HOWTO Guides

Usage without Vapor

  1. Create package with Swift Package Manager (SPM)
$ mkdir MyBot
$ cd MyBot
$ swift package init --type executable
  1. Define Dependencies in Package.swift file
let package = Package(
    name: "MyBot",
    dependencies: [
        .package(url: "https://github.com/givip/Telegrammer.git", from: "0.4.0")
        ],
    targets: [
        .target( name: "MyBot", dependencies: ["Telegrammer"])
        ]
)
  1. Resolve dependencies
$ swift package resolve
  1. Generate XCode project (for macOS only)
$ swift package generate-xcodeproj
  1. Open in XCode (for macOS only)
$ open MyBot.xcodeproj

You project is ready to create new Telegram Bot.

If you need more help through this steps, you can read How to create a Telegram bot with Telegrammer on Ubuntu / macOS

Usage with Vapor

You may also use previous way to create project with Vapor, only include Vapor as dependency in Package.swift

  1. Install Vapor CLI
$ brew install vapor/tap/vapor
  1. Create Vapor project with Telegrammer template
$ vapor new MyBot --template=https://github.com/givip/telegram-bot-template
  1. Generate XCode project
$ vapor xcode

Demo bots

EchoBot Sample

  1. Add Telegram Token in Environment Variables, so, either create an environment variable:
$ export TELEGRAM_BOT_TOKEN='000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
  1. Run EchoBot executable scheme or
$ swift run
  1. Send /echo command to bot

Requirements

Contributing

See CONTRIBUTING.md file.

Author

Givi Pataridze

[email protected]

telegrammer's People

Contributors

givip avatar nerzh avatar

Watchers

 avatar  avatar

Forkers

tonidevine1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.