---
name: wizard-telegram-deployment
description: Deploy a wizard house bot with Gitea integration and Telegram connectivity
---

# Wizard Telegram Bot Deployment

Deploy a Hermes wizard house with full Gitea integration and Telegram bot connectivity.

## Prerequisites
- Gitea admin access (or Timmy's token)
- Telegram BotFather token
- Hermes VPS with Ollama
- System resources (monitor RAM - 7B model = 4.9GB, 1.5B = 1.1GB)

## Steps

1. **Create Gitea User**
   ```bash
   curl -X POST "http://143.198.27.163:3000/api/v1/admin/users" \
     -H "Authorization: token $TIMMY_ADMIN_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"login_name":"wizardname","username":"wizardname","email":"wizard@timmy.foundation","password":"temp123","must_change_password":false}'
   ```

2. **Generate Token for User**
   ```bash
   # Must be done as non-root git user or via web UI
   # CLI method: SSH to Gitea server, run:
   sudo -u git gitea admin user generate-access-token --username wizardname --scopes read:repository,write:repository,read:user --token-name production
   ```

3. **Create Repo and Webhook**
   ```bash
   curl -X POST "http://143.198.27.163:3000/api/v1/user/repos" \
     -H "Authorization: token $WIZARD_TOKEN" \
     -d '{"name":"wizard-adventures","private":false}'
   
   curl -X POST "http://143.198.27.163:3000/api/v1/repos/wizardname/wizard-adventures/hooks" \
     -H "Authorization: token $WIZARD_TOKEN" \
     -d '{"type":"gitea","config":{"url":"http://localhost:PORT/webhook/wizard","content_type":"json"},"events":["push","pull_request","issues"],"active":true}'
   ```

4. **Directory Structure**
   ```
   /root/wizards/wizardname/
   ├── home/
   │   ├── .env (token, secrets)
   │   ├── wizard_dispatcher.py
   │   ├── wizard_telegram.py
   │   └── wizard_churn.py
   ├── SOUL.md
   └── ACTIVATE.sh
   ```

5. **Dispatcher Pattern (Snappy)**
   - Use queue.Queue() for non-blocking message intake
   - 2 worker threads processing Ollama
   - NO CANNED DIALOG - ever
   - On Ollama failure: brief error or silence
   - Timeout: 60s for Ollama generation

6. **Telegram Bot Setup**
   ```python
   from telegram import Update
   from telegram.ext import Application, MessageHandler, filters
   
   application = Application.builder().token(TOKEN).build()
   application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
   application.run_polling()
   ```

7. **Ollama Integration**
   ```python
   def generate_response(prompt):
       try:
           response = requests.post('http://localhost:11434/api/generate',
               json={"model": "qwen2.5:1.5b", "prompt": prompt, "stream": False},
               timeout=60)
           return response.json()['response']
       except Exception as e:
           return None  # NO CANNED FALLBACK - ever
   ```

## Pitfalls
- **NEVER add canned responses** - if Ollama down, return None or brief error
- **Monitor RAM** - 7B model will kill everything else
- **Kill burn scripts** - check for intentional CPU burners
- **One model at a time** - unload others before starting

## Verification
- Message bot directly → should respond via Ollama (not instantly)
- Check /api/tags → confirm model loaded
- Check RAM usage → ensure 2GB+ free for operations

## Tags to Create
- `golden_{wizardname}` - peak performance state
- `fix_saboteur` - when canned code removed
- `snappy_v2` - queue+worker architecture restored