My live bot: Telegram Bot Demo
This is a Simple Telegram Bot built in TypeScript.
It can:
- Respond to
/startwith a welcome message. - Respond to
/pingwithPong!. - Respond to
/imagewith a photo of Dua Lipa and caption. - Reply to unknown commands with a default message.
- Optionally, admins can use an
index.htmlpage to reset the bot, check webhook status, and see basic info.
/project-root
ββ public/
β ββ index.html # Admin page for reset, webhook status
ββ src/
β ββ index.ts # Main webhook handler
ββ package.json
ββ tsconfig.json
ββ .env # Environment variables (you create your own)
- Open Telegram and search for
@BotFather. - Type
/newbotand follow the instructions. - Copy the Bot Token.
Create a .env file (also add them on Vercel or Netlify):
TELEGRAM_BOT_TOKEN=YOUR_BOT_TOKEN_HERE
ADMIN_ID=YOUR_TELEGRAM_USER_IDnpm install
# or
yarnIf you want to deploy to Vercel or Netlify, compile TypeScript:
npx tsc- This generates
index.js(or the folder structure according totsconfig.json). - Vercel supports TS directly, but Netlify usually requires JS build.
node index.js- The bot will run on your local server.
- Use ngrok if you want Telegram to reach your local server:
ngrok http 3000- Then set the webhook to the ngrok URL.
- Connect your project to Vercel.
- Make sure
.envvariables are set in the Vercel Dashboard. - Deploy.
- Set your webhook:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://<your-vercel-domain>/api/index- Build the TypeScript code (
npx tsc) so Netlify can serveindex.js. - Deploy the folder containing the JS output as a serverless function.
- Set the Telegram webhook pointing to your Netlify function URL.
| Command | Response |
|---|---|
/start |
Welcome message with image |
/ping |
Pong! |
/image |
Sends a photo of Dua Lipa with caption |
| anything else | "Unknown command." |
public/index.htmlcan be used to reset the bot, check webhook status, and monitor basic info.- This is optional but useful for non-coding admins.
- Admin bot commands can also respond to messages differently from regular users.
- Telegram sends messages to the bot webhook.
- The bot checks the message text.
- Depending on the command, it calls
sendorsendPhoto. - Replies are sent back as replies to the original message.
- For menu buttons (if implemented), inline buttons can send callbacks with images, links, and descriptions.
- Open
index.ts. - Add a new
else ifcondition inside the handler:
else if (text === "/hello") {
await send(chatId, "Hello there!", messageId);
}- Rebuild TS to JS if deploying to Vercel, Netlify:
npx tsc- Redeploy.
- This bot is stateless and minimal, ideal for learning.
- Can be extended with menus, inline buttons, and admin panels.
- Works flawlessly with Vercel or Netlify.
β Thatβs it! You now have a fully working simple Telegram bot with admin support and easy deployment.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/