dot-build / telegram-js

[deprecated] Entrypoint library for Telegram API. Try https://github.com/alik0211/mtproto-core instead
54 stars 8 forks source link

Unable to retrieve a Type by Id #1

Closed pitersky closed 8 years ago

pitersky commented 8 years ago

Hi! First of all, thank you for this release. For me the library code is much more readable then telegram.link one's and it's very helping.

However I can't get it to work. I have managed how to establish connection to server, but client.callApi('help.getConfig') results in error: Unable to retrieve a Type by Id [e033ae7d]. The log is as follows:

[INFO] Wed, 10 Feb 2016 08:21:04 GMT  net.EncryptedRpcChannel Call of 'mtproto.service.invokeWithLayer' took 74ms
[INFO] Wed, 10 Feb 2016 08:21:04 GMT  net.EncryptedRpcChannel New session has been created by Telegram: { T:mtproto.type.New_session_created, first_msg_id: "0x56baf2f09851e3dc", unique_id: "0x00365a01fc49f22d", server_salt: "0x93fa9d177f7ad7d1" }
[INFO] Wed, 10 Feb 2016 08:21:04 GMT  net.EncryptedRpcChannel Send the ack to the server: { T:mtproto.type.Msgs_ack, msg_ids: { T:Vector, type: "Long", list: ["0x56baf2f0c0366801"] } }
[INFO] Wed, 10 Feb 2016 08:21:04 GMT  net.EncryptedRpcChannel The server sent a acknowledge for the followings [0x56baf2f09851e3dc]
[ERROR] Wed, 10 Feb 2016 08:21:04 GMT  ConstructorBuilder.registry Unable to retrieve a Type by Id [e033ae7d]
[ERROR] Wed, 10 Feb 2016 08:21:04 GMT  net.RpcChannel Unable to deserialize response 1f71613a29e4d98282fd9c42934c722496bb5af080172c2a1e92f0978da78afe68011c407cbd570c4ddd96f5fded4b6756f4e82f56ae963a77c35d52e8f6d94411289db90a8a8073d36fc5c791a139964ebd34ef98c71bb96e4bd700427ffc3e4449152150ad03ad8345d6f3c20495ea4af69dd9984d1ec0c310a9889b805239fcf06ab2f1251b4dcd944b937adb6474478027d0126c46c6a5ad6f5d17967cce5437a58a164d9ff53b2841bf2b8cd5c726dfca4fb37513ef0bdd93a5a26aa9c6cd91cbe3a88d0fe8a0c4aa0b0f265999a01c44fad7f4cd80b37fc9b2e9472976e774280d6771b2a871a563334d031ec01c9c4e091dfd95f9cb977d6c9ece3e7f4ce5dfa4917b9195a5c82e88a62f5546331259e06287e262 from mtproto.type.Msgs_ack due to Error: Unable to retrieve a Type by Id [e033ae7d]

Any tips how to debug this is appreciated. I made a gist with the code I am using: https://gist.github.com/shilka/fed44947350f15e92919

darlanalves commented 8 years ago

Hi! First of all, thanks for trying out the lib :) The code is still based on telegram link library, so probably not greatly designed yet. But that will change very soon.

About the error: this is an error caused by an unknown type being decoded inside telegram-tl-node. The hash you are seeing in the error is e033ae7d, which is a Int32LE number equivalent to 2108568544. Flipping it's bytes, we get 7dae33e0. This byte sequence should be present as a hash in one of these schemas:

https://core.telegram.org/schema https://core.telegram.org/schema/mtproto

Looking at the first link, you should find this hash as the Config constructor if you select the right layer. This is where things went bad. I tried the library with the wrong schema too, and got the error you mentioned. Then I remembered that sometimes the telegram docs won't show the most recent schema. Go to the first link above, and right after the first paragraph, and above the schema definitions, look for 'Layer xx'. It should be 23. If is not, switch to 23, and the grab the source code in the link to the schema JSON.

Replacing the schema file with the correct layer fixed the problem here, and I was able to run your gist code. Let me know if you still can't run it.

By the way, the gist has an error: the client.callApi method returns a Promise instead of using the callback format, so you want to use it like this:

client.callApi('help.getConfig').then(function(config) { ... });