
Build a Telegram Bot in 30 Lines
A Telegram bot is the fastest way to give your team an AI assistant that lives where they already chat. This guide walks through a working bot in about thirty lines of code.

What you need 🧰
- A bot token from @BotFather in Telegram
- Your DaqiAPI token
- Node.js with node-telegram-bot-api and the openai SDK
The core loop 🔁
Listen for text messages, send the message text to the chat endpoint and reply with the model’s answer. Add a small check so commands like /start are ignored.
Run it and test 🧪
Start the script, open your bot in Telegram and send a question. You should see an answer within a second or two, depending on the model.
| Piece | Tool | Why |
|---|---|---|
| Chat input | node-telegram-bot-api | Handles Telegram webhooks |
| Brain | chat completions | Generates the answer |
| Hosting | Any VPS or serverless | Keeps the bot online |
Frequently asked questions ❓
Do I need a webhook?
No. The simplest version polls Telegram’s API, which works fine for small bots.
Can I restrict who uses the bot?
Yes, filter by chat id or username before calling the model.
How much does a bot like this cost?
Pennies. A casual bot handling a few hundred messages a day costs a fraction of a credit.
Comments (0)