{"id":22847644,"url":"https://github.com/asbdaryaee/ollama-telegram-bot","last_synced_at":"2026-04-18T10:34:54.645Z","repository":{"id":267823114,"uuid":"902469268","full_name":"AsbDaryaee/Ollama-Telegram-Bot","owner":"AsbDaryaee","description":"This repository contains the code for a simple Telegram bot that integrates with the Ollama API to process user inputs and provide intelligent responses. The bot is built using the node-telegram-bot-api library and uses axios for HTTP requests.","archived":false,"fork":false,"pushed_at":"2024-12-12T18:11:30.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T05:45:58.892Z","etag":null,"topics":["ollama","ollama-api","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AsbDaryaee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-12-12T16:17:29.000Z","updated_at":"2025-03-05T07:25:31.000Z","dependencies_parsed_at":"2024-12-12T17:30:18.607Z","dependency_job_id":"fbe008dc-aa90-49b7-91f3-9b7603a890c9","html_url":"https://github.com/AsbDaryaee/Ollama-Telegram-Bot","commit_stats":null,"previous_names":["asbdaryaee/ollama-telegram-bot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsbDaryaee%2FOllama-Telegram-Bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsbDaryaee%2FOllama-Telegram-Bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsbDaryaee%2FOllama-Telegram-Bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsbDaryaee%2FOllama-Telegram-Bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AsbDaryaee","download_url":"https://codeload.github.com/AsbDaryaee/Ollama-Telegram-Bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246423727,"owners_count":20774819,"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":["ollama","ollama-api","telegram","telegram-bot"],"created_at":"2024-12-13T04:08:42.173Z","updated_at":"2025-10-25T21:02:50.353Z","avatar_url":"https://github.com/AsbDaryaee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram Ollama Bot\n\nA sophisticated Telegram bot that seamlessly integrates with Ollama API to provide AI-powered conversations with multiple personas, conversation memory, and customizable settings.\n\n## Features\n\n- 🤖 **Multiple AI Personas**: Switch between different conversation styles (assistant, creative, technical, casual, uncensored)\n- 💾 **Conversation Memory**: Maintains context throughout your chat session\n- ⚙️ **Customizable Settings**: Adjust conversation history length and other parameters\n- 🔄 **Data Persistence**: Automatically saves conversations and settings\n- 🛡️ **Robust Error Handling**: Graceful handling of API errors and timeouts\n- 🎯 **User-Friendly Interface**: Intuitive menu system with inline keyboards\n- 🔧 **Modular Architecture**: Clean, maintainable codebase structure\n\n## Prerequisites\n\n- Node.js (v18 or higher)\n- Ollama installed and running locally\n- A Telegram bot token from [@BotFather](https://t.me/botfather)\n\n## Installation\n\n1. Clone the repository:\n\n```bash\ngit clone https://github.com/AsbDaryaee/Ollama-Telegram-Bot.git\ncd telegram-ollama-bot\n```\n\n2. Install dependencies:\n\n```bash\nnpm install\n```\n\n3. Configure your environment:\n   - edit `config/config.js` with your settings:\n\n```javascript\nmodule.exports = {\n  BOT_TOKEN: \"your-telegram-bot-token\",\n  OLLAMA_URL: \"http://localhost:11434\",\n  MODEL_NAME: \"llama2\",\n  MAX_HISTORY: 10,\n  REQUEST_TIMEOUT: 30000,\n};\n```\n\n4. Ensure Ollama is running:\n\n```bash\nollama serve\n```\n\n5. Start the bot:\n\n```bash\nnpm start\n```\n\n## Usage\n\n### Basic Commands\n\n- `/start` - Initialize the bot and show the main menu\n- `/stop` - Stop the current conversation and clear history\n- `/menu` - Display the main menu at any time\n\n### Main Menu Options\n\n1. **💬 Chat with AI** - Start or continue a conversation\n2. **🎭 Change Persona** - Switch between different AI personalities\n3. **⚙️ Settings** - Adjust bot configuration\n4. **ℹ️ Help** - Get usage instructions\n5. **🚪 Exit** - Close the menu\n\n### Available Personas\n\n- **👨‍💼 Assistant**: Professional and helpful responses\n- **🎨 Creative**: Imaginative and artistic responses\n- **🔧 Technical**: Detailed technical explanations\n- **😊 Casual**: Friendly and conversational tone\n- **🔓 Uncensored**: Direct responses without content filtering\n\n### Settings\n\n- **Max History**: Control how many previous messages the AI remembers (1-50)\n- **Model Selection**: Choose different Ollama models (if available)\n\n## Example Interactions\n\nUser: /start\nBot: [Main Menu with options]\n\nUser: [Clicks \"💬 Chat with AI\"]\nBot: You're chatting with Assistant persona. What would you like to know?\n\nUser: Explain quantum computing\nBot: [Detailed explanation based on current persona...]\n\nUser: [Clicks \"🎭 Change Persona\"]\nBot: [Persona selection menu]\n\nUser: [Selects \"🎨 Creative\"]\nBot: Persona changed to Creative! 🎨\n\nUser: Write a poem about AI\nBot: [Creative poem about artificial intelligence...]\n\n## Configuration\n\n### Environment Variables\n\nYou can also use environment variables instead of editing the config file:\n\n```bash\nexport BOT_TOKEN=\"your-telegram-bot-token\"\nexport OLLAMA_URL=\"http://localhost:11434\"\nexport MODEL_NAME=\"llama2\"\nexport MAX_HISTORY=\"10\"\n```\n\n### Ollama Models\n\nThe bot supports any model available in your Ollama installation. Popular options include:\n\n- `llama2` - General purpose model\n- `codellama` - Code-focused model\n- `mistral` - Fast and efficient model\n- `neural-chat` - Conversational model\n\nTo use a different model, update the `MODEL_NAME` in your configuration.\n\n## Data Storage\n\nThe bot automatically manages data persistence:\n\n- **Conversations**: Stored in `bot_data/conversations.json`\n- **System Prompts**: Stored in `bot_data/system_prompts.json`\n- **Auto-save**: Data is saved after each interaction\n- **Graceful Shutdown**: Ensures data integrity when stopping the bot\n\n## Error Handling\n\nThe bot includes comprehensive error handling for:\n\n- **API Connection Issues**: Automatic retry with user notification\n- **Model Loading**: Clear messages when models are unavailable\n- **Timeout Handling**: Configurable request timeouts\n- **Data Corruption**: Automatic recovery and backup creation\n- **Network Issues**: Graceful degradation and user feedback\n\n\n## Development\n\n### Running in Development Mode\n\n```bash\nnode ./index.js\n```\n\n### Code Structure Guidelines\n\n- **Handlers**: Process different types of Telegram updates\n- **Keyboards**: Generate inline keyboard layouts\n- **Utils**: Reusable utility functions\n- **Data**: Manage persistent storage operations\n- **Config**: Centralized configuration management\n\n## Troubleshooting\n\n### Common Issues\n\n1. **Bot not responding**:\n\n   - Verify Ollama is running: `curl http://localhost:11434/api/tags`\n   - Check bot token validity\n   - Review console logs for errors\n\n2. **Memory issues**:\n\n   - Reduce `MAX_HISTORY` setting\n   - Clear conversation data: `/stop`\n\n3. **API timeouts**:\n\n   - Increase `REQUEST_TIMEOUT` in config\n   - Check Ollama model performance\n\n4. **Permission errors**:\n   - Ensure write permissions for `bot_data/` directory\n   - Check file ownership and access rights\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature-name`\n3. Make your changes following the existing code style\n4. Test thoroughly with different personas and scenarios\n5. Submit a pull request with a clear description\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Support\n\nFor issues and questions:\n\n- Check the troubleshooting section above\n- Review the [Ollama documentation](https://ollama.ai/docs)\n- Open an issue in the repository\n\n---\n\n**Note**: This bot requires a local Ollama installation. Make sure Ollama is properly configured and running before starting the bot.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasbdaryaee%2Follama-telegram-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasbdaryaee%2Follama-telegram-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasbdaryaee%2Follama-telegram-bot/lists"}