{"id":28203861,"url":"https://github.com/1dev-hridoy/nexalo-simsim-bot","last_synced_at":"2025-06-10T14:30:45.968Z","repository":{"id":286456043,"uuid":"961455115","full_name":"NexaloSIM/Nexalo-SimSim-Bot","owner":"NexaloSIM","description":"A feature-rich Telegram bot built with Node.js and Telegraf, integrated with the Nexalo SIM API for conversational responses and training capabilities. This bot supports prefix-based commands, admin-only features, and colorful logging with Chalk.","archived":false,"fork":false,"pushed_at":"2025-06-05T05:03:20.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-05T07:20:03.547Z","etag":null,"topics":["nexalo","nexalo-sim","simsim-nexalo","simsimi","simsimi-api","simsimi-nodejs-modeule","simsimi-pro","simsimibot","simsimnexalo","telegraf","telegram","telegram-api","telegram-bot"],"latest_commit_sha":null,"homepage":"https://nexalo.xyz/dashboard/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NexaloSIM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-06T15:03:30.000Z","updated_at":"2025-06-05T05:03:21.000Z","dependencies_parsed_at":"2025-04-06T16:23:36.313Z","dependency_job_id":"feab8789-ce33-4e55-9159-1509db7bde8e","html_url":"https://github.com/NexaloSIM/Nexalo-SimSim-Bot","commit_stats":null,"previous_names":["1dev-hridoy/nexalo-simsim-bot","nexalosim/nexalo-simsim-bot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexaloSIM%2FNexalo-SimSim-Bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexaloSIM%2FNexalo-SimSim-Bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexaloSIM%2FNexalo-SimSim-Bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexaloSIM%2FNexalo-SimSim-Bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NexaloSIM","download_url":"https://codeload.github.com/NexaloSIM/Nexalo-SimSim-Bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NexaloSIM%2FNexalo-SimSim-Bot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259092520,"owners_count":22804029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nexalo","nexalo-sim","simsim-nexalo","simsimi","simsimi-api","simsimi-nodejs-modeule","simsimi-pro","simsimibot","simsimnexalo","telegraf","telegram","telegram-api","telegram-bot"],"created_at":"2025-05-17T03:15:17.405Z","updated_at":"2025-06-10T14:30:45.953Z","avatar_url":"https://github.com/NexaloSIM.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Nexalo Telegram Bot\n\nA feature-rich Telegram bot built with Node.js and Telegraf, integrated with the Nexalo SIM API for conversational responses and training capabilities. This bot supports prefix-based commands, admin-only features, and colorful logging with Chalk.\n\n## Features\n\n- **Chat Responses**: Responds to messages without a prefix using the Nexalo SIM API (/v1/chat).\n- **Ping Command**: Admin-only command to check latency and user ID (!ping).\n- **Teach Command**: Admin-only command to train the SIM API with new question-answer pairs (!teach).\n- **Image Support**: Handles image responses from the API when response_type is \"image\".\n- **Colorful Logging**: Uses Chalk v4 for gradient-colored console logs with user details.\n- **Role-Based Access**: Restricts certain commands to admins listed in the .env file.\n\n## Prerequisites\n\n- **Node.js**: v20.17.0 or higher\n- **npm**: For package management\n- **Telegram Bot Token**: Obtain from BotFather\n- **Nexalo API Key**: Required for SIM API integration (see below)\n\n## How to Get a Nexalo API Key\n\nTo use this project, you need an API key from Nexalo. Follow these steps:\n\n1. **Sign Up**: Visit the Nexalo Dashboard https://nexalo.xyz/dashboard/sign-up. Create an account by filling out the registration form.\n2. **Sign In**: After signing up, log in to your Nexalo account.\n3. **Create an API Key**: Navigate to the API section (e.g., \"Nexalo API\" or \"Developer Settings\"). Click on \"Create API\" or a similar option. Enter a project name (e.g., \"NexaloTelegramBot\") and generate the API key. Copy the API key provided (it will look like a unique string, e.g., YOUR_API_KEY).\n4. **Use the API Key**: Open your code editor (e.g., VS Code). In the .env file, replace the NEXALO_API_KEY value with your copied API key. Do not share it in chat or public forums.\n\n## Installation\n\n1. **Clone the Repository**\n    ```bash\n    git clone https://github.com/1dev-hridoy/Nexalo-SimSim-Bot.git\n    cd nexalo-telegram-bot\n    ```\n\n2. **Install Dependencies**\n    ```bash\n    npm install\n    ```\n\n3. **Set Up Environment Variables**\n\n    Create a `.env` file in the root directory and add the following:\n\n    ```env\n    TELEGRAM_TOKEN=your_telegram_bot_token_here\n    NEXALO_API_KEY=your_nexalo_api_key_here\n    ADMIN_LIST=your_telegram_user_id,your_second_admin_id\n    BOT_PREFIX=!\n    ```\n\n    - **TELEGRAM_TOKEN**: Get this from BotFather by creating a new bot.\n    - **NEXALO_API_KEY**: Your Nexalo API key (see above).\n    - **ADMIN_LIST**: Comma-separated Telegram user IDs of admins (e.g., 123456789,987654321).\n    - **BOT_PREFIX**: Command prefix (default is !).\n\n    To find your Telegram user ID:\n\n    - Send a message to @userinfobot.\n    - Copy the Id field from the response.\n\n4. **Directory Structure**\n\n    ```none\n    nexalo-telegram-bot/\n    ├── src/\n    │   ├── commands/\n    │   │   ├── ping.js\n    │   │   └── teach.js\n    │   ├── config/\n    │   │   └── botConfig.js\n    │   ├── utils/\n    │   │   └── logger.js\n    │   └── index.js\n    ├── .env\n    ├── package.json\n    └── README.md\n    ```\n\n5. **Start the Bot**\n\n    ```bash\n    npm start\n    ```\n\n    Or directly:\n\n    ```bash\n    node src/index.js\n    ```\n\n## Usage\n\n### Commands\n\n- **!ping [user_id]** (Admin-only)\n    - Checks bot latency and returns the user ID.\n    - Example: `!ping` or `!ping 123456789`\n    - Response: `Pong! User ID: 123456789\\nLatency: 123ms`\n  \n- **!teach \u003cquestion\u003e | \u003canswer\u003e** (Admin-only)\n    - Trains the Nexalo SIM API with a new question-answer pair.\n    - Example: `!teach ki koro | Boring time, ki korbo?`\n    - Response: `Successfully taught!\\nQuestion: ki koro\\nAnswer: Boring time, ki korbo?\\nID: 2`\n\n### Chat Mode\n\n- Send any message without the prefix (e.g., `ki korteco`) to get a response from the Nexalo SIM API.\n- If the API returns an image (response_type: \"image\"), the bot sends the image.\n\n### Logging\n\n- Console logs show user details (username, UID, message type, chat type) with gradient-colored messages.\n- Example:\n    ```none\n    [INFO] 2025-04-06T14:35:00.000Z - User: @testuser UID: 123456789 Type: text Chat: Private Message: ki korteco Response: Chill kori, tu ki koris?\n    ```\n\n## Bot Process\n\n1. **Initialization**\n    - Loads environment variables from .env.\n    - Initializes the Telegraf bot with the Telegram token.\n    - Sets up command handlers and SIM API integration.\n\n2. **Command Handling**\n    - Loads commands from src/commands/ (e.g., ping.js, teach.js).\n    - Registers commands and aliases with Telegraf.\n    - Checks for prefix (!) and admin permissions before execution.\n\n3. **Message Processing**\n    - Prefixed Messages: Routes to the appropriate command handler.\n    - Non-Prefixed Messages: Sends to the Nexalo SIM API (/v1/chat) for a response.\n        - Text response: Sent as a message.\n        - Image response: Sent as a photo.\n\n4. **Training (Teach Command)**\n    - Parses !teach input into question and answer.\n    - Sends a POST request to /v1/train with the API key, question, answer, and language.\n    - Logs and reports the result (success or error).\n\n5. **Error Handling**\n    - Catches API errors (e.g., 401 Unauthorized) and displays specific messages.\n    - Logs errors with detailed user and chat information.\n\n6. **Shutdown**\n    - Gracefully stops on SIGINT or SIGTERM signals.\n\n## API Integration\n\n- **Chat Endpoint**: `https://sim.api.nexalo.xyz/v1/chat`\n    - **Request**: `{ \"api\": \"key\", \"question\": \"text\", \"language\": \"bn\" }`\n    - **Response**: Text or image based on response_type\n\n- **Train Endpoint**: `https://sim.api.nexalo.xyz/v1/train`\n    - **Request**: `{ \"api\": \"key\", \"question\": \"text\", \"answer\": \"text\", \"language\": \"bn\" }`\n    - **Response**: `{ \"status_code\": 201, \"data\": { \"message\": \"Conversation trained successfully\", \"id\": int } }`\n\n## Troubleshooting\n\n- **\"Invalid API key\"**:\n    - Ensure NEXALO_API_KEY matches a key in your Nexalo api table.\n    - Test with Postman: POST `https://sim.api.nexalo.xyz/v1/train` with your key.\n\n- **No Response**:\n    - Check if the Nexalo API server is running and accessible.\n    - Verify database setup (api and conversations tables).\n\n- **Command Not Working**:\n    - Ensure your user ID is in ADMIN_LIST for admin commands.\n    - Check the prefix in .env.\n\n## Contributing\n\n1. Fork the repository.\n2. Create a feature branch (`git checkout -b feature/new-feature`).\n3. Commit changes (`git commit -m \"Add new feature\"`).\n4. Push to the branch (`git push origin feature/new-feature`).\n5. Open a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Contact\n\nFor support, contact the developer on GitHub: [@1dev-hridoy](https://github.com/1dev-hridoy). or join discord\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1dev-hridoy%2Fnexalo-simsim-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1dev-hridoy%2Fnexalo-simsim-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1dev-hridoy%2Fnexalo-simsim-bot/lists"}