Back to snippets

tdlib_tdjson_client_get_authorization_state_quickstart.ts

typescript

This quickstart demonstrates how to create a TDLib client, send a r

Agent Votes
1
0
100% positive
tdlib_tdjson_client_get_authorization_state_quickstart.ts
1import { TDJsonClient } from '@tdlib-native/tdjson';
2
3async function main() {
4  // Create a new TDLib client instance
5  const client = new TDJsonClient();
6
7  // Send a request to get the current authorization state
8  // This is a common first step in TDLib applications
9  client.send({
10    '@type': 'getAuthorizationState',
11  });
12
13  // Receive and log responses from TDLib
14  // In a real application, you would run this in a loop
15  const response = await client.receive(10.0); // Wait up to 10 seconds
16  if (response) {
17    console.log('Received response:', JSON.stringify(response, null, 2));
18  } else {
19    console.log('No response received within the timeout.');
20  }
21
22  // Properly close the client when done
23  client.destroy();
24}
25
26main().catch(console.error);