This commit is contained in:
Kyle Fang
2023-05-01 11:16:32 +08:00
parent 26b6852e6b
commit 10e3fe17ce
5 changed files with 1873 additions and 4460 deletions

1
.tool-versions Normal file
View File

@@ -0,0 +1 @@
pnpm 8.3.1

4450
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,5 +12,10 @@
"start": "wrangler dev",
"deploy": "wrangler publish",
"test": "vitest"
},
"dependencies": {
"@cfworker/web": "^1.12.5",
"cfworker-middleware-telegraf": "^2.0.2",
"telegraf": "^4.12.2"
}
}

1850
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -7,10 +7,13 @@
*
* Learn more at https://developers.cloudflare.com/workers/
*/
import {Telegraf} from "telegraf";
import {Application, Router} from "@cfworker/web";
import createTelegrafMiddleware from 'cfworker-middleware-telegraf'
export interface Env {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
TG_GROUPS: KVNamespace;
//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
@@ -22,12 +25,16 @@ export interface Env {
// MY_SERVICE: Fetcher;
}
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
return new Response("Hello World!");
},
};
declare global {
const BOT_TOKEN: string
const SECRET_PATH: string
}
const bot = new Telegraf(BOT_TOKEN);
// Your code here, but do not `bot.launch()`
// Do not forget to set environment variables BOT_TOKEN and SECRET_PATH on your worker
const router = new Router();
router.post(`/${SECRET_PATH}`, createTelegrafMiddleware(bot));
new Application().use(router.middleware).listen();