antonio-antuan / rust-tdlib

Rust client for TDlib
MIT License
57 stars 11 forks source link

setTdlibParameters fields are all empty #24

Closed EricDeng1001 closed 1 year ago

EricDeng1001 commented 1 year ago

image

antonio-antuan commented 1 year ago

@EricDeng1001 could you provide some code?

EricDeng1001 commented 1 year ago
#[tokio::main]
async fn main() {
    init_log();
    let tdlib_params = TdlibParameters::builder().api_id("api_id_here").api_hash("api_hash_here").build();
    let client_config = Client::builder().with_tdlib_parameters(tdlib_params).build().unwrap();
    let mut worker = Worker::builder().build().unwrap();
    worker.start();
    let client = worker.bind_client(client_config).await.unwrap();
}
EricDeng1001 commented 1 year ago

full log if it helps

2022-12-20T20:20:42.780168062+08:00 DEBUG rust_tdlib::client::worker - new client created: 1
2022-12-20T20:20:42.780202442+08:00 DEBUG rust_tdlib::client::worker - new client added
[ 3][t 0][1671538842.780259132][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 4][1671538842.780621051][Td.cpp:2563][#1][!MultiTd]      Create Td with layer 150, database version 14 and version 44 on 4 threads
[ 3][t 4][1671538842.780646800][Td.cpp:3975][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.9"
  }
}
[ 3][t 4][1671538842.780673980][Td.cpp:3975][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "commit_hash"
  value = optionValueString {
    value = "e531ae2eb01d5c0ba2a195c8d860a4e53689a729"
  }
}
[ 3][t 4][1671538842.780676603][Td.cpp:3975][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateWaitTdlibParameters {
  }
}
[ 3][t 4][1671538842.780682325][Td.cpp:2932][#1][!Td][&td_requests]     Receive request 1: getApplicationConfig {
}
[ 3][t 0][1671538842.780696153][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7f6080001b50
[ 3][t 0][1671538842.780890464][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 0][1671538842.780904531][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7f6080001b90
[ 3][t 0][1671538842.781002998][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 0][1671538842.781013011][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7f6080001c60
[ 3][t 0][1671538842.781141281][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
2022-12-20T20:20:42.781128286+08:00 DEBUG rust_tdlib::client::worker - received new auth state: UpdateAuthorizationState { extra: None, client_id: Some(1), authorization_state: WaitTdlibParameters(AuthorizationStateWaitTdlibParameters { extra: None, client_id: None }) }
2022-12-20T20:20:42.781176545+08:00 DEBUG rust_tdlib::client::worker - handling new auth state: WaitTdlibParameters(AuthorizationStateWaitTdlibParameters { extra: None, client_id: None })
2022-12-20T20:20:42.781192807+08:00 DEBUG rust_tdlib::client::worker - going to set tdlib parameters
[ 3][t 4][1671538842.781272411][Td.cpp:2932][#1][!Td][&td_requests]     Receive request 2: setTdlibParameters {
  use_test_dc = false
  database_directory = ""
  files_directory = ""
  database_encryption_key = bytes [0] { }
  use_file_database = false
  use_chat_info_database = false
  use_message_database = false
  use_secret_chats = false
  api_id = 0
  api_hash = ""
  system_language_code = ""
  device_model = ""
  system_version = ""
  application_version = ""
  enable_storage_optimizer = false
  ignore_file_names = false
}
[ 3][t 4][1671538842.781296968][Td.cpp:4006][#1][!Td][&td_requests]     Sending error for request 2: error { code = 400 message = "Valid api_id must be provided. Can be obtained at https://my.telegram.org" }
[ 3][t 0][1671538842.781326293][Client.cpp:293][&td_requests]   End to wait for updates, returning object 2 0x7f6094002050
2022-12-20T20:20:42.781411393+08:00 ERROR rust_tdlib::client::worker - error received and possibly cannot be handled because of empty state receiver: Error { extra: Some("c7db2896-f8c3-4f90-aaf7-fd31cba6d9ab"), client_id: Some(1), code: 400, message: "Valid api_id must be provided. Can be obtained at https://my.telegram.org" }
[ 3][t 0][1671538842.781459331][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 0][1671538844.783809661][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 (nil)
EricDeng1001 commented 1 year ago

thx for responding. have been looking into the problem by myself for an hour. no clue

antonio-antuan commented 1 year ago

I'll take a look in six hours

On Tue, Dec 20, 2022, at 14:32, Eric Deng wrote:

thx for responding. have been looking into the problem by myself for an hour. no clue

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/24#issuecomment-1359290633, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYFJNBKXXMOPCEK6QALWOGROPANCNFSM6AAAAAATEMPDAU. You are receiving this because you commented.Message ID: @.***>

EricDeng1001 commented 1 year ago

more info: system: Ubuntu 2204 tdlib: build from this script:

sudo apt-get update                                                                                                ─╯
sudo apt-get upgrade
sudo apt-get install make git zlib1g-dev libssl-dev gperf php-cli cmake g++
git clone https://github.com/tdlib/td.git
cd td
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=../tdlib ..
cmake --build . --target install -j24
cd ..
cd ..
sudo cp -r td/tdlib/lib/* /lib

rustc --version: rustc 1.66.0 (69f9c33d7 2022-12-12)

cargo.toml:

[package]
name = "tg_bot_tdlib"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rust-tdlib = "0.4.1"
tokio = { version = "1.8", features = ["full"] }
log = "0.4.17"
log4rs = "1.2.0"
serde_json = "1.0.89"

full src:

use rust_tdlib::{client::{Client, Worker}, tdjson, types::*};

fn init_log() {
    log4rs::init_file("config/log4rs.yml", Default::default()).unwrap();
}

#[tokio::main]
async fn main() {
    init_log();
    let tdlib_params = TdlibParameters::builder().api_id().api_hash().build();
    let client_config = Client::builder().with_tdlib_parameters(tdlib_params).build().unwrap();
    let mut worker = Worker::builder().build().unwrap();
    worker.start();
    let client = worker.bind_client(client_config).await.unwrap();
}

config/log4rs.yml:

appenders:
  stdout:
    kind: console

root:
  level: debug
  appenders:
    - stdout
antonio-antuan commented 1 year ago

for now, could you please log params and provide an output:

log::info!("{:?}", tdlib_params);
EricDeng1001 commented 1 year ago

sure. for clarity but also repesct privacy, i faked app_id and api_hash. full src:

use rust_tdlib::{client::{Client, Worker}, tdjson, types::*};

fn init_log() {
    log4rs::init_file("config/log4rs.yml", Default::default()).unwrap();
}

#[tokio::main]
async fn main() {
    init_log();
    let fake_app_id = 3212321;
    let fake_api_hash = "dsafjkewqkdhadhwlqeowquei";
    let tdlib_params = TdlibParameters::builder().api_id(fake_app_id).api_hash(fake_api_hash).build();
    log::info!("{:?}", tdlib_params);
    let client_config = Client::builder().with_tdlib_parameters(tdlib_params).build().unwrap();
    let mut worker = Worker::builder().build().unwrap();
    log::info!("{:?}", client_config.get_tdlib_client());
    worker.start();
    let client = worker.bind_client(client_config).await.unwrap();
}

full output:

Finished dev [unoptimized + debuginfo] target(s) in 2.76s
     Running `target/debug/tg_bot_tdlib`
2022-12-21T00:24:00.283928915+08:00 INFO tg_bot_tdlib - TdlibParameters { extra: Some("d8565dcd-d6d9-439b-a07d-4830c6795fb1"), client_id: None, use_test_dc: false, database_directory: "", files_directory: "", use_file_database: false, use_chat_info_database: false, use_message_database: false, use_secret_chats: false, api_id: 3212321, api_hash: "dsafjkewqkdhadhwlqeowquei", system_language_code: "", device_model: "", system_version: "", application_version: "", enable_storage_optimizer: false, ignore_file_names: false }
2022-12-21T00:24:00.284004388+08:00 INFO tg_bot_tdlib - TdJson
2022-12-21T00:24:00.284098894+08:00 DEBUG rust_tdlib::client::worker - new client created: 1
2022-12-21T00:24:00.284128795+08:00 DEBUG rust_tdlib::client::worker - new client added
[ 3][t 0][1671553440.284631967][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 4][1671553440.285018920][Td.cpp:2563][#1][!MultiTd]      Create Td with layer 150, database version 14 and version 44 on 4 threads
[ 3][t 4][1671553440.285042524][Td.cpp:3975][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.9"
  }
}
[ 3][t 4][1671553440.285063982][Td.cpp:3975][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "commit_hash"
  value = optionValueString {
    value = "e531ae2eb01d5c0ba2a195c8d860a4e53689a729"
  }
}
[ 3][t 4][1671553440.285066843][Td.cpp:3975][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateWaitTdlibParameters {
  }
}
[ 3][t 4][1671553440.285081624][Td.cpp:2932][#1][!Td][&td_requests]     Receive request 1: getApplicationConfig {
}
[ 3][t 0][1671553440.285088300][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7f5d0c001b50
[ 3][t 0][1671553440.285311937][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 0][1671553440.285326957][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7f5d0c001b90
[ 3][t 0][1671553440.285447120][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 0][1671553440.285466909][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7f5d0c001c60
[ 3][t 0][1671553440.285660266][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
2022-12-21T00:24:00.285658991+08:00 DEBUG rust_tdlib::client::worker - received new auth state: UpdateAuthorizationState { extra: None, client_id: Some(1), authorization_state: WaitTdlibParameters(AuthorizationStateWaitTdlibParameters { extra: None, client_id: None }) }
2022-12-21T00:24:00.285709065+08:00 DEBUG rust_tdlib::client::worker - handling new auth state: WaitTdlibParameters(AuthorizationStateWaitTdlibParameters { extra: None, client_id: None })
2022-12-21T00:24:00.285732209+08:00 DEBUG rust_tdlib::client::worker - going to set tdlib parameters
[ 3][t 4][1671553440.285868883][Td.cpp:2932][#1][!Td][&td_requests]     Receive request 2: setTdlibParameters {
  use_test_dc = false
  database_directory = ""
  files_directory = ""
  database_encryption_key = bytes [0] { }
  use_file_database = false
  use_chat_info_database = false
  use_message_database = false
  use_secret_chats = false
  api_id = 0
  api_hash = ""
  system_language_code = ""
  device_model = ""
  system_version = ""
  application_version = ""
  enable_storage_optimizer = false
  ignore_file_names = false
}
[ 3][t 4][1671553440.285924196][Td.cpp:4006][#1][!Td][&td_requests]     Sending error for request 2: error { code = 400 message = "Valid api_id must be provided. Can be obtained at https://my.telegram.org" }
[ 3][t 0][1671553440.285954475][Client.cpp:293][&td_requests]   End to wait for updates, returning object 2 0x7f5d34002050
[ 3][t 0][1671553440.286235570][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
2022-12-21T00:24:00.286250377+08:00 ERROR rust_tdlib::client::worker - error received and possibly cannot be handled because of empty state receiver: Error { extra: Some("7516c100-51ff-4df7-af2a-3e8aeab36607"), client_id: Some(1), code: 400, message: "Valid api_id must be provided. Can be obtained at https://my.telegram.org" }
[ 3][t 0][1671553442.288278579][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 (nil)
[ 3][t 0][1671553442.288477659][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
[ 3][t 0][1671553444.290832996][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 (nil)
[ 3][t 0][1671553444.291532993][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 2.000000
antonio-antuan commented 1 year ago

Weird. OK, check it a bit later

On Tue, Dec 20, 2022, at 18:26, Eric Deng wrote:

sure. for clarity but also repesct privacy, i faked app_id and api_hash. full src:

use rust_tdlib::{client::{Client, Worker}, tdjson, types::*};

fn init_log() { log4rs::init_file("config/log4rs.yml", Default::default()).unwrap(); }

[tokio::main]

async fn main() { init_log(); let fake_app_id = 3212321; let fake_api_hash = "dsafjkewqkdhadhwlqeowquei"; let tdlib_params = TdlibParameters::builder().api_id(fake_app_id).api_hash(fake_api_hash).build(); log::info!("{:?}", tdlib_params); let client_config = Client::builder().with_tdlib_parameters(tdlib_params).build().unwrap(); let mut worker = Worker::builder().build().unwrap(); log::info!("{:?}", client_config.get_tdlib_client()); worker.start(); let client = worker.bind_client(client_config).await.unwrap(); } full output:

Finished dev [unoptimized + debuginfo] target(s) in 2.76s Runningtarget/debug/tg_bot_tdlib 2022-12-21T00:24:00.283928915+08:00 INFO tg_bot_tdlib - TdlibParameters { extra: Some("d8565dcd-d6d9-439b-a07d-4830c6795fb1"), client_id: None, use_test_dc: false, database_directory: "", files_directory: "", use_file_database: false, use_chat_info_database: false, use_message_database: false, use_secret_chats: false, api_id: 3212321, api_hash: "dsafjkewqkdhadhwlqeowquei", system_language_code: "", device_model: "", system_version: "", application_version: "", enable_storage_optimizer: false, ignore_file_names: false } 2022-12-21T00:24:00.284004388+08:00 INFO tg_bot_tdlib - TdJson 2022-12-21T00:24:00.284098894+08:00 DEBUG rust_tdlib::client::worker - new client created: 1 2022-12-21T00:24:00.284128795+08:00 DEBUG rust_tdlib::client::worker - new client added [ 3][t 0][1671553440.284631967][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000 [ 3][t 4][1671553440.285018920][Td.cpp:2563][#1][!MultiTd] Create Td with layer 150, database version 14 and version 44 on 4 threads [ 3][t 4][1671553440.285042524][Td.cpp:3975][#1][!Td][&td_requests] Sending update: updateOption { name = "version" value = optionValueString { value = "1.8.9" } } [ 3][t 4][1671553440.285063982][Td.cpp:3975][#1][!Td][&td_requests] Sending update: updateOption { name = "commit_hash" value = optionValueString { value = "e531ae2eb01d5c0ba2a195c8d860a4e53689a729" } } [ 3][t 4][1671553440.285066843][Td.cpp:3975][#1][!Td][&td_requests] Sending update: updateAuthorizationState { authorization_state = authorizationStateWaitTdlibParameters { } } [ 3][t 4][1671553440.285081624][Td.cpp:2932][#1][!Td][&td_requests] Receive request 1: getApplicationConfig { } [ 3][t 0][1671553440.285088300][Client.cpp:293][&td_requests] End to wait for updates, returning object 0 0x7f5d0c001b50 [ 3][t 0][1671553440.285311937][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000 [ 3][t 0][1671553440.285326957][Client.cpp:293][&td_requests] End to wait for updates, returning object 0 0x7f5d0c001b90 [ 3][t 0][1671553440.285447120][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000 [ 3][t 0][1671553440.285466909][Client.cpp:293][&td_requests] End to wait for updates, returning object 0 0x7f5d0c001c60 [ 3][t 0][1671553440.285660266][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000 2022-12-21T00:24:00.285658991+08:00 DEBUG rust_tdlib::client::worker - received new auth state: UpdateAuthorizationState { extra: None, client_id: Some(1), authorization_state: WaitTdlibParameters(AuthorizationStateWaitTdlibParameters { extra: None, client_id: None }) } 2022-12-21T00:24:00.285709065+08:00 DEBUG rust_tdlib::client::worker - handling new auth state: WaitTdlibParameters(AuthorizationStateWaitTdlibParameters { extra: None, client_id: None }) 2022-12-21T00:24:00.285732209+08:00 DEBUG rust_tdlib::client::worker - going to set tdlib parameters [ 3][t 4][1671553440.285868883][Td.cpp:2932][#1][!Td][&td_requests] Receive request 2: setTdlibParameters { use_test_dc = false database_directory = "" files_directory = "" database_encryption_key = bytes [0] { } use_file_database = false use_chat_info_database = false use_message_database = false use_secret_chats = false api_id = 0 api_hash = "" system_language_code = "" device_model = "" system_version = "" application_version = "" enable_storage_optimizer = false ignore_file_names = false } [ 3][t 4][1671553440.285924196][Td.cpp:4006][#1][!Td][&td_requests] Sending error for request 2: error { code = 400 message = "Valid api_id must be provided. Can be obtained at https://my.telegram.org" } [ 3][t 0][1671553440.285954475][Client.cpp:293][&td_requests] End to wait for updates, returning object 2 0x7f5d34002050 [ 3][t 0][1671553440.286235570][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000 2022-12-21T00:24:00.286250377+08:00 ERROR rust_tdlib::client::worker - error received and possibly cannot be handled because of empty state receiver: Error { extra: Some("7516c100-51ff-4df7-af2a-3e8aeab36607"), client_id: Some(1), code: 400, message: "Valid api_id must be provided. Can be obtained at https://my.telegram.org" } [ 3][t 0][1671553442.288278579][Client.cpp:293][&td_requests] End to wait for updates, returning object 0 (nil) [ 3][t 0][1671553442.288477659][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000 [ 3][t 0][1671553444.290832996][Client.cpp:293][&td_requests] End to wait for updates, returning object 0 (nil) [ 3][t 0][1671553444.291532993][Client.cpp:280][&td_requests] Begin to wait for updates with timeout 2.000000

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/24#issuecomment-1359673531, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYC4GRJZG5GR2NR4DYDWOHM2DANCNFSM6AAAAAATEMPDAU. You are receiving this because you commented.Message ID: @.***>

EricDeng1001 commented 1 year ago

As u can see, in rust all params are set correctly. I can confirm that because i have done some more test in caller side. To check if there is an error in this lib, I walked through the call stack, but still dont figure out how my tdlib_params get to pass to tdlib. So I am here for help!

EricDeng1001 commented 1 year ago

update: by change code in src/client/worker.rs, line 624 to image I can confirm that even to this step, params are correctly carried.

2022-12-21T00:51:49.330237698+08:00 DEBUG rust_tdlib::client::worker - going to set tdlib parameters: TdlibParameters { extra: Some("ddbecc10-fc35-4708-b05f-1430e1a456aa"), client_id: None, use_test_dc: false, database_directory: "", files_directory: "", use_file_database: false, use_chat_info_database: false, use_message_database: false, use_secret_chats: false, api_id: 3212321, api_hash: "dsafjkewqkdhadhwlqeowquei", system_language_code: "", device_model: "", system_version: "", application_version: "", enable_storage_optimizer: false, ignore_file_names: false }
[ 3][t 4][1671555109.330323934][Td.cpp:2932][#1][!Td][&td_requests]     Receive request 2: setTdlibParameters {
  use_test_dc = false
  database_directory = ""
  files_directory = ""
  database_encryption_key = bytes [0] { }
  use_file_database = false
  use_chat_info_database = false
  use_message_database = false
  use_secret_chats = false
  api_id = 0
  api_hash = ""
  system_language_code = ""
  device_model = ""
  system_version = ""
  application_version = ""
  enable_storage_optimizer = false
  ignore_file_names = false
}
[ 3][t 4][1671555109.330347776][Td.cpp:4006][#1][!Td][&td_requests]     Sending error for request 2: error { code = 400 message = "Valid api_id must be provided. Can be obtained at https://my.telegram.org" }
antonio-antuan commented 1 year ago

For now I assume that I need to update bindings for the new version of tdlib. Code was generated only for 1.8.0.

Anyway, I going to investigate this.

On Tue, Dec 20, 2022, at 18:54, Eric Deng wrote:

update: by change code in src/client/worker.rs, line 624 to image https://user-images.githubusercontent.com/28720903/208721984-bb747354-4faf-4a4a-a6b1-4bf74c2a2495.png I can confirm that even to this step, params are correctly carried.

2022-12-21T00:51:49.330237698+08:00 DEBUG rust_tdlib::client::worker - going to set tdlib parameters: TdlibParameters { extra: Some("ddbecc10-fc35-4708-b05f-1430e1a456aa"), client_id: None, use_test_dc: false, database_directory: "", files_directory: "", use_file_database: false, use_chat_info_database: false, use_message_database: false, use_secret_chats: false, api_id: 3212321, api_hash: "dsafjkewqkdhadhwlqeowquei", system_language_code: "", device_model: "", system_version: "", application_version: "", enable_storage_optimizer: false, ignore_file_names: false } [ 3][t 4][1671555109.330323934][Td.cpp:2932][#1][!Td][&td_requests] Receive request 2: setTdlibParameters { use_test_dc = false database_directory = "" files_directory = "" database_encryption_key = bytes [0] { } use_file_database = false use_chat_info_database = false use_message_database = false use_secret_chats = false api_id = 0 api_hash = "" system_language_code = "" device_model = "" system_version = "" application_version = "" enable_storage_optimizer = false ignore_file_names = false } [ 3][t 4][1671555109.330347776][Td.cpp:4006][#1][!Td][&td_requests] Sending error for request 2: error { code = 400 message = "Valid api_id must be provided. Can be obtained at https://my.telegram.org" }

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/24#issuecomment-1359714019, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYGWLO42QK7MRNTZ333WOHQE3ANCNFSM6AAAAAATEMPDAU. You are receiving this because you commented.Message ID: @.***>

EricDeng1001 commented 1 year ago

Ok. I will try 1.8.0 too. Will update my info here

EricDeng1001 commented 1 year ago

You are right. It's a version mismatch thing. In 1.8.0 it all works good. closing this thread.

EricDeng1001 commented 1 year ago

Thx all the help btw