{"id":22080565,"url":"https://github.com/electronic-mango/openai-chatgpt-telegram-bot","last_synced_at":"2026-01-28T17:06:30.558Z","repository":{"id":158837215,"uuid":"634186106","full_name":"Electronic-Mango/openai-chatgpt-telegram-bot","owner":"Electronic-Mango","description":"Telegram bot for your ChatGPT needs.","archived":false,"fork":false,"pushed_at":"2024-06-15T14:59:59.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-16T15:02:34.725Z","etag":null,"topics":["bot","chatgpt","openai","python","python-telegram-bot","python3","telegram"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Electronic-Mango.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":"2023-04-29T10:18:12.000Z","updated_at":"2024-06-15T15:00:02.000Z","dependencies_parsed_at":"2023-11-07T17:30:06.018Z","dependency_job_id":"9c81962d-0b79-47c9-817e-def811ecec1a","html_url":"https://github.com/Electronic-Mango/openai-chatgpt-telegram-bot","commit_stats":null,"previous_names":["electronic-mango/openai-chatgpt-telegram-bot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electronic-Mango%2Fopenai-chatgpt-telegram-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electronic-Mango%2Fopenai-chatgpt-telegram-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electronic-Mango%2Fopenai-chatgpt-telegram-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electronic-Mango%2Fopenai-chatgpt-telegram-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Electronic-Mango","download_url":"https://codeload.github.com/Electronic-Mango/openai-chatgpt-telegram-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709932,"owners_count":20821297,"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":["bot","chatgpt","openai","python","python-telegram-bot","python3","telegram"],"created_at":"2024-11-30T23:15:47.742Z","updated_at":"2026-01-28T17:06:30.517Z","avatar_url":"https://github.com/Electronic-Mango.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple OpenAI text model Telegram bot\n\nA simple and unofficial Telegram bot wrapping [OpenAI API](https://openai.com/blog/openai-api/) text models (like [ChatGPT](https://openai.com/blog/chatgpt)), build with [`python-telegram-bot`](https://github.com/python-telegram-bot/python-telegram-bot)!\n\nJust start a conversation and all messages in the chat will be used as inputs for ChatGPT.\n\nConversation/context is not stored permanently and will be removed when the bot is restarted.\n\n\n\n## Requirements\n\nThis bot was built with `Python 3.11`, [`python-telegram-bot`](https://github.com/python-telegram-bot/python-telegram-bot) and [`openai-python`](https://github.com/openai/openai-python).\nFull list of Python requirements is in the `requirements.txt` file, you can use it to install all of them.\n\n\n\n## Configuration\n\nConfiguration is done through a `.env` file. You can copy example file `.env.example` as `.env` and fill required parameters.\n\n```commandline\ncp .env.example .env\n```\n\n\n### Telegram bot\n\nOnly required parameter is a [bot token](https://core.telegram.org/bots#creating-a-new-bot).\n\nYou can also restrict who can access the bot via `ALLOWED_USERNAMES`.\nYou can specify multiple usernames delimited by space.\nIf you don't want to restrict the bot at all you can remove this parameter or leave it empty.\n\nYou can also define max response length in characters via `MAX_MESSAGE_LENGTH`.\nBot responses can be up to 4096 characters long, that value is used by default if this parameter is absent.\n\n```dotenv\nBOT_TOKEN='\u003cyour secret bot token\u003e'\nALLOWED_USERNAMES='myusername friendusername'\nMAX_MESSAGE_LENGTH=\u003ccustom max response length\u003e\n```\n\n\n### OpenAI API\n\nOne required parameter is [API key](https://platform.openai.com/account/api-keys).\n\n```dotenv\nOPENAI_TOKEN='\u003cyour secret API key\u003e'\n```\n\nThrough `.env` you can also configure other parameters:\n* `OPENAI_MODEL` - which model to use (gpt-3.5-turbo is used by default)\n* `OPENAI_SYSTEM_MESSAGE` - system message\n* `OPENAI_CONTEXT_LIMIT` - how many messages will be kept in the context aside from prompt, all messages will be kept if empty\n* `OPENAI_INITIAL_MESSAGE` - additional message added after system message to all conversations, can be empty for no additional messages\n* `OPENAI_LOG` - log level of OpenAI API, either `debug` or `info`, can be empty for no additional logging configuration\n\nNote that `gpt-3.5-turbo` [doesn't pay strong attention to system message](https://platform.openai.com/docs/guides/chat/instructing-chat-models), so changing it might not provide significant changes to responses.\nYou can use `OPENAI_INITIAL_MESSAGE` to tweak initial behaviour of the model.\n\n```dotenv\nOPENAI_MODEL='gpt-3.5-turbo'\nOPENAI_SYSTEM_MESSAGE='You are a helpful assistant.'\nOPENAI_CONTEXT_LIMIT=1000\nOPENAI_INITIAL_MESSAGE='You are a helpful assistant acting like 18th century butler,'\nOPENAI_LOG='info'\n```\n\n\n## Commands\n\n* `/start` - prints initial message returned from the model for just system message and optional initial message, doesn't impact conversation context\n* `/reset` - resets current conversation and removes all context, other than system message\n* `/promptset` - set new custom prompt, changes both system message and custom initial message (overwrites both `OPENAI_SYSTEM_MESSAGE` and `OPENAI_INITIAL_MESSAGE`)\n* `/promptreset` - restore prompt to default\n* `/promptget` - get custom prompt, won't respond with default one to avoid leaking configuration to users\n* `/promptremove` - force-remove any prompts from the conversation, including one defined in configuration files\n* `/cancel` - cancels ongoing operation, applies only to `/promptset`\n\n\n## Running the bot\n\nYou can run the bot from the source code directly, or in a Docker container.\n\n\n### From source code\n\n1. Create a Telegram bot via [BotFather](https://core.telegram.org/bots#6-botfather)\n2. Create [OpenAI API key](https://platform.openai.com/account/api-keys)\n3. Install all packages from `requirements.txt`\n4. Fill `.env` file\n5. Run `main.py` file with Python\n\n\n### Docker\n\n1. Create a Telegram bot via [BotFather](https://core.telegram.org/bots#6-botfather)\n2. Create [OpenAI API key](https://platform.openai.com/account/api-keys)\n3. Fill `.env` file\n4. Run `docker compose up -d --build` in terminal\n\nNote that `.env` file is used only for loading environment variables into Docker container through compose.\nThe file itself isn't added to the container.\n\n\n\n## Vision\n\nBot can respond to messages containing a **single** photo.\nUploading more photos will result in bot responding to each one separately.\nOther messages than photo or text are ignored.\n\n\n## Disclaimer\n\nThis bot is in no way affiliated, associated, authorized, endorsed by, or in any way officially connected with OpenAI.\nThis is an independent and unofficial project.\nUse at your own risk.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectronic-mango%2Fopenai-chatgpt-telegram-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felectronic-mango%2Fopenai-chatgpt-telegram-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectronic-mango%2Fopenai-chatgpt-telegram-bot/lists"}