All Projects → ShaneQi → ZEGBot

ShaneQi / ZEGBot

Licence: Apache-2.0 license
Build your Telegram Bot with Swift! (works on macOS / Ubuntu)

Programming Languages

swift
15916 projects
shell
77523 projects

Projects that are alternatives of or similar to ZEGBot

Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+376.92%)
Mutual labels:  server-side-swift, telegram-bot-api
BSON
Native Swift library for BSON (http://bsonspec.org)
Stars: ✭ 98 (+88.46%)
Mutual labels:  server-side-swift
Console Kit
💻 APIs for creating interactive CLI tools.
Stars: ✭ 252 (+384.62%)
Mutual labels:  server-side-swift
Perfect-WebSocketsServer
Perfect Example Module: WebSockets Server
Stars: ✭ 34 (-34.62%)
Mutual labels:  server-side-swift
aiogram-structured
Code your aiogram bot faster, easier & modular.
Stars: ✭ 32 (-38.46%)
Mutual labels:  telegram-bot-api
theimagebot
Blog.TheOstrich.Eu.Org
Stars: ✭ 15 (-71.15%)
Mutual labels:  telegram-bot-api
Mongo Swift Driver
The official MongoDB driver for Swift
Stars: ✭ 242 (+365.38%)
Mutual labels:  server-side-swift
python-telegram-bot-calendar
Python inline calendar for Telegram bots
Stars: ✭ 71 (+36.54%)
Mutual labels:  telegram-bot-api
gotgbot
Autogenerated Go wrapper for the telegram API. Inspired by the python-telegram-bot library.
Stars: ✭ 178 (+242.31%)
Mutual labels:  telegram-bot-api
telegram-bot-dumper
🔪 Dumper & ripper for Telegram bots by token
Stars: ✭ 82 (+57.69%)
Mutual labels:  telegram-bot-api
awesome-swift-nio
📖 A collaborative list of all things Swift NIO
Stars: ✭ 81 (+55.77%)
Mutual labels:  server-side-swift
Perfect-URL-Shortener
An Example URL Shortener System for Perfect
Stars: ✭ 37 (-28.85%)
Mutual labels:  server-side-swift
wptelegram
Integrate your WordPress site perfectly with Telegram with full control.
Stars: ✭ 31 (-40.38%)
Mutual labels:  telegram-bot-api
SwiftMC
A Minecraft server and proxy written from scratch in Swift.
Stars: ✭ 22 (-57.69%)
Mutual labels:  server-side-swift
Kitura-NIO
A networking library for Kitura, based on SwiftNIO
Stars: ✭ 35 (-32.69%)
Mutual labels:  server-side-swift
Futures
Lightweight promises for iOS, macOS, tvOS, watchOS, and Linux
Stars: ✭ 59 (+13.46%)
Mutual labels:  server-side-swift
VaporTwilioService
Twilio API provider for all your Vapor needs
Stars: ✭ 19 (-63.46%)
Mutual labels:  server-side-swift
nestjs-telegraf
🤖 Powerful Nest module for easy and fast creation Telegram bots
Stars: ✭ 300 (+476.92%)
Mutual labels:  telegram-bot-api
sqlite-kit
Non-blocking SQLite client library with SQL builder built on SwiftNIO
Stars: ✭ 51 (-1.92%)
Mutual labels:  server-side-swift
PassEncoder
Simple PassKit (Apple Wallet) encoding and signing in Swift.
Stars: ✭ 28 (-46.15%)
Mutual labels:  server-side-swift

ZEGBot

CI Swift Version Platforms License

This library wraps the JSON decoding processing, making it easy to decode incoming JSON String to manipulatable objects.

This library wraps the processing of converting objects to Telegram Bot API request parameters and the processing of performing request, making it easy to handle incoming update.

Installation

Add this project as a dependency in your Package.swift file.

.package(url: "https://github.com/shaneqi/ZEGBot.git", from: Version(4, 2, 8))

Quick Start

Checkout the example here: ./Example.

Or you can just put the following code into main.swift of your project.

  • Sending messages directly:
import ZEGBot

// Don't forget to fill in your bot token.
let bot = ZEGBot(token: "TYPE YOUR TOKEN HERE")

do {
  try bot.send(message: "Hello world!", to: AnyChat(chatId: CHAT_ID))
} catch let error {
  NSLog("Bot exit due to: \(error)")
}
  • or responding to incoming messages/updates:
import ZEGBot

// Don't forget to fill in your bot token.
let bot = ZEGBot(token: "YOUR_BOT_TOKEN")

do {
  try bot.run { updates, bot in
    // Handle updates here...
  }
} catch let error {
  NSLog("Bot exit due to: \(error)")
}

Usage

  • Get text content of the incoming message:

    ...
    if let text = update.message?.text {
      // Do something.
    }
    ...
  • Get other type of content if exists:

    ...
    if let voice = update.message?.voice {
      // Do something.
    }
    ...
  • Send a text message to a chat:

    ...
    if let message = update.message {
      do {
        try bot.send(message: "bar", to: message.chat)
      } catch let error {
        NSLog("Failed to send message due to: \(error)")
      }
    }
    ...

    or

    ...
    do {
      try bot.send(message: "bar", to: AnyChat(chatId: CHAT_ID))
    } catch let error {
      NSLog("Failed to send message due to: \(error)")
    }
    ...
  • Send a silent message with a none-preview markdown link to a chat:

    ...
    do {
      try bot.send(
        message: "[Google](https://google.com)",
        to: AnyChat(chatId: CHAT_ID),
        parseMode: .markdown,
        disableWebPagePreview: true,
        disableNotification: true)
    } catch let error {
      NSLog("Failed to send message due to: \(error)")
    }
    ...
  • In all the sending methods, send to a Message Object means reply to this specific message. While Send to a Chat Object means send to this chat without replying to anyone.

    ...
    if let message = update?.message {
      do {
        /* This sends a message replying to another message. */
        try bot.send(message: "bar", to: message)
        /* This doesn't reply to a message. */
        try bot.send(message: "bar", to: message.chat)
      } catch let error {
        NSLog("Failed to send message due to: \(error)")
      }
    }
    ...

Support Types

  • Update
  • Message
  • Chat
  • User
  • MessageEntity
  • Audio
  • Document
  • PhotoSize
  • Sticker
  • Video
  • Voice
  • Contact
  • Location
  • Venue
  • File
  • ParseMode
  • ChatAction
  • ChatMember
  • InlineKeyboardButton
  • InlineKeyboardMarkup
  • CallbackQuery

Not all the types are supported, checkout more details on Telegram Bot API.

Support Methods

  • sendMessage
  • forwardMessage
  • sendPhoto
  • sendAudio
  • sendDocument
  • sendSticker
  • sendVideo
  • sendVoice
  • sendLocation
  • sendVenue
  • sendContact
  • sendChatAction
  • getFile
  • deleteMessage
  • getChatAdministrators
  • answerCallbackQuery
  • restrictChatMember
  • kickChatMember
  • editMessageText
  • editMessageCaption

Not all the methods are supported, checkout more details on Telegram Bot API.

Feature Requests are VERY WELCOME

The goal of this project is NOT keeping updated to the latest Telegram bot API, but to serve the community. So even though you don't see the API features you need in this project, please CONTACT ME, and I WILL do my best to add the features you requested.

License

This project is licensed under Apache License v2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].