Guides

Connecting Manually

Main Walkthrough 3 of 25

Use the methods on this page when your application needs to control each authorization step. For most applications, start provides a simpler authorization flow.

Connecting

connect establishes a connection to Telegram without authorizing an account.

await client.connect();

Authorizing a User

Call sendCode with the user’s phone number, then pass the code they receive to checkCode.

await client.sendCode(phoneNumber);
const result = await client.checkCode(code);

The result describes the next step:

  • signedIn means authorization is complete.
  • passwordRequired means two-step verification is enabled. getPasswordHint returns the account’s password hint, and checkPassword checks the password and completes authorization.
  • signUpRequired means the phone number is not registered. Call signUp to create the account.
  • invalidCode means the submitted code was incorrect.
if (result.type === "passwordRequired") {
  const hint = await client.getPasswordHint();
  const password = await getPassword(hint);
  const passwordResult = await client.checkPassword(password);

  if (passwordResult.type === "invalidPassword") {
    // Ask for the password again.
  }
} else if (result.type === "signUpRequired") {
  await client.signUp(firstName, { lastName });
}

Authorizing a Bot

checkBotToken validates a bot token and authorizes the bot when the token is valid.

const result = await client.checkBotToken(botToken);