A small Node.js relay service that polls an X account and forwards posts to Telegram and optional Discord.
┌──────────────┐
│ X │
│ (@account) │
└──────┬───────┘
│
X API │ Polling
│
┌──────▼───────┐
│ Open Relay │
│ Node.js │
└──────┬───────┘
│
┌──────┴───────────────┐
│ │
Telegram Bot API Discord Webhook
│ │
┌──────▼───────┐ ┌──────▼───────┐
│ Telegram │ │ Discord │
│ Channel / │ │ Server / │
│ Group / DM │ │ Channel │
└──────────────┘ └──────────────┘
- Polls an X user timeline for new posts
- Forwards text, photos, and videos to Telegram
- Optional Discord webhook forwarding with embed + attachment support
- Reposts and quote posts styled for Discord
- Rate-limited splitting for long text
- Optional Telegram admin commands (
/pin,/unpin,/delete,/unpinall)
- Node.js 18+
- X developer credentials
- Telegram bot token and chat ID
- Optional: Discord webhook URL and role mention
git clone https://github.com/kier2023/OpenRelay.git
cd twitterGram
npm installCopy and edit .env from .env.example:
cp .env.example .envThen fill these values:
# X
X_BEARER_TOKEN=
X_USER_ID=
X_USERNAME=
# Telegram
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=
TELEGRAM_ADMIN_IDS=
# Optional Discord
DISCORD_ENABLED=false
DISCORD_WEBHOOK_URL=
DISCORD_ROLE=
DISCORD_ROLE_ID=
# Polling
POLL_MS=60000DISCORD_ENABLED=trueto enable Discord integrationDISCORD_WEBHOOK_URLmust be set when enabledDISCORD_ROLEorDISCORD_ROLE_IDcan be used for a role mention
npm startThe app verifies X and Telegram, then polls at POLL_MS.
- Startup loads
.envand validates required vars. - Main loop polls X via
fetchLatestPosts. - New posts are normalized in
src/services/telegramRelay.js. - Telegram sends messages using
node-telegram-bot-api. - If Discord enabled, it sends embed + attachments in
src/services/discordRelay.js.
- Sends one embed per post with title, body, and quote blocks.
- Optional role mentions are added as message content.
- Media is downloaded and sent as actual webhook attachments.
- Reposts/quotes are styled with blockquotes and source fields.
In groups, allowed IDs from TELEGRAM_ADMIN_IDS can run:
/pin,/unpin,/delete,/unpinall,/help
- Do not commit real API keys.
- Keep
.envprivate. - If Discord is enabled, ensure webhook URL is valid and has permission in the channel.