LLM Flashcard Generator & Telegram Bot.
This application automatically generates flashcards from knowledge sources (like Notion) using an LLM and delivers them via a Telegram bot. You can also query your flashcards through Telegram commands.
- Automated flashcard generation from Notion.
- LLM integration via OpenRouter.
- Storage in SQLite database.
- Configuration via a simple web dashboard.
- Scheduled delivery of new flashcards via Telegram.
- Telegram commands (
/summary,/random) to retrieve flashcards.
To set up the application for the first time, follow these steps:
-
Install uv (if not already installed):
- Run
make install-uvto install uv, a fast Python package installer and resolver.
- Run
-
Create a Virtual Environment:
- Run
make venvto create a virtual environment using uv.
- Run
-
Install Dependencies:
- Run
make depto install the required dependencies from pyproject.toml into the virtual environment.
- Run
-
Run the Development Server:
- Run
make run-devto start the FastAPI development server for the web dashboard.
- Run
-
Launch the Telegram Bot:
- Run
make launch-telegram-botto start the Telegram bot in a separate terminal or background process.
- Run
-
Linting and Code Style:
- Run
make lintto check the codebase for style and errors. - Run
make lintfixto automatically fix linting issues where possible.
- Run
To set up the Telegram bot for this application, follow these steps:
-
Create a Bot with BotFather:
- Open Telegram and search for
@BotFather. - Start a chat with BotFather and send the
/startcommand. - Send the
/newbotcommand to create a new bot. - Follow the instructions to name your bot and get a bot token. Keep this token secure.
- Open Telegram and search for
-
Get Your Chat ID:
- Add your bot to a chat or create a new one with your bot.
- Send a message to your bot.
- Open a web browser and navigate to
https://api.telegram.org/bot<YourBOTToken>/getUpdates, replacing<YourBOTToken>with the token you received from BotFather. - Find the
chat_idin the response. This is the ID you will use to configure where the bot sends messages.
-
Configure the Bot in the Application:
- Access the web dashboard of this application.
- Enter the bot token and chat ID in the configuration settings under the Telegram section.
- Save the settings to update the configuration.
-
Running the Bot:
- Ensure the application is running, and the bot will start polling for updates and respond to commands like
/start,/summary, and/random.
- Ensure the application is running, and the bot will start polling for updates and respond to commands like
This project includes integration tests for the Notion API and related services. These tests ensure that the application correctly interacts with external APIs and manages data in the database.
- Ensure you have completed the "First-Time Setup" steps to install dependencies.
- Install any additional testing dependencies if not already included, such as
pytestandpytest-asyncio
- Create a file named
.env.integration.testin the root of the project. - Add the following environment variables to
.env.integration.test. Replace the placeholders with your actual values:NOTION_API_KEY=your_notion_api_key_here TEST_NOTION_PAGE_ID=your_test_page_id_here TEST_NOTION_DATABASE_ID=your_test_database_id_here- These variables are required for the tests to run without skipping. The
NOTION_API_KEYshould be a valid key from your Notion account.
- These variables are required for the tests to run without skipping. The
- Execute the tests using pytest:
pytest tests/ - To enable debug logging, set the
DEBUGenvironment variable toTruebefore running tests:DEBUG=True pytest tests/ - This will run the asynchronous tests and display detailed logs if configured.
- Tests are located in the
tests/directory. - They use pytest-asyncio for handling asynchronous code.
- If tests are skipped, check your
.env.integration.testfile for missing variables. - Run tests in your virtual environment to avoid conflicts.