chatgpt-telegram-workers

repository·master·Indexed 26 days ago

https://github.com/tbxark/chatgpt-telegram-workers

A lightweight, serverless framework for deploying ChatGPT-powered Telegram bots on platforms like Cloudflare Workers and Vercel. It supports multiple AI providers including OpenAI, Azure OpenAI, Cloudflare AI, Cohere, Anthropic, Mistral, DeepSeek, Gemini, and Groq. The project includes a plugin system and an experimental version, ChatGPT-Telegram-Workers-Next, driven by @vercel/ai.

Tokens
29.5K
Snippets
60
Records
162
Agent score
85%

What's inside chatgpt-telegram-workers

  1. Overview of ChatGPT-Telegram-Workers

    master

    ChatGPT-Telegram-Workers is a project designed to deploy your own ChatGPT Telegram bot easily. It is optimized for serverless deployment, specifically targeting Cloudflare Workers, allowing for a single-file 'copy-paste' setup without needing a local development environment, a domain, or a dedicated server.

    Key features include:

    • Serverless Deployment: Supports Cloudflare Workers, Vercel, and Docker.
    • Multi-AI Provider Support: Compatible with OpenAI, Azure OpenAI, Cloudflare AI, Cohere, Anthropic, Mistral, and more.
    • Bot Management: Supports multiple Telegram bots, streaming output, and multi-language support.
    • Interactive UI: Uses InlineKeyboards for model switching and supports custom commands for switching models or bot presets.
    • Extensibility: Includes a plugin system for custom functionality and supports text-to-image generation.
  2. Synchronize environment variables from Cloudflare Workers to Vercel

    master

    If you are reusing a wrangler.toml configuration file from Cloudflare Workers, you can synchronize those environment variables to Vercel by running pnpm run vercel:syncenv.

    Important: After modifying environment variables in the Vercel console, you must perform a redeployment for the changes to take effect.

    pnpm run vercel:syncenv
  3. Create custom shortcut commands

    master

    You can simplify long commands into single-word shortcuts using environment variables. Use the pattern CUSTOM_COMMAND_XXX where XXX is your desired command name. The value should be the full command string you want to execute.

    Examples:

    • To create /azure which runs /setenvs {"AI_PROVIDER": "azure"}, set CUSTOM_COMMAND_azure to /setenvs {"AI_PROVIDER": "azure"}.
    • To create /gpt4 which sets the provider to OpenAI and the model to GPT-4, set CUSTOM_COMMAND_gpt4 to /setenvs {"AI_PROVIDER": "openai", "OPENAI_CHAT_MODEL": "gpt-4"}.

    If using a TOML configuration file, use the following format:

    CUSTOM_COMMAND_azure= '/setenvs {"AI_PROVIDER": "azure"}'
    CUSTOM_COMMAND_gpt4 = '/setenvs {"AI_PROVIDER": "openai", "OPENAI_CHAT_MODEL": "gpt-4"}'
    CUSTOM_COMMAND_azure= '/setenvs {"AI_PROVIDER": "azure"}'
    CUSTOM_COMMAND_workers = '/setenvs {"AI_PROVIDER": "workers"}'
    CUSTOM_COMMAND_gpt3 = '/setenvs {"AI_PROVIDER": "openai", "OPENAI_CHAT_MODEL": "gpt-3.5-turbo"}'
    CUSTOM_COMMAND_gpt4 = '/setenvs {"AI_PROVIDER": "openai", "OPENAI_CHAT_MODEL": "gpt-4"}'
    CUSTOM_COMMAND_cn2en = '/setenvs {"SYSTEM_INIT_MESSAGE": "You are a translator. Please translate everything I say below into English."}'
  4. Automate repository synchronization with GitHub Actions

    master

    Because forked repositories do not automatically sync with the upstream repository, you must manually sync them to trigger deployments. To automate this synchronization, create a file at .github/workflows/sync.yml in your repository and use the following configuration.

    Note: This implementation is provided for reference only and has not been tested.

    name: Sync
    on:
      schedule:
        - cron: '0 0 * * *'
    jobs:
        sync:
            runs-on: ubuntu-latest
            steps:
            - name: Sync
                uses: repo-sync/github-sync@v2
                with:
                source_repo: 'https://github.com/TBXark/ChatGPT-Telegram-Workers'
                target_repo: 'Fill in your repository address'
                github_token: ${{ secrets.GITHUB_TOKEN }} 
                source_branch: 'master'
  5. Deploy to Vercel automatically

    master

    You can use the Vercel deployment button to automatically clone the repository and deploy it to your Vercel account. This process will prompt you to configure necessary environment variables such as UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN, and TELEGRAM_AVAILABLE_TOKENS.

    [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FTBXark%2FChatGPT-Telegram-Workers&env=UPSTASH_REDIS_REST_URL,UPSTASH_REDIS_REST_TOKEN,TELEGRAM_AVAILABLE_TOKENS&project-name=chatgpt-telegram-workers&repository-name=ChatGPT-Telegram-Workers&demo-title=ChatGPT-Telegram-Workers&demo-description=Deploy%20your%20own%20Telegram%20ChatGPT%20bot%20on%20Cloudflare%20Workers%20with%20ease.&demo-url=https%3A%2F%2Fchatgpt-telegram-workers.vercel.app)
  6. Configure GitHub Action Secrets for Automated Deployment

    master

    To enable the automated deployment workflow, you must add specific secrets to your forked repository's GitHub settings and enable Actions.

    1. Add Secrets

    Navigate to your repository's Settings -> Secrets and add the following:

    Secret NameDescription
    CF_API_TOKENYour Cloudflare API Token created in the previous step.
    WRANGLER_TOMLThe complete content of your wrangler.toml file. You can use wrangler-example.toml as a reference.
    CF_WORKERS_DOMAIN(Optional) Your Cloudflare Workers route (e.g., your-subdomain.workers.dev, excluding https://).

    2. Enable Actions

    Navigate to Settings -> Actions in your GitHub repository and ensure Actions are enabled.

  7. Create a Cloudflare API Token for Workers

    master

    To enable automated deployment via GitHub Actions, you must create a Cloudflare API Token with specific permissions:

    1. Log in to your Cloudflare account and navigate to My Profile.
    2. Select API Tokens from the left menu.
    3. Click Create Token.
    4. Select the Edit Cloudflare Workers template.
    5. Under Zone Resources, select the appropriate zone.
    6. Under Account Resources, select the appropriate account.
    7. Click Create Token.

    Note: Keep this token secure and do not share it. It is required for the GitHub Action to deploy your workers.

  8. Build and run with Docker

    master

    You can deploy the project using Docker by either building a local image or pulling the official image from GitHub Container Registry (GHCR).

    Building a local image

    Use docker build or the provided pnpm script to create an image.

    Running a container

    When running the container, you must map the configuration files from your host to the container and expose port 8787.

    Note: If using the Docker Hub/GHCR image, ensure you use the correct image name ghcr.io/tbxark/chatgpt-telegram-workers:latest.

    # 1. Build image
    docker build -t chatgpt-telegram-workers:latest .
    # OR
    pnpm run build:docker
    
    # 2. Run container
    docker run -d -p 8787:8787 -v $(pwd)/config.json:/app/config.json:ro -v $(pwd)/wrangler.toml:/app/config.toml:ro chatgpt-telegram-workers:latest

    Using GHCR image

    docker pull ghcr.io/tbxark/chatgpt-telegram-workers:latest
    docker run -d -p 8787:8787 -v $(pwd)/config.json:/app/config.json:ro -v $(pwd)/wrangler.toml:/app/config.toml:ro ghcr.io/tbxark/chatgpt-telegram-workers:latest
  9. Run the project locally using pnpm

    master

    You can run the project locally using pnpm via two methods:

    Method 1: Direct start

    pnpm install
    pnpm run start:local

    Method 2: Build and start with custom config paths Use this method to explicitly define the CONFIG_PATH and TOML_PATH environment variables.

    pnpm install
    CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml pnpm run start:dist
    pnpm install
    pnpm run start:local
  10. Deploy to Vercel automatically

    master

    You can deploy the project to Vercel using the provided deployment button. Note that the Vercel deployment implementation is currently experimental and located in /packages/app/vercel. While it allows for basic functional testing, it does not guarantee that all features will work correctly.

    [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FTBXark%2FChatGPT-Telegram-Workers&env=UPSTASH_REDIS_REST_URL,UPSTASH_REDIS_REST_TOKEN,TELEGRAM_AVAILABLE_TOKENS&project-name=chatgpt-telegram-workers&repository-name=ChatGPT-Telegram-Workers&demo-title=ChatGPT-Telegram-Workers&demo-description=Deploy%20your%20own%20Telegram%20ChatGPT%20bot%20on%20Cloudflare%20Workers%20with%20ease.&demo-url=https%3A%2F%2Fchatgpt-telegram-workers.vercel.app)