Skip to content

AshrafiPouya/OpenAssistantBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Telegram Bot

A serverless Telegram chatbot on Cloudflare Workers

A secure, lightweight AI chatbot that runs entirely on Cloudflare's free tier. Powered by OpenRouter's top free AI models, with a built-in web dashboard for setup β€” no terminal, no CLI, no build step.

Cloudflare Workers License Cost


🌟 Why this bot?

  • ⚑ Zero server cost β€” runs on Cloudflare's Free Tier. No VPS, no maintenance.
  • πŸ“‹ Copy-paste deploy β€” one _worker.js file. Paste it into the dashboard. Done.
  • 🎨 Web setup dashboard β€” configure tokens and settings in your browser, not in code.
  • πŸ€– 10 free AI models β€” switch any time with /model, automatic fallback on rate limits.
  • πŸ’Ύ Persists in KV β€” your settings survive code updates.
  • πŸ’¬ Remembers context β€” multi-turn conversations per user.

✨ Features

Feature Description
πŸ”€ Model switcher /model shows an inline keyboard of the top 10 free OpenRouter models
♻️ Auto-fallback If a model is rate-limited (429), the next one is tried automatically
🧠 Memory Remembers the last 10 messages per user (/clear to wipe)
πŸ” Protected webhook Secret-token check so only Telegram can reach your bot
πŸŽ›οΈ Web dashboard Change tokens, system prompt, and model list at /setup
βœ‚οΈ Long replies Auto-splits messages over Telegram's 4096-char limit

πŸš€ Quick Start

Get your bot running in about 3 minutes, entirely in the browser.

1. Create a KV Namespace

  1. Go to Cloudflare Dashboard β†’ Workers & Pages β†’ KV.
  2. Click Create a namespace, name it BOT_DB.

2. Deploy the Worker

  1. Go to Workers & Pages β†’ Create Application β†’ Create Worker.
  2. Name it (e.g. ai-bot) and click Deploy.
  3. Click Edit code, delete the sample, paste the contents of _worker.js, and click Deploy.

3. Bind the storage

  1. Go to your Worker β†’ Settings β†’ Bindings (or Variables).
  2. Add a KV Namespace Binding:
    • Variable name: BOT_DB
    • KV namespace: select the BOT_DB you created.
  3. Save and Deploy.

4. Configure & connect

  1. Open https://<your-worker>.workers.dev/setup.
  2. Enter:
  3. Click Save configuration, then click the Register webhook link.
  4. Open your bot in Telegram and send /start. πŸŽ‰

⚠️ Tip: Change the default admin password (admin) in the setup form right after your first save, so nobody else can edit your config.

πŸŽ›οΈ Managing your bot

Everything is changed from the web dashboard β€” no code edits needed:

  • /setup β€” update tokens, system prompt (personality), or the model list
  • /register β€” re-register the Telegram webhook (e.g. after changing the secret)
  • / β€” status page showing whether the bot is configured

In Telegram:

  • /model β€” pick which free AI model answers you
  • /clear β€” wipe your conversation history
  • /help β€” show commands

πŸ“Š Free-tier limits

Layer Free limit Meaning
Cloudflare Workers 100,000 req/day Effectively unlimited for a personal bot
Cloudflare KV 100,000 writes/day, 1,000 lists Plenty for chat history
OpenRouter free models ~20 req/min, ~50–200 req/day Your real bottleneck

If you outgrow OpenRouter's free daily cap, a one-time $10 credit (never expires) raises the free-model daily limit to ~1000 requests.

πŸ”§ Customization

The model list and personality are editable from /setup β€” but you can also change defaults at the top of _worker.js:

  • DEFAULT_MODELS β€” the model list and order
  • DEFAULT_SYSTEM_PROMPT β€” the bot's personality
  • HISTORY_LIMIT β€” how many past messages to remember

Free model IDs (ending in :free) change over time β€” see the current list at openrouter.ai/collections/free-models.

πŸ› οΈ Troubleshooting

  • Bot doesn't reply β†’ check the Worker's Logs (real-time) in the dashboard, and verify the webhook at https://api.telegram.org/bot<TOKEN>/getWebhookInfo
  • "Setup needed" page β†’ the BOT_DB KV binding is missing (step 3)
  • 403 in logs β†’ webhook secret mismatch; re-run Register webhook from /setup
  • "All free models rate-limited" β†’ you hit OpenRouter's daily free quota; wait for reset or add the one-time $10 credit

About

πŸ€– Free and open-source AI-powered Telegram assistant. Self-host, customize, and run your own bot in minutes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors