How to host a Telegram bot (long polling vs webhooks)
Host a Telegram bot 24/7 on Schokr with python-telegram-bot, grammY or Telegraf. Why long polling is the easiest option and how webhooks differ.
Updated · 2 min read
The easiest way to host a Telegram bot on Schokr is long polling: your bot asks Telegram for new messages, so it needs no public URL, no HTTPS and no open port. Upload your code to a Python, Node.js or Bun server, put your bot token in a .env file and start it.
Long polling vs webhooks
| Long polling | Webhooks | |
|---|---|---|
| How it works | Bot repeatedly asks Telegram for updates | Telegram sends updates to your URL |
| Needs a public HTTPS URL | No | Yes, Telegram requires HTTPS |
| Setup on Schokr | Simple | Needs your own domain and an HTTPS proxy in front |
| Recommended | Yes, for almost every bot | Only if you have a specific reason |
Schokr servers do not sleep, so a polling bot stays online 24/7.
Python: python-telegram-bot
requirements.txt:
python-telegram-bot==21.6
python-dotenv==1.0.1
bot.py:
import os
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
load_dotenv()
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hello! I am running on Schokr.")
app = Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
Node.js or Bun: grammY
require('dotenv').config()
const { Bot } = require('grammy')
const bot = new Bot(process.env.TELEGRAM_TOKEN)
bot.command('start', (ctx) => ctx.reply('Hello! I am running on Schokr.'))
bot.catch((err) => console.error(err))
bot.start()
Node.js: Telegraf
require('dotenv').config()
const { Telegraf } = require('telegraf')
const bot = new Telegraf(process.env.TELEGRAM_TOKEN)
bot.start((ctx) => ctx.reply('Hello! I am running on Schokr.'))
bot.launch()
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))
Deploy on Schokr
- Get a token from @BotFather in Telegram.
- Create a Python, Node.js or Bun server in the console. 128 to 256 MB is enough for most bots.
- Upload your code and
requirements.txtorpackage.jsonwith the file manager. - Create
.envwithTELEGRAM_TOKEN=<your-token>. See environment variables and secrets. - Set the main file in your server's Startup settings and start the server.
- Send
/startto your bot.
Common problems
- 409 Conflict: terminated by other getUpdates request: the same token is polling from two places, for example your laptop and Schokr. Stop the other copy.
- Bot ignores messages after switching from webhooks: delete the old webhook. grammY and python-telegram-bot do this on start by default; otherwise call the Bot API
deleteWebhookmethod. - Bot does not see group messages: privacy mode is on. Change it with BotFather or make the bot an admin.
Using webhooks anyway
Webhooks need an HTTPS URL on port 443, 80, 88 or 8443. Schokr has no built-in HTTPS, so you would need your own domain and a proxy in front that terminates TLS and forwards to your server's port. See using your own domain.