From Telegram
Telegram News API
API for retrieving news from a Telegram channel. Automatically saves all messages from the channel and provides them via REST API.
Features
- Automatic retrieval of new messages from the channel
- Persistence of messages between restarts
- REST API for fetching messages
- Docker support
- Automatic restart on failures
Installation
Standard Installation
- Clone the repository
- Install dependencies:
npm install
- Copy the
.env.examplefile to.envand fill in the necessary environment variables:
BOT_TOKEN=your_bot_token
CHANNEL_USERNAME=@your_channel
PORT=3000
Docker Installation
- Clone the repository
- Create a
.envfile with the required environment variables (as described above) - Run via Docker Compose:
docker-compose up -d
To update the container:
docker-compose build && docker-compose up -d
Running
Standard Run
For development:
npm run dev
For production:
npm start
Docker Run
Start:
docker compose up -d
View logs:
docker compose logs -f
Stop:
docker compose down
API Endpoints
GET /api/news
Returns a list of news from the Telegram channel.
Response format:
{
"success": true,
"total": 10,
"data": [
{
"title": "News Title",
"content": "News Content",
"date": "2024-01-01T12:00:00.000Z",
"type": "text",
"channel": "Channel Name",
"messageId": 123
}
]
}
Data Storage
- In a standard installation, messages are saved to the
messages.jsonfile in the project root. - In a Docker installation, the
messages.jsonfile is mounted as a volume to persist data between container restarts.
Requirements
- Node.js 18 or higher
- For Docker installation: Docker and Docker Compose
Troubleshooting
- Ensure the bot is added to the channel as an administrator.
- Verify the bot token and channel name in
.env. - If using Docker, check the logs:
docker compose logs -f. - Ensure the
messages.jsonfile is writable.