diff --git a/example/cpp/README.md b/example/cpp/README.md index 7f6ffbc2d..36c348697 100644 --- a/example/cpp/README.md +++ b/example/cpp/README.md @@ -18,3 +18,5 @@ cd build cmake -DCMAKE_BUILD_TYPE=Release -DTd_DIR=/example/cpp/td/lib/cmake/Td .. cmake --build . ``` + +Documentation for all available classes and methods can be found at https://core.telegram.org/tdlib/docs. diff --git a/example/ios/README.md b/example/ios/README.md index e44eec0b8..25a1e68fc 100644 --- a/example/ios/README.md +++ b/example/ios/README.md @@ -37,3 +37,5 @@ Resulting library for iOS will work on any architecture (arv7, armv7s, arm64) an We use [CMake/iOS.cmake](https://github.com/tdlib/td/blob/master/CMake/iOS.cmake) toolchain, other toolchains may work too. Built libraries will be store in `tdjson` directory. + +Documentation for all available classes and methods can be found at https://core.telegram.org/tdlib/docs. diff --git a/example/python/README.md b/example/python/README.md new file mode 100644 index 000000000..261710684 --- /dev/null +++ b/example/python/README.md @@ -0,0 +1,11 @@ +# TDLib Python example + +First you need to [build](https://github.com/tdlib/td#building) TDLib and copy built tdjson shared library to this directory. + +Then you can run the example: +``` +python tdjson_example.py +``` + +Description of all available classes and methods can be found at [td_json_client](https://core.telegram.org/tdlib/docs/td__json__client_8h.html), +[td_log](https://core.telegram.org/tdlib/docs/td__log_8h.html) and [td_api](https://core.telegram.org/tdlib/docs/td__api_8h.html) documentation. diff --git a/example/python/tdjson_example.py b/example/python/tdjson_example.py index 9df28746d..1b6a84c8b 100644 --- a/example/python/tdjson_example.py +++ b/example/python/tdjson_example.py @@ -3,12 +3,14 @@ from ctypes import * import json import sys +# load shared library tdjson_path = find_library("tdjson") or "tdjson.dll" if tdjson_path is None: print('can\'t find tdjson library') quit() tdjson = CDLL(tdjson_path) +# load TDLib functions from shared library td_json_client_create = tdjson.td_json_client_create td_json_client_create.restype = c_void_p td_json_client_create.argtypes = [] @@ -47,6 +49,7 @@ td_set_log_fatal_error_callback = tdjson.td_set_log_fatal_error_callback td_set_log_fatal_error_callback.restype = None td_set_log_fatal_error_callback.argtypes = [fatal_error_callback_type] +# initialize TDLib log with desired parameters def on_fatal_error_callback(error_message): print('TDLib fatal error: ', error_message) @@ -54,8 +57,10 @@ td_set_log_verbosity_level(2) c_on_fatal_error_callback = fatal_error_callback_type(on_fatal_error_callback) td_set_log_fatal_error_callback(c_on_fatal_error_callback) +# create client client = td_json_client_create() +# simple wrappers for client usage def td_send(query): query = json.dumps(query).encode('utf-8') td_json_client_send(client, query) @@ -73,15 +78,23 @@ def td_execute(query): result = json.loads(result.decode('utf-8')) return result +# testing TDLib execute method print(td_execute({'@type': 'getTextEntities', 'text': '@telegram /test_command https://telegram.org telegram.me', '@extra': ['5', 7.0]})) +# testing TDLib send method td_send({'@type': 'getAuthorizationState', '@extra': 1.01234}) + +# main events cycle while True: event = td_receive() if event: + # if client is closed, we need to destroy it and create new client if event['@type'] is 'updateAuthorizationState' and event['authorization_state']['@type'] is 'authorizationStateClosed': break + + # handle an incoming update or an answer to a previously sent request print(event) sys.stdout.flush() +# destroy client when it is closed and isn't needed anymore td_json_client_destroy(client) diff --git a/example/swift/README.md b/example/swift/README.md index 55e407658..6a333df76 100644 --- a/example/swift/README.md +++ b/example/swift/README.md @@ -10,3 +10,6 @@ cmake --build . --target install ``` Then you can open and build the example with the latest Xcode. + +Description of all available classes and methods can be found at [td_json_client](https://core.telegram.org/tdlib/docs/td__json__client_8h.html), +[td_log](https://core.telegram.org/tdlib/docs/td__log_8h.html) and [td_api](https://core.telegram.org/tdlib/docs/td__api_8h.html) documentation.