Configure Telegram
Configure Telegram login
Follow this guide to create a telegram bot. After creating a Telegram bot, you must set your domain using the/setdomain command in the @BotFather chat. You will need to provide the following to Privy via the Privy Dashboard upon completion:
- Bot token (eg:
1234567890:AzByCxDwEvFuGtHsIr1k2M4o5Q6s7U8w9Y0) - Bot handle (eg:
@MyBot_bot)
- Your domain must be configured as your bot’s allowed domain.
- Important: Telegram does not support
.xyzdomains for authentication. If your application uses a.xyzdomain, you must use a different top-level domain (TLD) for Telegram authentication to function properly. - If you have CSP enforcement, you’ll need to update these directives:
script-srcmust allowhttps://telegram.orgin order to be able to download Telegram’s widget script.frame-srcmust allowhttps://oauth.telegram.orgin order to be able to render Telegram’s widget iframe.
Since you need to set your bot’s allowed domain you’ll need to use a tunneling tool for local
development such as Cloudflare
tunnels or
ngrok.
Essential: Secure your bot secret
Integration interfaces
[optional] Enable Telegram in your client-side loginMethods
You must enable Telegram in the Privy Dashboard to enable login with Telegram.
If you additionally have loginMethods configured client-side in your PrivyProvider config, make sure you add "telegram" to that list as well. Client-side login method configuration is only necessary if you want to restrict logins to a subset of those configured in the Dashboard.
Seamless login with Telegram
You can integrate Privy to enable login directly from within a Telegram bot or Telegram mini-app.- If enabled, Privy will automatically log your user in when your user initiates login from within Telegram. You do not have to call
loginfrom theusePrivyhook in this case! - To enable seamless login, send your website URL using , InlineKeyboardButton.web_app or InlineKeyboardButton.login_url or use a direct link (ex:
t.me/xxx_bot/xxx) - For reference, see these docs:
Login with Telegram
Once Telegram is enabled, you will automatically see Telegram in the Privy login modal. You can also list'telegram' when configuring login methods client-side, in the PrivyProvider.
Link Telegram
You can use thelinkTelegram and unlinkTelegram methods from the usePrivy hook to add or remove Telegram accounts from a user. See the SDK reference for more details:
Link Telegram seamlessly within a Telegram Mini app
You can use thelinkTelegram methods from the usePrivy hook within a Telegram Mini App to add to a user seamlessly by passing launchParams as a parameter. See the SDK reference for more details:
TelegramAccount type
Theuser object contains information about all of the accounts a user has linked with Privy.
TelegramAccount extends LinkedAccount
| Field | Type | Description |
|---|---|---|
| type | ’telegram’ | N/A |
| telegram_user_id | string | ID of a user’s telegram account. |
| first_name | string | The first name displayed on a user’s telegram account. |
| last_name | string | (Optional) The last name displayed on a user’s telegram account. |
| username | string | (Optional) The username displayed on a user’s telegram account. |
| photo_url | string | (Optional) The url of a user’s telegram account profile picture. |

