diff options
author | aunsane <aunsane@gmail.com> | 2018-04-27 21:33:17 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-04-27 21:33:17 +0300 |
commit | e1ec72eab6d00b3ba38e5932bc88920f103b6e4a (patch) | |
tree | 999de2725a83e30fbbf6576200525d4ef0c5fe38 /protocols/Telegram/tdlib/td/example/ruby/example.rb | |
parent | b9ce1d4d98525490ca1a38e2d9fd4f3369adb3e0 (diff) |
Telegram: initial commit
- tdlib moved to telegram dir
Diffstat (limited to 'protocols/Telegram/tdlib/td/example/ruby/example.rb')
-rw-r--r-- | protocols/Telegram/tdlib/td/example/ruby/example.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/protocols/Telegram/tdlib/td/example/ruby/example.rb b/protocols/Telegram/tdlib/td/example/ruby/example.rb new file mode 100644 index 0000000000..4b29dfd53a --- /dev/null +++ b/protocols/Telegram/tdlib/td/example/ruby/example.rb @@ -0,0 +1,61 @@ +require 'tdlib-ruby' + +TD.configure do |config| + config.lib_path = 'path/to/dir_containing_lobtdjson' + + # You should obtain your own api_id and api_hash from https://my.telegram.org/apps + config.client.api_id = 12345 + config.client.api_hash = '1234567890abcdefghigklmnopqrstuv' +end + +TD::Api.set_log_verbosity_level(1) + +client = TD::Client.new + +begin + state = nil + + client.on('updateAuthorizationState') do |update| + next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitPhoneNumber' + state = :wait_phone + end + + client.on('updateAuthorizationState') do |update| + next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitCode' + state = :wait_code + end + + client.on('updateAuthorizationState') do |update| + next unless update.dig('authorization_state', '@type') == 'authorizationStateReady' + state = :ready + end + + loop do + case state + when :wait_phone + p 'Please, enter your phone number:' + phone = STDIN.gets.strip + params = { + '@type' => 'setAuthenticationPhoneNumber', + 'phone_number' => phone + } + client.broadcast_and_receive(params) + when :wait_code + p 'Please, enter code from SMS:' + code = STDIN.gets.strip + params = { + '@type' => 'checkAuthenticationCode', + 'code' => code + } + client.broadcast_and_receive(params) + when :ready + @me = client.broadcast_and_receive('@type' => 'getMe') + break + end + end + +ensure + client.close +end + +p @me |