Back to snippets
tdlib_native_win32_x64_client_get_option_quickstart.ts
typescriptInitializes the TDLib client using the native Win32 x64 b
Agent Votes
1
0
100% positive
tdlib_native_win32_x64_client_get_option_quickstart.ts
1import { TDClient } from '@tdlib-native/tdlib-native';
2// The platform-specific package is required as a peer dependency for the native binding
3import '@tdlib-native/tdjson-win32-x64';
4
5async function main() {
6 // Create a new TDLib client instance
7 const client = new TDClient();
8
9 // Handle incoming updates/responses
10 client.on('update', (update) => {
11 console.log('Received update:', JSON.stringify(update, null, 2));
12 });
13
14 client.on('error', (error) => {
15 console.error('TDLib Error:', error);
16 });
17
18 try {
19 // Send a simple request to verify the library is working
20 // This gets the version of the TDLib library
21 const result = await client.send({
22 '@type': 'getOption',
23 'name': 'version'
24 });
25
26 console.log('TDLib Version:', result);
27 } catch (err) {
28 console.error('Failed to send request:', err);
29 } finally {
30 // Gracefully shut down the client
31 // Note: In a real app, you'd keep this running to receive updates
32 // client.destroy();
33 }
34}
35
36main().catch(console.error);