A simple Telegram bot that uses the OpenAI Agents SDK to interact with the Model Context Protocol (MCP) server.
# Build the Docker image
docker build -t agentic-telegram-bot .
# Run the Docker container
docker run -d \
--name telegent \
-e BOT_USERNAME="" \
-e TELEGRAM_BOT_TOKEN="" \
-e OPENAI_API_KEY="" \
-e OPENAI_MODEL="gpt-4.1" johnlin/agentic-telegram-bot
uv sync
-
Create a new bot using the BotFather on Telegram.
-
Get the bot token and username.
-
Setting for privacy mode:
- Use the command
/setprivacy
in the BotFather chat. - Select your bot.
- Choose "Disable" to allow the bot to receive all messages in groups.
- Use the command
-
Set the bot token and username in the
.envrc
or.env
file.
Create a .envrc
file in the root directory of the project and add the following environment variables:
# Telegram bot
export BOT_USERNAME=""
export TELEGRAM_BOT_TOKEN=""
# OpenAI API
export OPENAI_API_KEY=""
export OPENAI_MODEL="gpt-4.1"
# Firecrawl API key for advanced scrape feature(Optional)
FIRECRAWL_API_KEY=""
# Langfuse API key for LLM debug use(Optional)
LANGFUSE_PUBLIC_KEY=""
LANGFUSE_SECRET_KEY=""
LANGFUSE_HOST=""
If you are using Azure OpenAI, you can set the following environment variables instead:
AZURE_OPENAI_API_KEY=""
AZURE_OPENAI_ENDPOINT="https://<myopenai>.azure.com/"
OPENAI_MODEL="gpt-4.1"
AZURE_OPENAI_API_VERSION="2025-03-01-preview"
uv run bot