Skip to content

Commit 9e034c1

Browse files
committed
feat: daily scheduled /morning push (cron)
1 parent 152ac65 commit 9e034c1

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

cloudflare/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,4 +1921,24 @@ export default {
19211921

19221922
return new Response("OK", { status: 200 });
19231923
},
1924+
1925+
async scheduled(controller: ScheduledController, env: Env, ctx: ExecutionContext): Promise<void> {
1926+
const token = getToken(env);
1927+
if (!token) return;
1928+
const allowed = parseAllowedChatIds(env);
1929+
if (allowed.length === 0) return;
1930+
1931+
ctx.waitUntil(
1932+
(async () => {
1933+
for (const chatId of allowed) {
1934+
try {
1935+
const body = await handle(chatId, "/morning", env);
1936+
await sendMessage(token, chatId, body, { replyMarkup: buildHelpMenu() });
1937+
} catch {
1938+
// ignore
1939+
}
1940+
}
1941+
})(),
1942+
);
1943+
},
19241944
};

cloudflare/wrangler.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
name = "gstack-telegram-webhook"
22
main = "src/index.ts"
33
compatibility_date = "2026-03-28"
4+
5+
[triggers]
6+
crons = ["0 1 * * *"]

0 commit comments

Comments
 (0)