Made by t.me/aizvestia
Python script fetches Telegram channel messages, processes them into a digest via Claude AI, generates an image with Replicate API, and sends both to user's saved Telegram messages.
- Telegram API: Fetches messages from a Telegram channel.
- Claude AI: Generates a digest from the combined messages.
- Replicate API: Generates an image based on the digest (FLUX + LoRa).
- Asyncio: Utilizes asynchronous programming to handle API requests efficiently.
The following Python libraries are required to run the script:
aiohttp
telethon
pytz
replicate
requests
argparse
logging
You can install the required libraries by running:
pip install -r requirements.txt
-
Clone the repository and navigate to the project directory.
-
Create a
.env
file in the root directory to store your environment variables.
Example .env
file:
API_ID=<your_telegram_api_id>
API_HASH=<your_telegram_api_hash>
PHONE_NUMBER=<your_phone_number>
CHANNEL_USERNAME=<your_telegram_channel_username>
CLAUDE_API_KEY=<your_claude_api_key>
REPLICATE_API_TOKEN=<your_replicate_api_token>
- Install dependencies:
pip install -r requirements.txt
To run the script, use the following command:
python digest.py
This script enables custom date ranges for digests via start_date
and end_date
arguments in YYYY-MM-DD
format, defining the message fetch period. Without arguments, it defaults to the last 7 days, allowing for various timeframes like weekly reports or project milestones.
Example usage with date range:
python digest.py --start_date 2023-09-01 --end_date 2023-09-07
In this example, the script fetches messages from the specified Telegram channel between September 1-7, 2023. Without these arguments, it generates a digest for the last 7 days by default.
The script will:
- Load the environment variables from the
.env
file. - Fetch messages from the specified Telegram channel.
- Process the messages into a digest using the Claude AI API.
- Generate an image using the Replicate API.
- Send the digest (with the generated image) to your saved messages on Telegram.
The script requires the following environment variables to be set in a .env
file:
API_ID
: Your Telegram API ID.API_HASH
: Your Telegram API hash.PHONE_NUMBER
: Your phone number registered with Telegram.CHANNEL_USERNAME
: The username of the Telegram channel to fetch messages from.CLAUDE_API_KEY
: API key for Claude AI to generate text digest.REPLICATE_API_TOKEN
: API token for Replicate API to generate images.
- Go to Telegram's my.telegram.org and log in with your Telegram account.
- Navigate to the "API development tools" section.
- Create a new application and you will receive your
API_ID
andAPI_HASH
. - Use your Telegram-registered phone number for the
PHONE_NUMBER
value. - Find the username of the Telegram channel you wish to fetch messages from and add it to
CHANNEL_USERNAME
.
- Register or sign in to Claude AI (from Anthropic) via their developer console.
- Go to the API section and generate your API key.
- Use this key as
CLAUDE_API_KEY
in your.env
file.
- Sign up or log in at Replicate.
- Navigate to the account settings and find your API token.
- Use the API token as
REPLICATE_API_TOKEN
in your.env
file.
The script uses the built-in logging
library to provide detailed logs about the execution. Logs are displayed in the console, including warnings and errors related to missing environment variables or failed API requests.
This project is licensed under the MIT License. See the LICENSE
file for details.