tbdavid2019 / Telegram-bot-Workers

cloudflare 的 worker 可以執行

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

本專案來自 fork https://github.com/TBXark/ChatGPT-Telegram-Workers

新增字典,股市等功能
image

接下來會在把 whois , ip geo , weather, DuckDuckGo search 等常用功能掛上去

Deployment Process

Video Tutorial

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 worker.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.
  6. 還有許多變數可以自行設定
image

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.
  2. 或者點擊這個 image

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.

About

cloudflare 的 worker 可以執行


Languages

Language:JavaScript 100.0%