@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.
Files changed (2) hide show
  1. package/README.md +83 -23
  2. package/package.json +8 -8
package/README.md CHANGED
@@ -19,39 +19,99 @@ CF Workers Telegram Bot
19
19
 
20
20
  ![screenshot of cf-workers-telegram-bot](https://raw.githubusercontent.com/codebam/cf-workers-telegram-bot/master/assets/screenshot.png)
21
21
 
22
+ A lightweight, type-safe Telegram Bot framework for Cloudflare Workers.
23
+
24
+ ## Installation
25
+
22
26
  ```sh
23
- npm i @codebam/cf-workers-telegram-bot
27
+ npm install @codebam/cf-workers-telegram-bot
24
28
  ```
25
29
 
26
- See [cwtb-consumer](https://github.com/codebam/cwtb-consumer) for an example of what a bot might look like. Just import from `@codebam/cf-workers-telegram-bot`.
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
- See [my blog post](https://seanbehan.ca/posts/cf-workers-telegram-bot) for a more in-depth guide for how to set up a bot.
57
+ ## Features
29
58
 
30
- - `npm create cloudflare@latest`
31
- - `npx wrangler login`
32
- - `npx wrangler secret put SECRET_TELEGRAM_API_TOKEN`, set it to your telegram bot token that you got from `@BotFather`
33
- - `npx wrangler deploy`
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
- To set up GitHub actions to deploy when you push, see https://github.com/cloudflare/wrangler-action
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
- These instructions are for if you want to deploy a copy of the bot along with
41
- the library. Such as if you need extra API requests that haven't been
42
- implemented yet.
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
- [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/codebam/cf-workers-telegram-bot)
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
- - Click the deploy button
47
- - Navigate to your new **GitHub repository &gt; Settings &gt; Secrets** and add the following secrets:
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
- ```yaml
50
- - Name: CLOUDFLARE_API_TOKEN (should be added automatically)
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
- - Name: SECRET_TELEGRAM_API_TOKEN
54
- - Value: your-telegram-bot-token
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
- - Push to `master` to trigger a deploy
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.0",
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.20260510.1",
39
+ "@cloudflare/workers-types": "^4.20260511.1",
40
40
  "@eslint/js": "^10.0.1",
41
- "@typescript-eslint/eslint-plugin": "^8.59.2",
42
- "@typescript-eslint/parser": "^8.59.2",
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.1.1",
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.2",
52
- "vitest": "^4.1.5",
53
- "wrangler": "^4.90.0"
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"