A minimal project mirroring the WhatsApp bot API structure, but for Telegram USER ACCOUNT (MTProto), not a bot.
- MTProto user account via GramJS
- Express HTTP server with
/health, login endpoints, and/send - Session string support to persist login
- Copy
.env.exampleto.envand setTELEGRAM_API_ID,TELEGRAM_API_HASH,TELEGRAM_PHONE. - Install dependencies.
- Run in dev mode.
If your network blocks Telegram, you can use either SOCKS or MTProto proxy:
TELEGRAM_PROXY_ENABLED=true
TELEGRAM_PROXY_MODE=socks
TELEGRAM_PROXY_HOST=127.0.0.1
TELEGRAM_PROXY_PORT=1080
TELEGRAM_PROXY_TYPE=socks5 # or socks4
TELEGRAM_PROXY_USERNAME= # optional
TELEGRAM_PROXY_PASSWORD= # optional
TELEGRAM_PROXY_ENABLED=true
TELEGRAM_PROXY_MODE=mtproto
TELEGRAM_MTPROTO_HOST=example.com
TELEGRAM_MTPROTO_PORT=443
TELEGRAM_MTPROTO_SECRET=ee1234567890abcdef... # hex secret from proxy
These settings are picked up automatically by the MTProto client.
# from telegram-bot-api folder
pnpm install
pnpm devLogin flow (once per environment):
# send login code to your phone
curl -X POST http://localhost:8081/login/sendCode \
-H "Content-Type: application/json" \
-d '{"phone": "+989123456789"}'
# verify code (replace CODE and PHONE_CODE_HASH from previous response)
curl -X POST http://localhost:8081/login/verifyCode \
-H "Content-Type: application/json" \
-d '{"phone": "+989123456789", "code": "12345", "phoneCodeHash": "HASH"}'
# if account has 2FA password, verify it
curl -X POST http://localhost:8081/login/password \
-H "Content-Type: application/json" \
-d '{"phone": "+989123456789", "password": "YOUR_PASSWORD", "session": "SESSION_FROM_VERIFY"}'
# Save the returned session string (TELEGRAM_SESSION) into your .env to auto-login next time.Tip: If you want to onboard many accounts with different Telegram API credentials, you can pass
apiIdandapiHashin the login requests (/login/sendCode,/login/verifyCode,/login/password). Otherwise, the values from.envare used.
Send a message (after login):
curl -X POST http://localhost:8081/send \
-H "Content-Type: application/json" \
-d '{"chatId": "@username_or_numeric_id", "text": "Hello from account"}'