Skip to content

Example from README doesn't work: "Parameters aren't specified" (setTdlibParameters) #72

@petRUShka

Description

@petRUShka

I'm using code from README. Only additions are using Bundler and printing config params. On execution, I see the following errors in logs:

 Receive request 1: setTdlibParameters {
  parameters = null
}
Sending error for request 1: error { code = 400 message = "Parameters aren't specified" }

tdlib version is 1.8.0 is installed from Arch Linux AUR: telegram-tdlib. In PKGBUILD there is a following line: source=("https://github.com/tdlib/td/archive/v$pkgver.tar.gz") which is basically referring the fact that source code is downloaded from https://github.com/tdlib/td/archive/v1.8.0.tar.gz.

from Gemfile.lock

    tdlib-ruby (3.1.0)
    tdlib-schema (1.7.0.4)

Full log:

❯ ruby minimal.rb
lib_path: /usr/lib/libtdjson.so
api_id: <API ID from my.telegram.org>
api_hash: <API HASH from my.telegram.org>
[ 3][t 1][1739658867.758758306][Td.cpp:2668][#1][!MultiTd]      Create Td with layer 135, database version 13 and version 35 on 4 threads
[ 3][t 1][1739658867.758826255][Td.cpp:4062][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.0"
  }
}
[ 3][t 1][1739658867.758874416][Td.cpp:4062][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateWaitTdlibParameters {
  }
}
[ 3][t 0][1739658867.761230707][Client.cpp:278][&td_requests]   Begin to wait for updates with timeout 30.000000
[ 3][t 0][1739658867.761293649][Client.cpp:291][&td_requests]   End to wait for updates, returning object 0 0x77bc74101bb0
[ 3][t 0][1739658867.763499259][Client.cpp:278][&td_requests]   Begin to wait for updates with timeout 30.000000
[ 3][t 0][1739658867.763508558][Client.cpp:291][&td_requests]   End to wait for updates, returning object 0 0x77bc74101d20
[ 3][t 1][1739658867.764448881][Td.cpp:3030][#1][!Td][&td_requests]     Receive request 1: setTdlibParameters {
  parameters = null
}
[ 3][t 1][1739658867.764491319][Td.cpp:4091][#1][!Td][&td_requests]     Sending error for request 1: error { code = 400 message = "Parameters aren't specified" }
[ 3][t 0][1739658867.765032768][Client.cpp:278][&td_requests]   Begin to wait for updates with timeout 30.000000
[ 3][t 0][1739658867.765042066][Client.cpp:291][&td_requests]   End to wait for updates, returning object 1 0x77bc580090d0
[ 3][t 0][1739658867.767453432][Client.cpp:278][&td_requests]   Begin to wait for updates with timeout 30.000000

Full example:

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'tdlib-ruby'

TD.configure do |config|
  config.lib_path = '/usr/lib/libtdjson.so'
  config.client.api_id = ENV.fetch('TG_API_ID').to_i
  config.client.api_hash = ENV.fetch('TG_API_HASH')
end

puts "lib_path: #{TD.config.lib_path}"
puts "api_id: #{TD.config.client.api_id}"
puts "api_hash: #{TD.config.client.api_hash}"

client = TD::Client.new

begin
  state = nil

  client.on(TD::Types::Update::AuthorizationState) do |update|
    state = case update.authorization_state
            when TD::Types::AuthorizationState::WaitPhoneNumber
              :wait_phone_number
            when TD::Types::AuthorizationState::WaitCode
              :wait_code
            when TD::Types::AuthorizationState::WaitPassword
              :wait_password
            when TD::Types::AuthorizationState::Ready
              :ready
            else
              nil
            end
  end
  
  client.connect

  loop do
    case state
    when :wait_phone_number
      puts 'Please, enter your phone number:'
      phone = STDIN.gets.strip
      client.set_authentication_phone_number(phone_number: phone, settings: nil).wait
    when :wait_code
      puts 'Please, enter code from SMS:'
      code = STDIN.gets.strip
      client.check_authentication_code(code: code).wait
    when :wait_password
      puts 'Please, enter 2FA password:'
      password = STDIN.gets.strip
      client.check_authentication_password(password: password).wait
    when :ready
      client.get_me.then { |user| @me = user }.rescue { |err| puts "error: #{err}" }.wait
      break
    end
    sleep 0.1
  end

ensure
  client.dispose
end

p @me

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions