Skip to content

Pixlink-Team/telgeram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot API (Node + Telegraf)

A minimal project mirroring the WhatsApp bot API structure, but for Telegram USER ACCOUNT (MTProto), not a bot.

Features

  • MTProto user account via GramJS
  • Express HTTP server with /health, login endpoints, and /send
  • Session string support to persist login

Setup

  1. Copy .env.example to .env and set TELEGRAM_API_ID, TELEGRAM_API_HASH, TELEGRAM_PHONE.
  2. Install dependencies.
  3. Run in dev mode.

Using a proxy (Iran / restricted networks)

If your network blocks Telegram, you can use either SOCKS or MTProto proxy:

Option 1: SOCKS proxy (v2ray, Clash, Outline, etc.)

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

Option 2: MTProto proxy (Telegram-specific)

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.

Try it

# from telegram-bot-api folder
pnpm install
pnpm dev

Login 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 apiId and apiHash in the login requests (/login/sendCode, /login/verifyCode, /login/password). Otherwise, the values from .env are 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"}'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors