Skip to content

Commit d55a908

Browse files
codebamclaude
andcommitted
chore: move back to GitHub, plain wrangler, GitHub Actions CI
Repository - Submodules point at GitHub (codebam/telegram-bot, codebam/tux-robot-webapp) instead of Codeberg; the Codeberg remotes are kept locally as `codeberg`. - README drops the "moved to Codeberg" banner and documents the current deployment flow, the new secrets, and the CI triggers. Tooling - Replace wrangler-native-bun with plain wrangler everywhere (root, bot, webapp, Makefile). Scripts invoke it through npx so they work under both bun and npm regardless of workspace hoisting. - Makefile gains deploy-bot / deploy-webapp targets. CI - Replace .woodpecker/deploy.yml with .github/workflows/deploy.yml, keeping the same triggers: push to master deploys the bot to dev, bot-v* tags deploy production, webapp-v* tags deploy Pages. Adds a typecheck job that gates all three. Docs - The cf-workers-telegram-bot-docs Pages project builds this repo with `npm run docs`, but no such script existed, so every build failed. Add scripts/build-docs.mjs, which renders a self-contained static site. Model names and prices are read out of packages/shared at build time so the published pricing table cannot drift from what the bot charges. Shared - Telegram auth proofs are now bounded: verifyTelegramWebAppData and verifyTelegramLogin check auth_date (with clock-skew allowance) and compare hashes in constant time. A leaked proof previously worked forever. - Add verifyTelegramAuth, which returns the authenticated user id, so callers cannot accidentally trust a client-supplied one. - getBalance no longer writes a default balance back on read — that read-modify-write was itself a race. New users get 200 credits, matching what /start and the web app have always advertised (the code granted 100). - Centralise pricing constants and add modelConfigById. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GaLeuxVikb3iH2Etw2tHe7
1 parent 6dce2fe commit d55a908

12 files changed

Lines changed: 918 additions & 302 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: deploy
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
tags:
7+
- 'bot-v*'
8+
- 'webapp-v*'
9+
pull_request:
10+
branches: [master, main]
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
env:
17+
WRANGLER_SEND_METRICS: 'false'
18+
19+
jobs:
20+
check:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
submodules: recursive
26+
- uses: oven-sh/setup-bun@v2
27+
with:
28+
bun-version: latest
29+
- run: bun install --frozen-lockfile
30+
- name: Typecheck shared
31+
run: bun run --cwd packages/shared check
32+
- name: Typecheck bot
33+
run: bun run --cwd bot check
34+
35+
deploy_bot_dev:
36+
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/')
37+
needs: check
38+
runs-on: ubuntu-latest
39+
environment: dev
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
submodules: recursive
44+
- uses: actions/setup-node@v4
45+
with:
46+
node-version: 22
47+
- run: npm install
48+
- name: Deploy bot (dev)
49+
working-directory: bot
50+
env:
51+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
52+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
53+
SECRET_TELEGRAM_API_TOKEN: ${{ secrets.SECRET_TELEGRAM_API_TOKEN_DEV }}
54+
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
55+
run: |
56+
npx wrangler deploy \
57+
--containers-rollout=none \
58+
--env dev \
59+
--var SECRET_TELEGRAM_API_TOKEN:"$SECRET_TELEGRAM_API_TOKEN" \
60+
--var TAVILY_API_KEY:"$TAVILY_API_KEY" \
61+
--var COMMIT_SHA:"$GITHUB_SHA"
62+
63+
deploy_bot_prod:
64+
if: startsWith(github.ref, 'refs/tags/bot-v')
65+
needs: check
66+
runs-on: ubuntu-latest
67+
environment: production
68+
steps:
69+
- uses: actions/checkout@v4
70+
with:
71+
submodules: recursive
72+
- uses: actions/setup-node@v4
73+
with:
74+
node-version: 22
75+
- run: npm install
76+
- name: Deploy bot (production)
77+
working-directory: bot
78+
env:
79+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
80+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
81+
SECRET_TELEGRAM_API_TOKEN: ${{ secrets.SECRET_TELEGRAM_API_TOKEN }}
82+
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
83+
run: |
84+
npx wrangler deploy \
85+
--containers-rollout=none \
86+
--env production \
87+
--var SECRET_TELEGRAM_API_TOKEN:"$SECRET_TELEGRAM_API_TOKEN" \
88+
--var TAVILY_API_KEY:"$TAVILY_API_KEY" \
89+
--var COMMIT_SHA:"$GITHUB_SHA"
90+
91+
deploy_webapp_prod:
92+
if: startsWith(github.ref, 'refs/tags/webapp-v')
93+
needs: check
94+
runs-on: ubuntu-latest
95+
environment: production
96+
steps:
97+
- uses: actions/checkout@v4
98+
with:
99+
submodules: recursive
100+
- uses: actions/setup-node@v4
101+
with:
102+
node-version: 22
103+
- run: npm install
104+
- name: Build webapp
105+
working-directory: webapp
106+
run: npm run build
107+
- name: Deploy webapp
108+
working-directory: webapp
109+
env:
110+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
111+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
112+
run: npx wrangler pages deploy .svelte-kit/cloudflare --project-name telegram-webapp --branch main

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "webapp"]
22
path = webapp
3-
url = https://codeberg.org/codebam/telegram-webapp.git
3+
url = https://github.com/codebam/tux-robot-webapp.git
44
[submodule "bot"]
55
path = bot
6-
url = https://codeberg.org/codebam/telegram-bot.git
6+
url = https://github.com/codebam/telegram-bot.git

