For the Python implementation, please refer to Cloudflare-Workers-Ai-Telegram-Bot.
A Rust-built Cloudflare Workers AI Bot with support for context preservation.
Engages in conversations with users by invoking the Workers AI REST API.
Uses Workers KV to store context information for users.
- Context Preservation Implemented
- Proxy Support (leveraging environment variables supported by reqwest)
- User/Group ID Authentication
For additional features, please submit an issue or a pull request.
Create a new bot and obtain your bot ID along with user or group IDs. Detailed steps are not covered here.
Acquire your Account ID and corresponding API Token (a Global API Token can be used for simplicity).
Set up a Workers KV namespace for key-value storage and note its Namespace ID.
Also, establish an AI Gateway and retain its name.
First, download the configuration template:
wget https://raw.githubusercontent.com/GenshinMinecraft/Rust-Cloudflare-Workers-Ai-Telegram-Bot/main/config.yaml.exp -O config.yaml
Then, edit it with your preferred text editor. Below are explanations for each configuration item:
-
telegram
: Telegram-related configurationsbot_token
: (Required) Telegram Bot Tokenadmin_id
: (Optional) The admin of this Bot in Telegramusers_id
: (Optional) List of authorized users/groups; if specified, only these will have access, otherwise, it's open for all.
-
cloudflare
: Cloudflare-related configurations-
account_id
: (Required) Cloudflare Account ID, found in the Dashboard URL -
api_token
: (Required) Cloudflare Account API Token; a Global API Token can be used for convenience -
kv
: Workers KV configurationsnamespace_id
: (Required) Workers KV Namespace ID, located in its detail interface
-
ai_gateway
: AI Gateway configurationsname
: (Required) Name of the Cloudflare AI Gateway, set during creation
-
workers_ai
: Workers AI configurationsmodel
: (Optional) Model configuration; refer to Cloudflare Docs for all modelsprompt
: (Optional) Initial prompt for all users
-
- Cloudflare: Kudos to the big daddy.
- Teloxide: The primary Bot framework.
This project is licensed under the Do What the Fuck You Want to Public License (WTFPL).
So, you can do whatever the hell you want with this project (Do What the Fuck You Want).