Ruby bindings and client for TDLib (Telegram database library).
- Ruby 2.3+
- Compiled tdlib
We have precompiled versions for CentOS 6 & 7 in our repositories:
http://rpms.southbridge.ru/rhel7/stable/x86_64/
http://rpms.southbridge.ru/rhel6/stable/x86_64/
And also SRPMS:
http://rpms.southbridge.ru/rhel7/stable/SRPMS/
http://rpms.southbridge.ru/rhel6/stable/SRPMS/
Add to your gemfile:
gem'tdlib-ruby'and run bundle install.
Or just run gem install tdlib-ruby
require'tdlib-ruby'TD.configuredo |config|
config.lib_path='path_to_dir_containing_tdlibjson'config.client.api_id=your_api_idconfig.client.api_hash='your_api_hash'endTD::Api.set_log_verbosity_level(1)client=TD::Client.newbeginstate=nilclient.on(TD::Types::Update::AuthorizationState)do |update|
state=caseupdate.authorization_statewhenTD::Types::AuthorizationState::WaitPhoneNumber:wait_phone_numberwhenTD::Types::AuthorizationState::WaitCode:wait_codewhenTD::Types::AuthorizationState::WaitPassword:wait_passwordwhenTD::Types::AuthorizationState::Ready:readyelsenilendendloopdocasestatewhen:wait_phone_numberputs'Please, enter your phone number:'phone=STDIN.gets.stripclient.set_authentication_phone_number(phone).valuewhen:wait_codeputs'Please, enter code from SMS:'code=STDIN.gets.stripclient.check_authentication_code(code).valuewhen:wait_passwordputs'Please, enter 2FA password:'password=STDIN.gets.stripclient.check_authentication_password(password).valuewhen:ready@me=client.get_me.valuebreakendendensureclient.closeendp@meFrom version 1.0 TD::Client#broadcast returns Concurrent::Promise object.
me=client.broadcast('@type'=>'getMe').then{ |result| putsresult}.rescue{ |error| putserror}.valueTD.configuredo |config|
config.lib_path='path/to/dir_containing_libtdjson'# libtdson will be searched in this directory (*.so, *.dylib, *.dll are valid extensions). For Rails projects, if not set, will be considered as project_root_path/vendor. If not set and file doesn't exist in vendor, it will try to find lib by ldconfig (only on Linux).config.encryption_key='your_encryption_key'# it's not requiredconfig.client.api_id=12345config.client.api_hash='your_api_hash'config.client.use_test_dc=true# default: falseconfig.client.database_directory='path/to/db/dir'# default: "#{Dir.home}/.tdlib-ruby/db"config.client.files_directory='path/to/files/dir'# default: "#{Dir.home}/.tdlib-ruby/files"config.client.use_file_database=true# default: trueconfig.client.use_chat_info_database=true# default: trueconfig.client.use_secret_chats=true# default: trueconfig.client.use_message_database=true# default: trueconfig.client.system_language_code='ru'# default: 'en'config.client.device_model='Some device model'# default: 'Ruby TD client'config.client.system_version='42'# default: 'Unknown'config.client.application_version='1.0'# default: '1.0'config.client.enable_storage_optimizer=true# default: trueconfig.client.ignore_file_names=true# default: falseendYou can get rid of large tdlib log with
TD::Api.set_log_verbosity_level(1)You can also set log file path:
TD::Api.set_log_file_path('path/to/log_file')Additional options can be passed to client:
TD::Client.new(database_directory: 'will override value from config',files_directory: 'will override value from config')The gem is designed by Southbridge
Typeization made by Yuri Mikhaylov