Skip to main content

Obtaining API credentials

Every gotd client needs an api_id (an integer) and an api_hash (a string). These identify your application to Telegram and are required for both user and bot clients.

Get api_id and api_hash

  1. Sign in at my.telegram.org.
  2. Open API development tools.
  3. Create an application. You will be shown your api_id and api_hash.

Follow the official guide on obtaining api_id for details.

Keep your credentials secret

Never hardcode api_id / api_hash in source you publish, and never share them — they cannot be rotated easily. Read them from the environment or a config file instead.

Bot token

If you are building a bot, you also need a bot token from @BotFather. The api_id / api_hash still identify your application; the token authenticates the bot account.

Supplying credentials

You can pass credentials explicitly:

client := telegram.NewClient(appID, appHash, telegram.Options{})

or read them from the environment, which is what every example in the gotd repository does (see Environment helpers):

VariableMeaning
APP_IDapi_id from my.telegram.org
APP_HASHapi_hash from my.telegram.org
BOT_TOKENToken from @BotFather (bots only)
SESSION_FILEPath to a session file for persistent auth, e.g. ~/session.bot.json
SESSION_DIRDirectory for the session file, used when SESSION_FILE is unset

Next: Your first client.