A collection of simple TypeScript scripts for managing Telegram messages and chats.
- Node.js installed
- Telegram API credentials (API ID and API Hash)
- Get them from https://my.telegram.org/apps
-
Clone the repository
-
Install dependencies:
npm install
-
Create a
.envfile in the root directory:API_ID=your_api_id API_HASH=your_api_hash SESSION_STRING=your_session_string
Get your Telegram session string for authentication.
npm run get-session- Enter your phone number
- Enter the verification code
- Save the session string to your
.envfile asSESSION_STRING
List all your Telegram chats with their IDs.
npm run get-chatsDisplays:
- Chat name
- Chat ID (needed for other scripts)
- Chat type (User/Group/Channel)
Export all messages from a specific chat to an HTML file.
npm run get-messages- Enter the chat ID when prompted
- Messages are sorted by date (ascending)
- Output saved as
chat_{chatId}_{timestamp}.html
Delete all YOUR messages from a specific chat.
npm run clean-messages- Enter the chat ID when prompted
- Confirm the deletion
- Only your messages will be deleted
⚠️ Warning: This action cannot be undone!
- Session strings are sensitive - keep your
.envfile secure - Add
.envto.gitignoreto avoid committing credentials - The chat ID can be obtained using the
get-chatsscript - For the
clean-messagesscript to work, you need to have an active conversation with the user/chat
ISC