A powerful Telegram bot that utilizes OpenAI's GPT models for contextually accurate and dialect-specific translations!
Learn More Β»
Try Demo
Β·
Bot Commands
Β·
Contribute
Table of Contents
This Telegram bot leverages the power of OpenAI's GPT language models to provide advanced text translations. Unlike traditional translation services like Google Translate, this bot offers several unique advantages:
-
Contextual and Punctual Accuracy: Through prompt engineering, the bot is capable of understanding the context and nuances of the text, providing translations that are both contextually and punctually accurate.
-
Specific Language Context: The bot can be configured to understand and translate specific dialects or regional language variations, such as Spanish (Mexico Dialect).
-
Typo Detection: The advanced AI model automatically detects typos and corrects them, ensuring the translation is as accurate as possible.
π‘ Tip: This bot can be used in group chats as well as private chats for live translations!
To get your own local instance of the Telegram AI translation bot up and running, follow these simple steps:
Before you continue, you will need to do the following:
-
Get an OpenAI API key. If you don't know how to do so, use this guide for reference.
Before sure to review the pricing for OpenAI's API in deciding which model to use. The default model is
gpt-4o-mini
, which is the singificantly cheaper and faster option, compared togpt-4o
. -
Create a new Telegram bot and get the bot token using BotFather. If you don't know how to do so, use this guide for reference. Additionally, you will need to change the following settings in BotFather:
-
/mybots
-><your_bot_name>
->Bot Settings
->Group Privacy
->Turn off
-
/mybots
-><your_bot_name>
->Bot Settings
->Allow Groups
->Turn on
-
Although there isn't a completely simple way to set up this bot, the easiest way to do so is by deploy the Docker image on Google Cloud Platform. If you don't know what a Docker image is, don't worry, the following steps will guide you through the process of deploying the bot to the cloud using Google Cloud Platform:
If you'd prefer to deploy the bot manually, follow the folowing steps in your preferred local or cloud environment. For the sake of this guide, we will be deploying the bot locally from source and docker in a UNIX environment (On a MacOS or Linux machine).
If you don't have docker installed, you can use Option 2 to run the bot locally from source.
-
Pull the Docker image from Docker Hub:
docker pull hschickdevs/telegram-translate-ai
-
Run the Docker image:
You will need to specify your OpenAI API key and Telegram bot token as environment variables. Additionally, you can specify the GPT model to use (e.g.,
gpt-4o-mini
orgpt-4o
, or any desired model listed on their website). You can leave theMODEL
environment variable empty to use the default model (3.5 turbo).docker run -d --name telegram-translate-ai \ -e OPENAI_TOKEN=<YOUR_APIKEY> \ -e BOT_TOKEN=<YOUR_TELEGRAM_BOT_TOKEN> \ -e MODEL=<GPT-MODEL> \ hschickdevs/telegram-translate-ai
-
If you want to see the logs, you can use the following command:
docker logs -f telegram-translate-ai
You can also attach to the container to see the logs in real-time:
docker attach telegram-translate-ai
If you don't see any errors, the bot should now be running! Head to your bot on Telegram and test it out.
-
Before you begin, make sure you have Python 3.9+ and pip installed on your system.
Check your Python version in your command prompt using:
-
MacOS/Linux:
python3 -V
-
Windows:
python -V
or
py -V
If you do not have Python 3.9+ installed, you can download it π here.
-
-
Clone the repo:
git clone https://github.com/hschickdevs/Telegram-Translate-AI.git
-
CD into the project directory:
cd Telegram-Translate-AI
-
Install pip packages:
pip install -r requirements.txt
-
Set environment variables. The following environment variables should be set:
OPENAI_TOKEN=<YOUR_APIKEY> BOT_TOKEN=<YOUR_TOKEN> MODEL=<GPT-MODEL>
Note: The
MODEL
variable is optional and defaults togpt-4o-mini
. If you have the plus subscription, you can set this togpt-4o
for better results.To set your environment variables, rename the file called
.env.example
in the root directory of the project to.env
, and then replace the value contents with your tokens and model.Note: The existing values in the
.env.example
file are placeholders and are for demonstration purposes only. You should never share your API keys or tokens with anyone. -
Make sure that you are in the root directory of the project (type
pwd
), and then run the following command to start the bot:python3 -m src
Note: If you are using Windows, you may need to use
python -m src
orpy -m src
instead.
If you don't see any errors, the bot should now be running! Head to your bot on Telegram and test it out.
Returns all available commands and their descriptions.
(Use /t or /translate) π Translate text from one language to another.
The first two "-" symbols are used as the delimiter/separator for the source language & context, target language & context, and text. As long as you provide the first two "-" symbols between source & target and target & text, you can use as many as you want in the text.
Parameter | Description |
---|---|
source (context) | The source language and context (e.g., dialect) from which you want to translate. |
target (context) | The target language and context (e.g., dialect) to which you want to translate. |
text | The text you want to translate. |
For example, the following command translates English to Spanish in the dialect of Madrid, Spain (as opposed to Mexico City dialect):
/t English - Spanish (Madrid Dialect) - Hi there, I'm a bot!
(Use /s or /session) π Start a continuous translation session. In this mode, every following message you send will be automatically language detected and translated to the other language in the pair.
Parameter | Description |
---|---|
language1 (context) | The first language and context (e.g., dialect) in the translation pair. |
language2 (context) | The second language and context (e.g., dialect) in the translation pair. |
For example, the following command starts a continuous translation session with English and Spanish in the Mexico City dialect:
/session English - Spanish (Mexico City Dialect)
π To end a continuous session, click the "Quit Session" button on the inline keyboard below any of the translated messages.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Thanks to these awesome tools and frameworks for aiding in the development of this project!
- Add translation sessions
- Add detailed documentation
- Add Docker image
- Add bot Demo feature
- Add group translation sessions
- Multi-platform Support
- Discord
Distributed under the GPLv3.0 License. See LICENSE.txt
for more information.
In summary, the GNU General Public License v3 (GPLv3) is a free software license that allows you to use, modify, and distribute the software for personal and commercial use.
However, any changes you make must also be open-sourced under the same license. This ensures that derivative work remains free and open, promoting collaboration and transparency. Importantly, if you distribute the software or any modifications, you must make the source code available and clearly state any changes you've made.
Telegram: @hschickdevs