- Open Telegram and send the
/start
command to BotFather. - Send the
/newbot
command to BotFather and give your bot a name. - Give your bot a unique username ending with
_bot
. - BotFather will generate a token. Copy and save it. This token is the key that binds the bot to your account. Do not disclose it to others!
- Later, in the Cloudflare Workers settings, fill in the
TELEGRAM_TOKEN
variable with this token.
- Open OpenAI to register an account.
- Click on the avatar in the upper right corner to enter the personal settings page.
- Click on API Keys and create a new API Key.
- Later, in the Cloudflare Workers settings, fill in the
API_KEY
variable with this key.
- Open Cloudflare Workers to register an account.
- Click on
Create a Service
in the upper right corner. - Enter the newly created workers, select
Quick Edit
, copy the./dist/index.js
code into the editor, and save.
- Open Cloudflare Workers and click on your workers. Click on Setting -> Variables in the upper right corner.
API_KEY
: Set it to the OpenAI API Key.TELEGRAM_AVAILABLE_TOKENS
: Set it to the Telegram Bot Token.WORKERS_DOMAIN
: Set it to your Workers domain, for example,workers_name.username.workers.dev
. You can find it in thePreview
of the workers details page.CHAT_WHITE_LIST
: Set it to the ID of the users who are allowed to access, for example,123456789,987654321
. If you don't know your ID, use the/new
command in a conversation with the bot to get it.I_AM_A_GENEROUS_PERSON
: If you still don't understand how to get the ID, you can set this value totrue
to turn off the whitelist function and allow everyone to access.
- On the
Home-Workers-KV
page, clickCreate a Namespace
in the upper right corner. You can name it whatever you like, but when binding, it must be set toDATABASE
. - Open Cloudflare Workers and click on your workers.
- Click on Setting -> Variables in the upper right corner.
- Click
Edit variables
inKV Namespace Bindings
. - Click
Add variable
. - Set the name to
DATABASE
and select the KV data you just created.
- Run
https://workers_name.username.workers.dev/init
, Automatically bind telegram's webhook and set all commands.
- To start a new conversation, use the
/new
command. The chat context will then be sent to ChatGPT every time. - Use the
/setenv KEY=VALUE
command to modify user settings, such asSETENV SYSTEM_INIT_MESSAGE="Starting now, every sentence will end with 'meow'."
- Because every conversation includes all the historical records and may reach the 4096-token limit, it is recommended to clean up the history by using the
/new
command when there is nothing to discuss.
- Manual deployment steps one, two, three
- Modify the configuration file
wrangler-example.toml
towrangler.toml
npm install
npm run login
npm run deploy