- Description
- Features
- Documentation
- Why Telethon?
- Hugging Face Integration
- Installation
- Usage
- Configuration
- To Obtain Your Telegram Credentials
- Contributing
- License
- Contact
- Screenshots
The Virtual Secretary Bot is a Python-based automated application designed to respond to Telegram messages by checking availability in Google Calendar and replying based on scheduled events. It uses the Google Calendar API, Telethon, Hugging Face, and natural language parsing with parsedatetime for a smooth interactive experience.
- Automatic Responses: Provides real-time updates on availability based on scheduled events.
- Natural Language Processing: Understands and processes queries like "Are you free now?" or "What do you have on [date]?"
- Google Calendar Integration: Retrieves events from the user's primary and secondary calendars.
- Multilingual Support: Translates user inputs to English for better parsing.
- Current Event Check: Notifies users if they are currently busy with an event.
- AI-Powered Responses: Uses Hugging Face's Inference API for intelligent conversation capabilities.
-
Google Calendar API Quickstart for Python: Learn how to set up and use the Google Calendar API with Python. Google Calendar API Quickstart
-
Parsing Human-Readable Date/Time Strings: Use the parsedatetime library to parse date and time strings. Parsedatetime Library
-
Google Translate API: Guide on using Google Translate for translating text in Python. Google Translate in Python
-
Telethon for Telegram Userbot: Official documentation and GitHub repository for Telethon, the library used to interact with Telegram. Telethon Documentation Telethon GitHub Repository
-
Google Calendar Automation in Python: A video tutorial on automating Google Calendar with Python. Google Calendar Automation Video
-
Hugging Face Integration: This bot now integrates with Hugging Face's Inference API to provide AI-powered responses to Telegram messages. Hugging Face Inference API
We chose Telethon for this project because it stands out as one of the few libraries that support the creation of userbots in Telegram. Unlike other libraries like python-telegram-bot
or aiogram
, which are primarily designed for creating bots that interact with Telegram's Bot API, Telethon allows us to interact with Telegram as a regular user. This capability is crucial for our use case, where the bot needs to respond to messages in a personal user context, not just within bot channels or groups. Telethon provides robust functionality for managing user interactions and accessing Telegram's full range of features, making it an ideal choice for implementing a userbot that integrates seamlessly with Google Calendar and other services.
Hugging Face is a leading platform for machine learning models, specializing in natural language processing (NLP) and AI-powered applications. It provides an extensive library of pre-trained models and APIs that allow developers to integrate AI functionalities seamlessly into their applications. One of the key features of Hugging Face is the InferenceClient
, which enables users to interact with models hosted on the Hugging Face Hub, such as google/gemma-2-2b-it
.
To set up this bot, follow these steps:
-
Clone the Repository:
git clone https://github.com/SimoneMoreWare/virtual-secretary-bot.git
-
Create a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
Obtain API Credentials:
- Telegram API: Obtain your api_id and api_hash from Telegram here.
- Google Calendar API: Follow the quickstart guide to get your credentials.json.
- Hugging Face API: Obtain an API key from Hugging Face and ensure you have access to the model
google/gemma-2-2b-it
.
-
Configure Your Credentials:
- Replace the placeholder values in the script with your actual Telegram API credentials, Google Calendar credentials, and Hugging Face API key.
- Ensure you have a credentials.json file for Google Calendar and a token.json file if you've previously authenticated.
- Set up the bot by creating a
.env
file with the following parameters:TELEGRAM_API_ID=<your_api_id> TELEGRAM_API_HASH=<your_api_hash> GOOGLE_CALENDAR_ID=<your_calendar_id> HF_API_KEY=<your_huggingface_api_key>
Show examples of how to use the bot, including screenshots or commands.
- Start the bot with:
python bot.py
- Send a message on Telegram, for example:
- "Are you free now?": The bot checks for current events and responds with availability.
- "What is the next appointment?": The bot retrieves the next scheduled event.
- "What do you have on [date]?": The bot provides a list of events for the specified date.
- "Ask me anything": The bot responds using the Hugging Face google/gemma-2-2b-it model, providing general answers to your questions.
- "Summarize this text": The bot can generate concise summaries of provided text using the Hugging Face model.
- "Generate a meeting summary": If you provide meeting notes, the bot can use Hugging Face's model to summarize them.
- Telegram Credentials:
- Set api_id, api_hash, and phone_number in the script.
- Google Calendar API:
- Ensure credentials.json is present in the project directory.
- Hugging Face Integration:
- The bot leverages the
google/gemma-2-2b-it
model from Hugging Face for text generation and summarization. - Ensure the
transformers
library is installed:pip install transformers
. - If needed, set up your Hugging Face API token in the script.
- The bot leverages the
- User ID:
- Set yourUser_id to your Telegram user ID.
-
Visit the Telegram API Development page:
- Go to my.telegram.org.
-
Log in with your Telegram account:
- You’ll need to enter your phone number and verify it via a code sent to your Telegram app.
-
Create a new application:
- Once logged in, navigate to the "API Development Tools" section.
- Fill out the form to create a new application. You will need to provide:
- App title
- Short name
- URL (optional)
- After creating the app, you will see your API ID and API Hash.
You can find your user ID using one of the following methods:
- Using a Telegram Bot:
- Search for the bot named "userinfobot" in Telegram and sent it a messagge. Bot replies with User ID information.
Feel free to fork the repository, create branches, and submit pull requests. Contributions to improve functionality or documentation are welcome. If you have specific coding standards or testing procedures, please adhere to them:
- Ensure all code adheres to PEP 8 for Python styling.
- Include tests for any new features or bug fixes.
- Update the documentation accordingly.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or issues, please open an issue on the GitHub repository or contact me at [email protected]. You can also check my GitHub profile for more projects and updates.