Total Pageviews

Monday 22 April 2024

ChatGPT-Telegram-Workers

 

Deploy your own Telegram ChatGPT bot on Cloudflare Workers with ease.

t.me/ChatGPT_Telegram_Workers
English | 中文

    Deploy your own Telegram ChatGPT bot on Cloudflare Workers with ease.

    About

    The simplest and fastest way to deploy your own ChatGPT Telegram bot. Use Cloudflare Workers, single file, copy and paste directly, no dependencies required, no need to configure local development environment, no domain name required, serverless.

    You can customize the system initialization information so that your debugged personality never disappears.

    example

    Features

    • Serverless deployment
    • Support for multiple Telegram bots
    • Support for multiple OpenAI keys
    • Support for Azure OpenAI Service
    • Support for Cloudflare AI (free)
    • Support for streaming output
    • Support for custom roles
    • Support for multiple platforms deployment

    Documentation

  • How to deploy
  • How to set up configuration
  • Automatic update
  • Support Platform

from https://github.com/TBXark/ChatGPT-Telegram-Workers 

--------------------------------------------------------------------------

Deployment Process

Video Tutorial

image

Thanks to lipeng0820 for providing this video tutorial.

Manual Deployment

Step 1. Create a Telegram Bot and Obtain a Token

image

  1. Open Telegram and send the /start command to BotFather.
  2. Send the /newbot command to BotFather and give your bot a name.
  3. Give your bot a unique username that ends with _bot.
  4. BotFather will generate a Token. Copy and save this Token. This Token is the secret key that is bound to your bot. Do not disclose it to others!
  5. Later, in the settings of Cloudflare Workers, fill in this Token in the TELEGRAM_TOKEN variable.

Step 2. Register an OpenAI Account and Create an API Key

image

  1. Open OpenAI and register an account.
  2. Click on the avatar in the upper right corner to enter the personal settings page.
  3. Click on API Keys and create a new API Key.
  4. Later, in the settings of Cloudflare Workers, fill in this API Key in the API_KEY variable.

Step 3. Deploy Workers

image

  1. Open Cloudflare Workers and register an account.
  2. Click on Create a Service in the upper right corner.
  3. Enter the newly created Workers, select Quick Edit, copy the ../dist/index.js code into the editor, and save.

Step 4. Configure Environment Variables

image

  1. Open Cloudflare Workers, click on your Workers, and click on Setting -> Variables in the upper right corner.
  2. API_KEY: Set it to your OpenAI API Key.
  3. TELEGRAM_AVAILABLE_TOKENS: Set it to your Telegram Bot Token.
  4. CHAT_WHITE_LIST: Set it to the IDs of users who are allowed to access, for example, 123456789,987654321. If you don't know your ID, use the /new command to obtain it in conversation with the bot you created.
  5. I_AM_A_GENEROUS_PERSON: If you still don't understand how to obtain the ID, you can set this value to true to turn off the whitelist function and allow everyone to access.

Step 5. Bind KV Data

  1. Click on Create a Namespace at the top right corner of Home-Workers-KV, name it whatever you want, but when binding it, set it as DATABASE.
    image
  2. Open Cloudflare Workers and click on your Workers.
  3. Click on Setting at the top right corner and choose Variables.
    image
  4. Click on Edit variables under KV Namespace Bindings.
  5. Click on Add variable.
  6. Name it DATABASE and choose the KV data you just created.

Step 6. Initialization

  1. Run https://workers_name.username.workers.dev/init to automatically bind Telegram webhook and set all commands.

Step 7. Start Chatting

image

  1. Start a new conversation by using the /new command. The chat context will be sent to ChatGPT every time.
  2. Modify user settings with the /setenv KEY=VALUE command, for example, SETENV SYSTEM_INIT_MESSAGE=Starting now is Meow, and each sentence ends with Meow.
  3. Since all historical records are carried with each conversation, it is easy to reach the 4096 token limit, so clear the history by using the /new command when necessary.

Automatic Deployment

  1. Steps one, two, and three are for manual deployment.
  2. Run mv wrangler-example.toml wrangler.toml and modify the corresponding configuration.
  3. Run npm install
  4. Run npm run deploy

from https://github.com/TBXark/ChatGPT-Telegram-Workers/blob/master/doc/en/DEPLOY.md

 

No comments:

Post a Comment