A simple experimental Telegram bot that translates text between languages using the Azure AI Translator API. This bot also tracks usage statistics using MongoDB and provides various commands for users to interact with.
- Detects the language of the input text and translates it to English.
- Translates text from English to a specified language.
- Provides usage statistics including total translations and system statistics.
- Lists supported languages.
- Tracks and displays the top translated languages.
- Allows users to send feedback.
- Tracks and displays the user's translation history.
- Allows users to delete their translation history.
- Node.js
- MongoDB
- Azure Translator API Key
-
Clone the repository:
git clone https://github.com/mezbaulanam/tg-translator-azure.git cd tg-translator-azure
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add your environment variables:TELEGRAM_BOT_TOKEN=your_telegram_bot_token MONGODB_URI=your_mongodb_uri AZURE_TRANSLATOR_KEY=your_azure_translator_key
-
Start the bot:
npm start
- /translate
<text>
: Detects the language of the input text and translates it to English.- Example:
/translate Hola, ¿cómo estás?
- Example:
- /translate_to
<lang_code>
<text>
: Translates the input text from English to the specified language.- Example:
/translate_to bn Hello, how are you?
- Example:
- /stats: Displays usage statistics including total translations and system statistics.
- Example:
/stats
- Example:
- /languages: Lists all supported languages.
- Example:
/languages
- Example:
- /feedback
<message>
: Sends feedback to the bot developers.- Example:
/feedback This bot is amazing!
- Example:
- /top_languages: Displays the top translated languages.
- Example:
/top_languages
- Example:
- /help: Shows the list of available commands.
- Example:
/help
- Example:
- /history: Retrieves and displays the user's translation history.
- Example:
/history
- Example:
- /delete_history: Deletes the user's translation history.
- Example:
/delete_history
- Example:
-
Translate text to English:
/translate Hola, ¿cómo estás?
-
Translate text to a specified language:
/translate_to bn Hello, how are you?
-
Get usage statistics:
/stats
-
List supported languages:
/languages
-
Send feedback:
/feedback This bot is amazing!
-
Get top translated languages:
/top_languages
-
Get help:
/help
-
Get translation history:
/history
-
Delete translation history:
/delete_history
dotenv
: Loads environment variables from a.env
file.node-telegram-bot-api
: Interacts with the Telegram Bot API.axios
: Makes HTTP requests to the Azure Translator API.fs
: Reads theazurevalid.json
file.os
: Retrieves system statistics.mongoose
: Connects to MongoDB and defines schemas and models.
-
Feedback Schema: Stores user feedback.
const feedbackSchema = new mongoose.Schema({ username: String, message: String, date: { type: Date, default: Date.now } });
-
Stats Schema: Tracks usage statistics.
const statsSchema = new mongoose.Schema({ totalTranslations: { type: Number, default: 0 }, languageCounts: { type: Map, of: Number, default: {} } });
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please see the CONTRIBUTING.md file for guidelines on how to contribute to this project.
If you have any questions or need further assistance, feel free to open an issue or start a discussion in the repository.