A CLI tool that automatically syncs Telegram chats to a Notion database. It finds all Telegram chats containing a specific substring (case-insensitive) and adds any new ones that aren't already in your Notion database.
Use this tool at your own risk! The author's Telegram account was frozen after using this tool. Telegram may flag automated access to their API as suspicious activity. Consider:
- Using this tool sparingly
- Adding delays between runs
- Monitoring your account for any warnings
- Scans Telegram: Searches through all your Telegram chats for those containing a specific substring (provided as a command line argument)
- Compares with Notion: Checks which of these chats already exist in your Notion database
- Syncs new chats: Automatically adds any new Telegram chats to your Notion database
-
Install dependencies:
npm install
-
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
- Copy the
api_id
andapi_hash
-
Get Notion credentials:
-
Integration Token: Go to https://www.notion.so/my-integrations
- Click "New integration"
- Give it a name (e.g., "Telegram Sync Tool")
- Select the workspace where your database is located
- Click "Submit"
- Copy the "Internal Integration Token" (this is your
NOTION_TOKEN
)
-
Database ID:
- Open your Notion database in the browser
- Look at the URL:
https://www.notion.so/workspace-name/DATABASE_ID?v=...
- Copy the
DATABASE_ID
part (it's a long string of letters/numbers) - Or right-click on the database title → "Copy link" and extract the ID from the URL
-
-
Set up environment variables:
cp env.example .env
Then edit
.env
and add your credentials:TELEGRAM_API_ID=your_api_id_here TELEGRAM_API_HASH=your_api_hash_here NOTION_TOKEN=your_notion_integration_token NOTION_DATABASE_ID=your_notion_database_id # Leave TELEGRAM_SESSION_STRING empty for first run TELEGRAM_SESSION_STRING=
Run the sync command with a substring to search for:
npm run dev -- update-notion "your-search-term"
Examples:
npm run dev -- update-notion "work"
npm run dev -- update-notion "friday"
This will:
- Authenticate with Telegram (if needed)
- Find all chats containing the specified substring in the name (case-insensitive)
- Check which ones are already in your Notion database
- Add any new ones automatically
- Automatically disconnect from Telegram when done
IMPORTANT: The first time you run this tool:
- Leave
TELEGRAM_SESSION_STRING
empty in your.env
file - Run the command - it will prompt you for your phone number and verification code
- Copy the session string that gets printed to the console
- Add it to your
.env
file asTELEGRAM_SESSION_STRING=your_session_string_here
- Future runs will use this session and won't require re-authentication
- Build:
npm run build
- Run in development mode:
npm run dev
- Watch for changes:
npm run watch
- The first time you run the tool, you'll need to provide your phone number and verification code
- If you have 2FA enabled, you'll also need to provide your password
- After successful login, save the session string for future use
- The tool accepts a search substring as a command line argument
- The tool automatically disconnects from Telegram when the sync is complete