Skip to content

telegram_command

telegram_command #122

Workflow file for this run

# .github/workflows/workflow.yml
# Project Oracle — Automated Instagram Content Pipeline
#
# Triggers:
# 1. CRON: Runs every 6 hours — autonomous mode (AI picks everything)
# 2. workflow_dispatch: Manual trigger from GitHub UI
# 3. repository_dispatch: Triggered by Telegram webhook (type: telegram_command)
name: 🔮 Project Oracle — Content Pipeline
on:
# ── Scheduled CRON run (every 6 hours) ────────────────────────────────────
schedule:
- cron: "0 */6 * * *" # 00:00, 06:00, 12:00, 18:00 UTC
# ── Manual trigger from GitHub UI ─────────────────────────────────────────
workflow_dispatch:
inputs:
topic:
description: "Topic to post about (leave blank for autonomous)"
required: false
default: ""
post_type:
description: "Post type"
required: false
default: "reel"
type: choice
options:
- reel
- feed
mode:
description: "Run mode"
required: false
default: "cron"
type: choice
options:
- cron # Drain queue or autonomous
- single # Post single topic from input above
# ── Triggered by Telegram webhook (via GitHub API) ─────────────────────────
repository_dispatch:
types: [telegram_command]
env:
PYTHON_VERSION: "3.11"
jobs:
oracle-pipeline:
name: 🚀 Run Oracle Pipeline
runs-on: ubuntu-latest
timeout-minutes: 60 # MusicGen takes ~10min on CPU — needs generous limit
steps:
# ── Checkout (with LFS for bundled audio) ─────────────────────────────
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
lfs: true
# ── System dependencies ────────────────────────────────────────────────
- name: 🎬 Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y \
ffmpeg \
fonts-dejavu-core \
fonts-liberation \
fontconfig \
--no-install-recommends
fc-cache -fv
ffmpeg -version | head -3
# ── Python setup ──────────────────────────────────────────────────────
- name: 🐍 Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
# ── PyTorch CPU (separate step — large download, benefits from caching) -
- name: 🔦 Install PyTorch CPU
run: |
pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
# ── Python dependencies ────────────────────────────────────────────────
- name: 📦 Install Python dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
# ── Cache MusicGen model weights (~300MB, downloads once) ─────────────
- name: 🎵 Cache MusicGen weights
uses: actions/cache@v4
with:
path: |
~/.cache/huggingface
/root/.cache/huggingface
key: musicgen-small-v1
restore-keys: musicgen-small-
# ── Verify secrets ────────────────────────────────────────────────────
- name: 🔐 Verify required secrets
run: |
echo "Checking required secrets..."
[ -n "${{ secrets.GEMINI_API_KEY }}" ] && echo "✅ GEMINI_API_KEY" || echo "❌ GEMINI_API_KEY MISSING"
[ -n "${{ secrets.IG_ACCESS_TOKEN }}" ] && echo "✅ IG_ACCESS_TOKEN" || echo "❌ IG_ACCESS_TOKEN MISSING"
[ -n "${{ secrets.IG_USER_ID }}" ] && echo "✅ IG_USER_ID" || echo "❌ IG_USER_ID MISSING"
[ -n "${{ secrets.HF_TOKEN }}" ] && echo "✅ HF_TOKEN" || echo "❌ HF_TOKEN MISSING (image generation will fail)"
echo "Optional:"
[ -n "${{ secrets.GIST_ID }}" ] && echo "✅ GIST_ID" || echo "⚠️ GIST_ID not set (local config.json fallback)"
[ -n "${{ secrets.GIST_TOKEN }}" ] && echo "✅ GIST_TOKEN" || echo "⚠️ GIST_TOKEN not set"
[ -n "${{ secrets.TELEGRAM_BOT_TOKEN }}" ] && echo "✅ TELEGRAM_BOT_TOKEN" || echo "⚠️ TELEGRAM_BOT_TOKEN not set"
# ── CRON / Autonomous mode ─────────────────────────────────────────────
- name: 🤖 Run pipeline (CRON — autonomous)
if: |
github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.mode == 'cron')
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
IG_ACCESS_TOKEN: ${{ secrets.IG_ACCESS_TOKEN }}
IG_USER_ID: ${{ secrets.IG_USER_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIST_ID: ${{ secrets.GIST_ID }}
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: python main.py cron
# ── Single topic mode (manual dispatch) ───────────────────────────────
- name: 🎯 Run pipeline (single topic)
if: |
github.event_name == 'workflow_dispatch' &&
github.event.inputs.mode == 'single' &&
github.event.inputs.topic != ''
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
IG_ACCESS_TOKEN: ${{ secrets.IG_ACCESS_TOKEN }}
IG_USER_ID: ${{ secrets.IG_USER_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIST_ID: ${{ secrets.GIST_ID }}
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
python main.py single "${{ github.event.inputs.topic }}" "${{ github.event.inputs.post_type }}"
# ── Telegram command mode (repository_dispatch) ────────────────────────
- name: 📲 Handle Telegram command
if: github.event_name == 'repository_dispatch'
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
IG_ACCESS_TOKEN: ${{ secrets.IG_ACCESS_TOKEN }}
IG_USER_ID: ${{ secrets.IG_USER_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIST_ID: ${{ secrets.GIST_ID }}
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_UPDATE: ${{ toJson(github.event.client_payload) }}
run: python telegram_webhook_handler.py
# ── Notify on failure ─────────────────────────────────────────────────
- name: 📣 Notify Telegram on failure
if: failure()
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
python -c "
import asyncio, sys
sys.path.insert(0, '.')
from core.telegram_bot import TelegramBot
bot = TelegramBot()
asyncio.run(bot.send_message('❌ Project Oracle pipeline FAILED.\nCheck: https://github.com/${{ github.repository }}/actions'))
" || true