NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

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 pollingWebhooks
How it worksBot repeatedly asks Telegram for updatesTelegram sends updates to your URL
Needs a public HTTPS URLNoYes, Telegram requires HTTPS
Setup on SchokrSimpleNeeds your own domain and an HTTPS proxy in front
RecommendedYes, for almost every botOnly 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

  1. Get a token from @BotFather in Telegram.
  2. Create a Python, Node.js or Bun server in the console. 128 to 256 MB is enough for most bots.
  3. Upload your code and requirements.txt or package.json with the file manager.
  4. Create .env with TELEGRAM_TOKEN=<your-token>. See environment variables and secrets.
  5. Set the main file in your server's Startup settings and start the server.
  6. Send /start to 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 deleteWebhook method.
  • 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.