Package Information
Documentation
n8n-nodes-mtproto
Custom n8n nodes for Telegram MTProto API with integrated GramJS library.
Features
This package provides full MTProto protocol access to Telegram, allowing you to:
- Messages: Send, receive, edit, delete, forward, and search messages
- Media: Send photos and documents
- Chats: Get dialogs, chat info, members, leave chats
- Channels: Join, leave, get info, get members/subscribers
- Contacts: Get contacts list, search users globally
- Users: Get user info, profile photos
- Account: Get current account info, manage sessions
Installation
In n8n (Docker)
- Build the package:
npm install
npm run build
- Copy the built package to your n8n custom nodes directory:
# If using Docker
docker cp dist/ n8n:/home/node/.n8n/custom/node_modules/n8n-nodes-mtproto/
# Or mount as volume in docker-compose.yml:
volumes:
- ./n8n-nodes-mtproto:/home/node/.n8n/custom/node_modules/n8n-nodes-mtproto
In n8n (npm global)
cd ~/.n8n/custom
npm install /path/to/n8n-nodes-mtproto
Development
npm install
npm run dev # Watch mode for development
Getting Started
1. Get Telegram API Credentials
- Go to https://my.telegram.org
- Log in with your phone number
- Go to "API development tools"
- Create a new application
- Note your
api_idandapi_hash
2. Generate Session String
Before using the nodes, you need to generate a session string:
npm install
npx ts-node scripts/generate-session.ts
Follow the prompts:
- Enter your API ID
- Enter your API Hash
- Enter your phone number (with country code)
- Enter the verification code sent to Telegram
- Enter 2FA password (if enabled)
Copy the generated session string - you'll need it for the credentials.
3. Configure Credentials in n8n
- Open n8n
- Go to Credentials → Create New
- Search for "MTProto API"
- Fill in:
- API ID: Your Telegram API ID
- API Hash: Your Telegram API Hash
- Phone Number: Your phone number with country code
- Session String: The string generated in step 2
- 2FA Password: (Optional) Your two-factor authentication password
Available Nodes
Telegram MTProto
Main node for interacting with Telegram.
Resources & Operations
Account
Get Me- Get current account informationGet Session String- Generate/retrieve session stringLog Out- Log out from current session
Message
Send- Send a text messageSend Media- Send a photo or documentGet Many- Get message historySearch- Search messages in a chatEdit- Edit a messageDelete- Delete messagesForward- Forward messages to another chat
Chat
Get All- Get all dialogs/chatsGet- Get chat informationGet Members- Get chat membersLeave- Leave a chat
Channel
Join- Join a channel (public or via invite link)Leave- Leave a channelGet Info- Get channel informationGet Members- Get channel subscribers
Contact
Get All- Get all contactsSearch- Search users globally
User
Get- Get user informationGet Photos- Get user profile photos
MTProto Trigger (Experimental)
Trigger node for listening to Telegram events.
Usage Examples
Send a Message
- Add "Telegram MTProto" node
- Select Resource: "Message"
- Select Operation: "Send"
- Enter Chat ID:
@usernameor numeric ID - Enter Message text
Get All Chats
- Add "Telegram MTProto" node
- Select Resource: "Chat"
- Select Operation: "Get All"
- Set Limit: 50
Search Messages
- Add "Telegram MTProto" node
- Select Resource: "Message"
- Select Operation: "Search"
- Enter Chat ID
- Enter search Query
- Optionally filter by type (photos, videos, etc.)
Join a Channel
- Add "Telegram MTProto" node
- Select Resource: "Channel"
- Select Operation: "Join"
- Enter channel username or invite link
Chat ID Formats
The nodes accept multiple formats for identifying chats:
- Username:
@usernameorusername - Phone number:
+1234567890 - Numeric ID:
123456789or-100123456789 - Invite link:
https://t.me/joinchat/XXXXXort.me/+XXXXX
Important Notes
Session Management
- The session string allows full access to your Telegram account
- Keep it secure and never share it
- Each session appears in Telegram's active sessions
- You can terminate sessions from Telegram settings
Rate Limits
Telegram has rate limits. If you send too many requests:
- You may get
FLOOD_WAIT_Xerrors - The node will need to wait X seconds before retrying
- Consider adding delays between operations
Media Files
When sending media:
- Use the binary data from previous nodes
- Supported: photos (jpg, png, gif) and documents (any file)
- Maximum file size depends on your Telegram account type
Troubleshooting
"Phone code required" Error
Your session string is invalid or expired. Generate a new one using:
npx ts-node scripts/generate-session.ts
"AUTH_KEY_UNREGISTERED" Error
The session was terminated. Generate a new session string.
"FLOOD_WAIT_X" Error
You've hit rate limits. Wait X seconds before making more requests.
"PEER_ID_INVALID" Error
The chat ID format is incorrect or the chat doesn't exist. Try:
- Using @username format
- Getting the numeric ID from "Get All Chats"
Development
Building
npm run build
Linting
npm run lint
npm run lintfix
Formatting
npm run format
License
MIT