# Build a Telegram AI Bot with OpenAI (ChatGPT models)

Source: https://langbot.app/docs/en/recipes/openai/telegram

Step-by-step guide to running a OpenAI (ChatGPT models)-powered AI bot on Telegram with LangBot: model setup, bot credentials, networking, testing and troubleshooting.

This recipe puts a OpenAI (ChatGPT models) model behind a Telegram bot. LangBot receives messages from Telegram, runs them through a pipeline, and sends the answer back, so you do not write any platform code.

Use OpenAI's GPT models with LangBot's built-in Agent, with optional knowledge bases, MCP tools, Skills and a code sandbox.

## What you need

- A running LangBot instance: [LangBot Cloud](https://space.langbot.app/cloud) (no server needed) or a [self-hosted deployment](https://langbot.app/docs/en/deploy/langbot/docker.md) with Docker or `uvx langbot`.
- A OpenAI (ChatGPT models) account or server you can call from LangBot.
- A bot token from [@BotFather](https://t.me/BotFather) (send `/newbot` and pick a username ending in `bot`).

## Networking

Telegram uses long polling: LangBot only needs outbound access to `api.telegram.org`. No public webhook URL is required, so a laptop or home server works.

## 1. Add the OpenAI (ChatGPT models) model

1. Create an API key in the OpenAI console.
2. In LangBot, open **Models**, add an LLM model with the provider set to OpenAI and request URL `https://api.openai.com/v1`, then paste the API key and the model ID.
3. Enable **Tool Use** if the model supports function calling; MCP tools, Skills and the sandbox need it.
4. Use a current model ID from OpenAI's model list. Any OpenAI-compatible endpoint works the same way with its own request URL.

## 2. Create a pipeline

Open **Pipelines** in the LangBot WebUI, create a pipeline (or edit the default one) and set **AI** as follows.

| Field           | Value                                                                  |
| --------------- | ---------------------------------------------------------------------- |
| Runner          | **Local Agent** (built-in Agent)                                       |
| Model           | The model you just added. You can add fallback models.                 |
| Prompt          | Instructions: who the bot is, tone, what it must not do.               |
| Knowledge Bases | Optional. Attach a knowledge base so answers come from your documents. |

## 3. Create the Telegram bot

1. Under **Bots**, create a bot and select the **Telegram** adapter (the new adapter in LangBot 4.11, not the deprecated legacy one).
2. Paste the token, enable Markdown and streaming if you want them, then enable and save the bot.

## 4. Bind and test

Open the bot, select the pipeline you created, save and make sure the bot is enabled.

Press **Start** in a private chat with the bot and send a message. In groups, the message must match the pipeline's trigger rules (for example, mention the bot or reply to it).

## Troubleshooting

- Region or network errors: LangBot must be able to reach the request URL. Behind a restricted network, use a compatible gateway you can reach.
- Only one running instance may poll a token. If replies are missing, make sure the same bot is not enabled in another LangBot instance or script.
- Check **Monitoring** in the WebUI: every message, pipeline run and error is recorded there.

## FAQ

### Do I need a server with a public IP for Telegram?

No. Telegram uses long polling: LangBot only needs outbound access to `api.telegram.org`. No public webhook URL is required, so a laptop or home server works.

### Does the Telegram bot support streaming replies?

Yes. Enable streaming on the bot; the AI back end must also stream. See the [platform feature matrix](https://langbot.app/docs/en/insight/platform-features.md) for details.

### Can the same OpenAI (ChatGPT models) setup serve other platforms too?

Yes. A pipeline can be bound to many bots, so one configuration can answer on several platforms at once.

## Related guides

- [Full Telegram setup guide](https://langbot.app/docs/en/usage/platforms/telegram.md)
- [Model configuration](https://langbot.app/docs/en/usage/models/readme.md)
- Other AI back ends on Telegram: [Dify](https://langbot.app/docs/en/recipes/dify/telegram.md) · [n8n](https://langbot.app/docs/en/recipes/n8n/telegram.md) · [Coze](https://langbot.app/docs/en/recipes/coze/telegram.md) · [Langflow](https://langbot.app/docs/en/recipes/langflow/telegram.md) · [DeepSeek](https://langbot.app/docs/en/recipes/deepseek/telegram.md)
- OpenAI (ChatGPT models) on other platforms: [Discord](https://langbot.app/docs/en/recipes/openai/discord.md) · [Slack](https://langbot.app/docs/en/recipes/openai/slack.md) · [Lark (Feishu)](https://langbot.app/docs/en/recipes/openai/lark.md) · [DingTalk](https://langbot.app/docs/en/recipes/openai/dingtalk.md) · [WeCom (internal app)](https://langbot.app/docs/en/recipes/openai/wecom.md) · [WeCom Intelligent Bot](https://langbot.app/docs/en/recipes/openai/wecombot.md)
