Skip to content
This repository has been archived by the owner on Dec 27, 2020. It is now read-only.

ssut/telegram-rb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram API for Ruby!

DUB Gem Version Code Climate Inline docs

Gitter

A Ruby wrapper that communicates with the Telegram-CLI.

Installation

Requirements

  • You need to install the Telegram-CLI version 1.3.0 or higher first.

RubyGems

In order to use the telegram-rb you will need to install the gem (either manually or using Bundler), and require the library in your Ruby application:

$ gem install telegram-rb

or in your Gemfile:

# latest stable
gem 'telegram-rb', require: 'telegram'

# or track master repo
gem 'telegram-rb', github: 'ssut/telegram-rb', require: 'telegram'

Usage

The library uses EventMachine, so the logic is wrapped in EM.run.

# When using Bundler, let it load all libraries
require 'bundler' 
Bundler.require(:default) 

# Otherwise, require 'telegram', which will load its dependencies
# require 'telegram'

EM.run do
  telegram = Telegram::Client.new do |cfg, auth|
    cfg.daemon = '/path/to/tg/bin/telegram-cli'
    cfg.key = '/path/to/tg/tg-server.pub'
    cfg.config_file = '/path/to/config' # optional, default file will be used if not set
    cfg.profile = 'user2' # optional, the profiles must be configured in ~/.telegram-cli/config
    cfg.logger = Logger.new(STDOUT) # optional, default logger will be created if not set

    # optional properties, could be used for authorization/registration telegram accounts
    auth.phone_number = '<valid phone number>'
    auth.confirmation_code = -> { '<received confirmation code via sms or call>' }
    auth.register = { # required in case with registration new telegram account
      first_name: '<user first name>',
      last_name: '<user last name>'
    }
  end

  telegram.connect do
    # This block will be executed when initialized.
    
    # See your telegram profile
    puts telegram.profile

    telegram.contacts.each do |contact|
      puts contact
    end
    
    telegram.chats.each do |chat|
      puts chat
    end
    
    # Event listeners
    # When you've received a message:
    telegram.on[Telegram::EventType::RECEIVE_MESSAGE] = Proc.new do |event|
      # `tgmessage` is TelegramMessage instance
      puts event.tgmessage
    end 

    # When you've sent a message:
    telegram.on[Telegram::EventType::SEND_MESSAGE] = Proc.new do |event|
      puts event
    end

    # When connection is closed:
    telegram.on_disconnect = Proc.new do
      puts 'Connection with telegram-cli is closed'
    end
  end
end

Documentation

You can check documentation from here!

My goal is to have the code fully documentated for the project, so developers can use this library easily!

Coverage (TODO)

  • Messaging/Multimedia
    • Send typing signal to specific user or chat
    • Send a message to specific user or chat
    • Send an image to specific user or chat
    • Send a video to specific user or chat
    • Mark as read all received messages
    • Download an image of someone sent
    • Forward a message to specific user
    • Set profile picture
  • Group chat options
    • Add a user to the group
    • Remove a user from the group
    • Leave from the group
    • Create a new group chat
    • Set group chat photo
    • Rename group chat title
  • Search
    • Search for specific message from a conversation
    • Search for specific message from all conversions
  • Secret chat
    • Reply message in secret chat
    • Visualize of encryption key of the secret chat
    • Create a new secret chat
  • Stats and various info
    • Get user profile
    • Get chat list
    • Get contact list
    • Get history and mark it as read
  • Card
    • export card
    • import card

Contributing

If there are bugs or things you would like to improve, fork the project, and implement your awesome feature or patch in its own branch, then send me a pull request here!

License

telegram-rb is licensed under the MIT License.

The MIT License (MIT)

Copyright (c) 2015 SuHun Han

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A Ruby wrapper that communicates with the Telegram-CLI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages