MCPcopy
hub / github.com/n3d1117/chatgpt-telegram-bot

github.com/n3d1117/chatgpt-telegram-bot @0.4.2 sqlite

repository ↗ · DeepWiki ↗ · release 0.4.2 ↗
171 symbols 605 edges 22 files 102 documented · 60%
README

ChatGPT Telegram Bot

python-version openai-version license Publish Docker image

A Telegram bot that integrates with OpenAI's official ChatGPT, DALL·E and Whisper APIs to provide answers. Ready to use with minimal configuration required.

Screenshots

Demo

demo

Plugins

plugins

Features

  • [x] Support markdown in answers
  • [x] Reset conversation with the /reset command
  • [x] Typing indicator while generating a response
  • [x] Access can be restricted by specifying a list of allowed users
  • [x] Docker and Proxy support
  • [x] Image generation using DALL·E via the /image command
  • [x] Transcribe audio and video messages using Whisper (may require ffmpeg)
  • [x] Automatic conversation summary to avoid excessive token usage
  • [x] Track token usage per user - by @AlexHTW
  • [x] Get personal token usage statistics via the /stats command - by @AlexHTW
  • [x] User budgets and guest budgets - by @AlexHTW
  • [x] Stream support
  • [x] GPT-4 support
  • If you have access to the GPT-4 API, simply change the OPENAI_MODEL parameter to gpt-4
  • [x] Localized bot language
  • Available languages :brazil: :cn: :finland: :de: :indonesia: :iran: :it: :malaysia: :netherlands: :poland: :ru: :saudi_arabia: :es: :taiwan: :tr: :ukraine: :gb: :uzbekistan: :vietnam: :israel:
  • [x] Improved inline queries support for group and private chats - by @bugfloyd
  • To use this feature, enable inline queries for your bot in BotFather via the /setinline command
  • [x] Support new models announced on June 13, 2023
  • [x] Support functions (plugins) to extend the bot's functionality with 3rd party services
  • Weather, Spotify, Web search, text-to-speech and more. See here for a list of available plugins
  • [x] Support unofficial OpenAI-compatible APIs - by @kristaller486
  • [x] (NEW!) Support GPT-4 Turbo and DALL·E 3 announced on November 6, 2023 - by @AlexHTW
  • [x] (NEW!) Text-to-speech support announced on November 6, 2023 - by @gilcu3
  • [x] (NEW!) Vision support announced on November 6, 2023 - by @gilcu3
  • [x] (NEW!) GPT-4o model support announced on May 12, 2024 - by @err09r
  • [x] (NEW!) o1 and o1-mini model preliminary support

Additional features - help needed!

If you'd like to help, check out the issues section and contribute!
If you want to help with translations, check out the Translations Manual

PRs are always welcome!

Prerequisites

Getting started

Configuration

Customize the configuration by copying .env.example and renaming it to .env, then editing the required parameters as desired:

Parameter Description
OPENAI_API_KEY Your OpenAI API key, you can get it from here
TELEGRAM_BOT_TOKEN Your Telegram bot's token, obtained using BotFather (see tutorial)
ADMIN_USER_IDS Telegram user IDs of admins. These users have access to special admin commands, information and no budget restrictions. Admin IDs don't have to be added to ALLOWED_TELEGRAM_USER_IDS. Note: by default, no admin (-)
ALLOWED_TELEGRAM_USER_IDS A comma-separated list of Telegram user IDs that are allowed to interact with the bot (use getidsbot to find your user ID). Note: by default, everyone is allowed (*)

Optional configuration

The following parameters are optional and can be set in the .env file:

Budgets

Parameter Description Default value
BUDGET_PERIOD Determines the time frame all budgets are applied to. Available periods: daily (resets budget every day), monthly (resets budgets on the first of each month), all-time (never resets budget). See the Budget Manual for more information monthly
USER_BUDGETS A comma-separated list of $-amounts per user from list ALLOWED_TELEGRAM_USER_IDS to set custom usage limit of OpenAI API costs for each. For *- user lists the first USER_BUDGETS value is given to every user. Note: by default, no limits for any user (*). See the Budget Manual for more information *
GUEST_BUDGET $-amount as usage limit for all guest users. Guest users are users in group chats that are not in the ALLOWED_TELEGRAM_USER_IDS list. Value is ignored if no usage limits are set in user budgets (USER_BUDGETS=*). See the Budget Manual for more information 100.0
TOKEN_PRICE $-price per 1000 tokens used to compute cost information in usage statistics. Source: https://openai.com/pricing 0.002
IMAGE_PRICES A comma-separated list with 3 elements of prices for the different image sizes: 256x256, 512x512 and 1024x1024. Source: https://openai.com/pricing 0.016,0.018,0.02
TRANSCRIPTION_PRICE USD-price for one minute of audio transcription. Source: https://openai.com/pricing 0.006
VISION_TOKEN_PRICE USD-price per 1K tokens of image interpretation. Source: https://openai.com/pricing 0.01
TTS_PRICES A comma-separated list with prices for the tts models: tts-1, tts-1-hd. Source: https://openai.com/pricing 0.015,0.030

Check out the Budget Manual for possible budget configurations.

Additional optional configuration options

Parameter Description Default value
ENABLE_QUOTING Whether to enable message quoting in private chats true
ENABLE_IMAGE_GENERATION Whether to enable image generation via the /image command true
ENABLE_TRANSCRIPTION Whether to enable transcriptions of audio and video messages true
ENABLE_TTS_GENERATION Whether to enable text to speech generation via the /tts true
ENABLE_VISION Whether to enable vision capabilities in supported models true
PROXY Proxy to be used for OpenAI and Telegram bot (e.g. http://localhost:8080) -
OPENAI_PROXY Proxy to be used only for OpenAI (e.g. http://localhost:8080) -
TELEGRAM_PROXY Proxy to be used only for Telegram bot (e.g. http://localhost:8080) -

Core symbols most depended-on inside this repo

localized_text
called by 77
bot/openai_helper.py
get_thread_id
called by 29
bot/utils.py
get_reply_to_message_id
called by 22
bot/utils.py
edit_message_with_retry
called by 11
bot/utils.py
is_direct_result
called by 8
bot/utils.py
is_group_chat
called by 7
bot/utils.py
wrap_with_indicator
called by 6
bot/utils.py
check_allowed_and_within_budget
called by 6
bot/telegram_bot.py

Shape

Method 125
Function 26
Class 20

Languages

Python100%

Modules by API surface

bot/openai_helper.py24 symbols
bot/telegram_bot.py23 symbols
bot/utils.py21 symbols
bot/usage_tracker.py16 symbols
bot/plugins/spotify.py13 symbols
bot/plugins/ddg_web_search.py6 symbols
bot/plugin_manager.py6 symbols
bot/plugins/worldtimeapi.py5 symbols
bot/plugins/wolfram_alpha.py5 symbols
bot/plugins/webshot.py5 symbols
bot/plugins/deepl.py5 symbols
bot/plugins/ddg_image_search.py5 symbols

Dependencies from manifests, versioned

Pillow11.0.0 · 1×
duckduckgo_search7.1.1 · 1×
gtts2.5.4 · 1×
openai1.58.1 · 1×
pydub0.25.1 · 1×
python-dotenv1.0.0 · 1×
pytube15.0.0 · 1×
requests2.32.3 · 1×
spotipy2.24.0 · 1×
tenacity8.3.0 · 1×
tiktoken0.7.0 · 1×

For agents

$ claude mcp add chatgpt-telegram-bot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact