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:
signedInmeans authorization is complete.passwordRequiredmeans two-step verification is enabled. getPasswordHint returns the account’s password hint, and checkPassword checks the password and completes authorization.signUpRequiredmeans the phone number is not registered. Call signUp to create the account.invalidCodemeans 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);