.woodpecker/deploy.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build clean deploy
1+
.PHONY: build clean deploy deploy-bot deploy-webapp
22

33
build:
44
bun run build
@@ -7,6 +7,11 @@ clean:
77
rm -rf webapp/.svelte-kit
88
rm -rf bot/dist
99

10-
deploy:
10+
deploy-bot:
1111
bun run --cwd bot deploy
12-
bun run --cwd webapp build && bunx wrangler-native-bun pages deploy .svelte-kit/cloudflare
12+
13+
deploy-webapp:
14+
bun run --cwd webapp build
15+
bun run --cwd webapp deploy
16+
17+
deploy: deploy-bot deploy-webapp

README.md

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@ CF Workers Telegram Bot
55
<br/>
66
</h3>
77

8-
> 🚀 **This project has moved to [Codeberg](https://codeberg.org/codebam/cf-workers-telegram-bot)**
9-
108
A monorepo containing a Telegram Bot and a Svelte web application, both running on Cloudflare Workers and Pages.
119

1210
## Structure
1311

1412
This is a monorepo containing:
15-
- `bot`: The main Telegram Bot built with [grammY](https://grammy.dev/)
16-
- `webapp`: A Svelte 5 web application for interacting with the bot
1713

18-
## Deployment
14+
- `bot`: The main Telegram Bot built with [grammY](https://grammy.dev/)[codebam/telegram-bot](https://github.com/codebam/telegram-bot) (submodule)
15+
- `webapp`: A Svelte 5 web application for interacting with the bot — [codebam/telegram-webapp](https://github.com/codebam/telegram-webapp) (submodule)
16+
- `packages/shared`: Types and helpers shared by both
1917

20-
### Deploying the Bot
18+
## Setup
2119

2220
1. **Clone the repository with submodules**:
2321

2422
```sh
2523
git clone --recursive https://github.com/codebam/cf-workers-telegram-bot.git
24+
cd cf-workers-telegram-bot
2625
```
2726

2827
2. **Install dependencies**:
@@ -31,57 +30,94 @@ This is a monorepo containing:
3130
bun install
3231
```
3332

34-
3. **Configure the bot**:
35-
Navigate to the `bot` directory and update `wrangler.toml` with your desired worker name and bindings.
33+
3. **Set up Git hooks** (runs the full build on every commit):
3634

37-
4. **Set your Telegram Token**:
38-
Get a token from [@BotFather](https://t.me/BotFather) and add it to your worker:
35+
```sh
36+
./setup_hooks.sh
37+
```
38+
39+
4. **Authenticate wrangler**:
40+
41+
```sh
42+
bunx wrangler login
43+
```
44+
45+
## Deployment
46+
47+
### Bot
48+
49+
1. **Configure**: edit `bot/wrangler.toml` with your worker name and bindings. Note that
50+
`[env.dev]` and `[env.production]` must point at **different** KV namespaces and
51+
Vectorize indexes.
52+
53+
2. **Set secrets**: get a token from [@BotFather](https://t.me/BotFather), then:
3954

4055
```sh
4156
cd bot
42-
bunx wrangler-native-bun secret put SECRET_TELEGRAM_API_TOKEN
57+
bunx wrangler secret put SECRET_TELEGRAM_API_TOKEN --env production
58+
bunx wrangler secret put SECRET_TELEGRAM_WEBHOOK --env production # webhook shared secret
59+
bunx wrangler secret put SECRET_ADMIN_TOKEN --env production # guards GET /?command=set
60+
bunx wrangler secret put TAVILY_API_KEY --env production # optional, web search
4361
```
4462

45-
5. **Deploy**:
63+
Repeat with `--env dev` for the development worker.
64+
65+
3. **Deploy**:
4666

4767
```sh
48-
bun run deploy
68+
make deploy-bot
69+
# or: cd bot && bunx wrangler deploy --env production
4970
```
5071

51-
For more information on deploying grammY bots, see the [grammY deployment documentation](https://grammy.dev/guide/deployment).
72+
4. **Register the webhook** (once per deploy target):
5273

53-
### Deploying the Web App
74+
```sh
75+
curl "https://<your-worker-host>/?command=set&token=<SECRET_ADMIN_TOKEN>"
76+
```
5477

55-
The web app is a SvelteKit project designed to be deployed to Cloudflare Pages.
78+
For more on deploying grammY bots, see the [grammY deployment documentation](https://grammy.dev/guide/deployment).
79+
80+
### Web App
81+
82+
The web app is a SvelteKit project deployed to Cloudflare Pages.
5683

5784
```sh
58-
cd webapp
59-
bun install
60-
bun run build
61-
bunx wrangler-native-bun pages deploy .svelte-kit/cloudflare
85+
make deploy-webapp
86+
# or: cd webapp && bun run build && bunx wrangler pages deploy .svelte-kit/cloudflare
6287
```
6388

64-
## Development
89+
### Everything
90+
91+
```sh
92+
make deploy
93+
```
6594

66-
You can use the root `Makefile` to run common tasks across all projects:
95+
## Development
6796

6897
```sh
6998
make build # Build all projects
7099
make clean # Clean build artifacts
100+
101+
bun run --cwd bot start # local worker via wrangler dev
102+
bun run --cwd webapp dev # local webapp via vite
71103
```
72104

73-
### Setup
105+
## Continuous Deployment
74106

75-
1. **Install dependencies**:
76-
```sh
77-
bun install
78-
```
107+
CI runs on GitHub Actions (`.github/workflows/deploy.yml`):
79108

80-
2. **Set up Git hooks**:
81-
This project uses custom Git hooks for quality control. Run the following script to enable them:
82-
```sh
83-
./setup_hooks.sh
84-
```
109+
| Trigger | Action |
110+
| ---------------- | ----------------------------------- |
111+
| push to `master` | deploy bot to the `dev` environment |
112+
| tag `bot-v*` | deploy bot to `production` |
113+
| tag `webapp-v*` | deploy webapp to Cloudflare Pages |
114+
115+
Required repository secrets:
116+
117+
- `CLOUDFLARE_API_TOKEN`
118+
- `CLOUDFLARE_ACCOUNT_ID`
119+
- `SECRET_TELEGRAM_API_TOKEN`, `SECRET_TELEGRAM_API_TOKEN_DEV`
120+
- `TAVILY_API_KEY`
85121

86122
## License
87123

0 commit comments

Comments
 (0)