iSolvoltar ao site

ENGINEERING

A Telegram bot answered by your own gateway

August 2026 · 4 min read

Just activated iSol API? Your key lives in the customer portal, isollm.ai/account → API keys (the portal shows the raw sk-… value; store it in your secret manager). The endpoint for every guide on this blog is https://tokens.4clouders.com/v1, and per-key spend updates live on the same portal page. That is all you need to follow along.

Why Telegram + your own gateway

Telegram is where half the company already answers questions, so it is the cheapest place to put a private assistant. The bot below needs no webhook, no public URL and no framework: long-polling from any machine with outbound internet. Every message is answered by your gateway, on infrastructure you control, with the same per-key budget and audit log as every other tool in this series.

Step 1: Create the bot (2 minutes)

  1. In Telegram, talk to @BotFather → /newbot → pick a name and a handle.
  2. BotFather replies with the bot token, that is your TELEGRAM_BOT_TOKEN.

Step 2: The whole bot

import os, requests

TG = f"https://api.telegram.org/bot{os.environ['TELEGRAM_BOT_TOKEN']}"
ISOL = "https://tokens.4clouders.com/v1/chat/completions"
KEY = os.environ["ISOL_API_KEY"]

def ask_isol(text: str) -> str:
    r = requests.post(ISOL, timeout=60,
        headers={"Authorization": f"Bearer {KEY}"},
        json={"model": "isol-4.9", "messages": [
            {"role": "system", "content": "You are the company's private assistant. Be brief."},
            {"role": "user", "content": text}]})
    r.raise_for_status()
    return r.json()["choices"][0]["message"]["content"]

def main():
    offset = None
    while True:
        upds = requests.get(f"{TG}/getUpdates",
            params={"timeout": 50, "offset": offset}, timeout=60).json()
        for u in upds.get("result", []):
            offset = u["update_id"] + 1
            msg = u.get("message") or {}
            if "text" in msg:
                requests.post(f"{TG}/sendMessage", json={
                    "chat_id": msg["chat"]["id"],
                    "text": ask_isol(msg["text"])})

if __name__ == "__main__":
    main()

Step 3: Prove the brain works before wiring the token

The function every message goes through is ask_isol(), and you can run it before touching Telegram at all. This is it, executed live against our gateway:

Real run of the Telegram bot handler answering through the iSol gateway
Real call, captured 2026-08-19: the exact function the bot runs per message, answered by the live gateway. Key masked.

Then: export TELEGRAM_BOT_TOKEN=…, python3 telegram_isol_bot.py, and message your bot.

Real session: the function the bot calls on every message, answered by the gateway in 2.6s.

Gotchas we hit running this for real

Handler executed against the live iSol gateway on 2026-08-19. Chat-side screenshots come from the deployment walkthrough, bring your BotFather token.

Same gateway, rest of your stack: every guide with real sessions

The pattern: one gateway, every tool WhatsApp GitHub Actions Teams Claude Code Cursor VS Code aider OpenCode n8n Zapier Power Automate Power BI Google Sheets Website chatbot Hermes Agent

Try it on ours

Our gateway (iSol API) runs exactly this setup on sovereign infrastructure, US$ 99/month, 14-day trial.

See plans →