Git Product home page Git Product logo

telegrammer's Introduction

SwiftyBot Banner

Telegrammer

Telegram Bot Framework written in Swift 5.1 with SwiftNIO network framework

Build Version Language Platform License

What does it do

Telegrammer is open-source framework for Telegram Bots developers. It was built on top of Apple/SwiftNIO

Join to our Telegram developers chat Join to our Telegrammer channel on Vapor Discord server

The simplest code of Echo Bot looks like this:


main.swift

import Foundation
import Telegrammer

do {
    let bot = try Bot(token: "BOT_TOKEN_HERE")

    let echoHandler = MessageHandler { (update, _) in
        _ = try? update.message?.reply(text: "Hello \(update.message?.from?.firstName ?? "anonymous")", from: bot)
    }

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

    _ = try Updater(bot: bot, dispatcher: dispatcher).startLongpolling().wait()
} catch {
    exit(1)
}

Documentation

Usage without Vapor

Usage with Vapor

Demo bots

All sample bots

  1. Add Telegram Token in Environment Variables, so, either create an environment variable:
$ export TELEGRAM_BOT_TOKEN='000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
  1. Run Bot executable scheme or
$ swift run

EchoBot sources Starts/stops with command "/echo", then simply responds with your message

HelloBot sources Says "Hello" to new users in group. Responds with "hello" message on command "/greet"

SchedulerBot sources Demonstrate Jobs Queue scheduling mechanism. Command "/start X" starts repeatable job, wich will send you a message each X seconds. Command "/once X" will send you message once after timeout of X seconds. Command "/stop" stops JobsQueue only for you. Other users continues to receive scheduled messages.

SpellCheckerBot sources Demonstrate how works InlineMenus and Callback handlers. Command "/start" will start bot. Send any english text to bot and it will be checked for mistakes. Bot will propose you some fixes in case of found mistake.

Requirements

Contributing

See CONTRIBUTING.md file.

Author

Givi Pataridze

[email protected] @givip

telegrammer's People

Contributors

cooloneofficial avatar ferrerohub avatar givip avatar hootigger avatar nerzh avatar nikstar avatar theeshka avatar uetcis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telegrammer's Issues

Crash on using combined filters (EXC_BAD_ACCESS)

When using a combined filter in a telegrammer-vapor-middleware based app like so (here a 'not'):

        let answerHandler = MessageHandler(filters: !Filters.command,
                                           callback: answerResponse)
        dispatcher.add(handler: answerHandler,to: HandlerGroup.answers)


it results in the following crash on an incoming update:
image

Not only for the logical not (!), but same result for other logical operations (like and: &&, or: ||)
Without logical operations it works like expected.

Implement Message object helpers

  • caption_html
  • caption_html_urled
  • caption_markdown
  • caption_markdown_urled
  • chat_id
  • delete
  • edit_caption
  • edit_reply_markup
  • edit_text
  • effective_attachment
  • forward
  • parse_caption_entities
  • parse_caption_entity
  • parse_entities
  • parse_entity
  • reply_audio
  • reply_contact
  • reply_document
  • reply_html
  • reply_location
  • reply_markdown
  • reply_media_group
  • reply_photo
  • reply_sticker
  • reply_text
  • reply_venue
  • reply_video
  • reply_video_note
  • reply_voice
  • text_html
  • text_html_urled
  • text_markdown
  • text_markdown_urled

Using Telegrammer with Vapor and Fluent (Postgresql)

I've set up a project with Telegrammer and Vapor. I've installed the postgresql driver and registered FluentPostgreSQLProvider, but I'm not sure how to get a database connection in my bot class.

If I have a model called User and I want to query all users, I'd write the following code: User.query(on: conn).all(), where conn is an object that conforms to DatabaseConnectable. I'm not sure where/how I can access this object in my bot class.

Timeout

After an arbitrary number of incoming connections of the web hook, i get a timeout for get updates. Is there an option to reconnect?

[2019-01-14T13:17:07.558Z] [INFO] [BotClient.swift:45 respond(endpoint:body:headers:)] Sending request:
POST https://api.telegram.org:443/bot729517131:AAFH1wdt6_rnVxXFyNmY_jsLLzUmCtJ-P8w/getUpdates HTTP/1.1
Content-Type: application/json
content-length: 14
{"timeout":20}
[2019-01-14T13:17:07.573Z] [INFO] [BotClient.swift:68 send(request:)] Creating new HTTP Client
[2019-01-14T13:17:07.574Z] [INFO] [BotClient.swift:78 send(request:)] Sending request to vapor HTTPClient
[2019-01-14T13:17:27.601Z] [INFO] [BotClient.swift:82 send(request:)] Decoding response from HTTPClient
[2019-01-14T13:17:27.601Z] [VERBOSE] [Bot.swift:59 wrap] 
Received response
Code: 0
Status OK: true
Description: Empty
Result: [
  
]

Webhook certificate text instead of file path?

First of all, great repo BTW. Thanks for this 🎉

I noticed that the code is expecting the pem certificate's path.

if let publicCert = bot.settings.webhooksPublicCert {
  guard let fileHandle = FileHandle(forReadingAtPath: publicCert) else {
    let errorDescription = "Public key '\(publicCert)' was specified for HTTPS server, but wasn't found"
    log.error(errorDescription.logMessage)
    throw CoreError(identifier: "FileIO", reason: errorDescription)
  }

  cert = InputFile(data: fileHandle.readDataToEndOfFile(), filename: publicCert)
}

Since I'm deploying the bot with Dokku, I don't have too much control on the file system (everything running on containers). I was thinking about an option of getting the certficate's content on another environment variable. What do you think?

Extra argument 'from' in call

Hello!

First I want to thank you for your amazing library, I find it extremely convenient to work with.
Now back to my issue. I can't build my project if I use the function below

self.dispatcher.remove(handler: handler, from: group)

I get the error
Error:(76, 60) extra argument 'from' in call

I can't understand what's wrong with it. group variable is correct and has type HandlerGroup. I'm using Swift 4.1. Does your project successfully build using the line like this?

Thank you!

Create documentation

  • Generation parameters documentation for Telegram models in grenerate_wrappers.rb
  • Documentation for public classes

Language filter implementation

Filters messages to only allow those which are from users with a certain language code.

Note: According to telegrams documentation, every single user does not have the language_code attribute.

Implement Delay Queue

Processes callbacks from queue with specified throughput limits. Creates a separate thread to process callbacks with delays.

Problem running generate_wrappers.rb

Hi! I wanted to update generated files, but the script crashed on the line below

continue unless text.length != 0

./generate_wrappers.rb:178:in `fetch_description': undefined local variable or method `continue' for main:Object (NameError)

I'm not sure what continue is, but it does not seem to be part of ruby :)

As far as I can tell, commenting out this line does not break anything. Will it be safe to remove it?

Fail update dependency

swift package generate-xcodeproj return error after update to 0.5.4 version.

Console log:

error: multiple products named 'Logging' in: Console, swift-log
error: multiple targets named 'Logging' in: Console, swift-log

Swift version:

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.2.0

Implement Message Queue

Implements callback processing with proper delays to avoid hitting Telegram’s message limits.

Implement Conversation Handler

A handler to hold a conversation with a single user by managing four collections of other handlers. Note that neither posts in Telegram Channels, nor group interactions with multiple users are managed by instances of this class.

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.