@codebam/cf-workers-telegram-bot 11.5.0 → 11.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -23
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -19,39 +19,99 @@ CF Workers Telegram Bot
|
|
|
19
19
|
|
|
20
20
|

|
|
21
21
|
|
|
22
|
+
A lightweight, type-safe Telegram Bot framework for Cloudflare Workers.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
22
26
|
```sh
|
|
23
|
-
npm
|
|
27
|
+
npm install @codebam/cf-workers-telegram-bot
|
|
24
28
|
```
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import TelegramBot, { TelegramExecutionContext } from '@codebam/cf-workers-telegram-bot';
|
|
34
|
+
|
|
35
|
+
export interface Env {
|
|
36
|
+
SECRET_TELEGRAM_API_TOKEN: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
41
|
+
const bot = new TelegramBot(env.SECRET_TELEGRAM_API_TOKEN);
|
|
42
|
+
|
|
43
|
+
await bot
|
|
44
|
+
.command('start', async (ctx) => {
|
|
45
|
+
await ctx.reply('Hello! I am running on Cloudflare Workers.');
|
|
46
|
+
})
|
|
47
|
+
.onMessage(async (ctx) => {
|
|
48
|
+
await ctx.reply(`You said: ${ctx.text}`);
|
|
49
|
+
})
|
|
50
|
+
.handle(request);
|
|
51
|
+
|
|
52
|
+
return new Response('ok');
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
```
|
|
27
56
|
|
|
28
|
-
|
|
57
|
+
## Features
|
|
29
58
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
- Open this url in your browser to set your webhook `https://your-worker.username.workers.dev/SECRET_TELEGRAM_API_TOKEN?command=set`
|
|
59
|
+
- **Type-safe**: Built with TypeScript for a better developer experience.
|
|
60
|
+
- **Middleware support**: Run logic before your handlers.
|
|
61
|
+
- **Built-in Webhook Management**: Easily set your webhook with a simple URL.
|
|
62
|
+
- **Lightweight**: Zero dependencies (other than type definitions).
|
|
35
63
|
|
|
36
|
-
|
|
64
|
+
## Using the Consumer Template
|
|
37
65
|
|
|
38
|
-
|
|
66
|
+
The `consumer` directory in this repository serves as a template for new projects. It is included as a git submodule.
|
|
39
67
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
68
|
+
1. **Clone the repository with submodules**:
|
|
69
|
+
```sh
|
|
70
|
+
git clone --recursive https://github.com/codebam/cf-workers-telegram-bot.git
|
|
71
|
+
```
|
|
72
|
+
*Or, if you've already cloned it:*
|
|
73
|
+
```sh
|
|
74
|
+
git submodule update --init --recursive
|
|
75
|
+
```
|
|
43
76
|
|
|
44
|
-
|
|
77
|
+
2. **Copy the consumer directory**:
|
|
78
|
+
```sh
|
|
79
|
+
cp -r consumer my-new-bot
|
|
80
|
+
cd my-new-bot
|
|
81
|
+
npm install
|
|
82
|
+
```
|
|
45
83
|
|
|
46
|
-
|
|
47
|
-
|
|
84
|
+
3. **Configure your bot**:
|
|
85
|
+
Update `wrangler.toml` with your worker name.
|
|
86
|
+
|
|
87
|
+
4. **Set your Telegram Token**:
|
|
88
|
+
Get a token from [@BotFather](https://t.me/BotFather) and add it to your worker:
|
|
89
|
+
```sh
|
|
90
|
+
npx wrangler secret put SECRET_TELEGRAM_API_TOKEN
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
5. **Deploy**:
|
|
94
|
+
```sh
|
|
95
|
+
npm run deploy
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
6. **Set Webhook**:
|
|
99
|
+
Visit the following URL in your browser to register your worker with Telegram:
|
|
100
|
+
`https://<your-worker>.<your-subdomain>.workers.dev/<SECRET_TELEGRAM_API_TOKEN>?command=set`
|
|
101
|
+
|
|
102
|
+
## Deployment
|
|
103
|
+
|
|
104
|
+
### Manual Deployment
|
|
105
|
+
Use [Wrangler](https://developers.cloudflare.com/workers/wrangler/) to deploy:
|
|
106
|
+
```sh
|
|
107
|
+
npx wrangler deploy
|
|
108
|
+
```
|
|
48
109
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- Name: CLOUDFLARE_ACCOUNT_ID (should be added automatically)
|
|
110
|
+
### GitHub Actions
|
|
111
|
+
To automate deployments, use the [Wrangler Action](https://github.com/cloudflare/wrangler-action). Add `CLOUDFLARE_API_TOKEN` and `SECRET_TELEGRAM_API_TOKEN` to your repository secrets.
|
|
52
112
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
```
|
|
113
|
+
## API Documentation
|
|
114
|
+
Detailed API documentation is available at [cf-workers-telegram-bot.codebam.ca](https://cf-workers-telegram-bot.codebam.ca).
|
|
56
115
|
|
|
57
|
-
|
|
116
|
+
## License
|
|
117
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebam/cf-workers-telegram-bot",
|
|
3
|
-
"version": "11.5.
|
|
3
|
+
"version": "11.5.2",
|
|
4
4
|
"description": "serverless telegram bot on cf workers",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"module": "./dist/main.js",
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
"url": "https://github.com/codebam/cf-workers-telegram-bot.git"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@cloudflare/workers-types": "^4.
|
|
39
|
+
"@cloudflare/workers-types": "^4.20260511.1",
|
|
40
40
|
"@eslint/js": "^10.0.1",
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^8.59.
|
|
42
|
-
"@typescript-eslint/parser": "^8.59.
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^8.59.3",
|
|
42
|
+
"@typescript-eslint/parser": "^8.59.3",
|
|
43
43
|
"eslint": "^10.3.0",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
45
|
"globals": "^17.6.0",
|
|
46
|
-
"npm-check-updates": "^22.
|
|
46
|
+
"npm-check-updates": "^22.2.0",
|
|
47
47
|
"prettier": "^3.8.3",
|
|
48
48
|
"typedoc": "^0.28.19",
|
|
49
49
|
"typedoc-plugin-extras": "^4.0.1",
|
|
50
50
|
"typescript": "^6.0.3",
|
|
51
|
-
"typescript-eslint": "^8.59.
|
|
52
|
-
"vitest": "^4.1.
|
|
53
|
-
"wrangler": "^4.90.
|
|
51
|
+
"typescript-eslint": "^8.59.3",
|
|
52
|
+
"vitest": "^4.1.6",
|
|
53
|
+
"wrangler": "^4.90.1"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@eslint/eslintrc": "^3.3.5"
|