tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.07k stars 1.44k forks source link

Not done in ClientJson.cpp #65

Closed isopen closed 6 years ago

isopen commented 6 years ago

ClientJson.cpp Result ClientJson::to_request(Slice request) {

Lazarus(fpc) td_execute('{"@type": "getTextEntities", "text": "@telegram /test_command https://telegram.org telegram.me", "@extra": ["5", 7.0]}'); [ 1][t 0][1518264724,360867500][ClientJson.cpp:92] Failed to parse [request:\320|\221\001] [Error : 0 : Unexpected symbol]

td_json_client_send(client, '{"@type": "getAuthorizationState", "@extra": 1.01234}'); - work [ 3][t 4][1518271871.434058428][Td.cpp:4296][!Td][&td_requests] Sending update: updateAuthorizationState { authorization_state = authorizationStateWaitTdlibParameters { } } [ 3][t 4][1518271871.434437513][Td.cpp:4305][!Td][&td_requests] Sending result for request 1: authorizationStateWaitTdlibParameters { }

I typed a string on the keyboard '{"@type": "getTextEntities", "text": "@telegram / test_command https://telegram.org telegram.me", "@extra": ["5", 7.0]}' [ 1][t 0][1518264724,360867500][ClientJson.cpp:92] Failed to parse [request:\320|\221\001] [Error : 0 : Unexpected symbol]

I tried :) td_json_client_execute(client, '{"@type": "getTextEntities", "text": "123", "@extra": ["5", 7.0]}'); [ 1][t 0][1518272665.850152969][ClientJson.cpp:92] Failed to parse [request:\020\254\263] [Error : 0 : Unexpected symbol ''] td_json_client_execute(client, '{"@type": "getTextEntities", "text": "@telegram /test_command https://telegram.org telegram.me", "@extra": 1.01234}'); [ 1][t 0][1518273040.330082893][ClientJson.cpp:92] Failed to parse [request:\020LE\002] [Error : 0 : Unexpected symbol ''] td_json_client_execute(client, '{"@type": "getTextEntities", "text": "123", "@extra": 1.01234}'); [ 1][t 0][1518273309.035333395][ClientJson.cpp:92] Failed to parse [request:\020L\366\001] [Error : 0 : Unexpected symbol '']

I also check fpc. If the call to this method is a procedure, then it is executed correctly. If you call a function that returns a string, an error occurs. There may be a bug somewhere in the script, fpc or tdlib. td_json_client_create is also a function (in the understanding of fpc. without parameters)

Ruby '{"@type": "getTextEntities", "text": "@telegram /test_command https://telegram.org telegram.me", "@extra": ["5", 7.0]}' - work But! [ 1][t 0][1518271356.440364599][ClientJson.cpp:92] Failed to parse [request:{'@type': 'getTextEntities', 'text': '@telegram /test_command https://telegram.org telegram.me', '@extra': ['5', 7.0]}] [Error : 0 : Opening '"' expected] - as though all right :) According to the specification for json you can say that this is normal.

Something with a parser in Result ClientJson::to_request(Slice request) {

arseny30 commented 6 years ago

Errors are quite clear.

Lazarus(fpc) Something is wrong with passing string to C function. tdlib received [request:\020\254\263], not string you tried to send.

Ruby Single quotes are not valid JSON.

isopen commented 6 years ago
Lazarus(fpc)
Something is wrong with passing string to C function. tdlib received [request:\020\254\263], not string you tried to send.

td_json_client_send(client, '{"@type": "getAuthorizationState", "@extra": 1.01234}'); - work it is a procedure.

Сall plan for which an error occurs

uses dynlibs, ...;

type
  ...
  tyour_func = function(client: pcunsigned; request: string): string;
var
  tdlib: TLibHandle= dynlibs.NilHandle;
  your_func: tyour_func;
  res: string;
begin
  tdlib:= LoadLibrary('./libtdjson.so');
  if tdlib = dynlibs.NilHandle then Exit;
  your_func:= tyour_func(GetProcedureAddress(tdlib, 'your_func'));
  ...
  res:= your_func(client, '{"@type": "getTextEntities", "text": "@telegram /test_command https://telegram.org telegram.me", "@extra": ["5", 7.0]}');
end.

Here you can read more about the interface :) http://wiki.lazarus.freepascal.org/Lazarus/FPC_Libraries

arseny30 commented 6 years ago

Isn't this interface is for fpc libraries?

isopen commented 6 years ago

Yes it does not matter what it is. I would say that this is a piece of shit. We'll try it source lazarus(fpc).

UnblockerUsername commented 6 years ago

@isopen gave an example above. Pascal is very common in teaching. @levlam is there any result on this interface?

levlam commented 6 years ago

No. We will not provide Lazarus example ourselves, but third-party examples/class bindings are welcome.

UnblockerUsername commented 6 years ago

Why then was the library created? Try to write in Python shorter alphabet: array['a'..'z'] of Integer;