diff --git a/README.md b/README.md index 88be5de..1d17ebc 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ The worker forwards `text` to Telegram as-is (no prepended metadata). For reques ### For AI agents / Claude Code routines +Machine-readable usage spec: [`llms.txt`](llms.txt), served at `GET https://miti-telegram.miti99.workers.dev/llms.txt`. It is the only GET route; every other GET returns 405, so no crawler or link preview can trigger a message. + Read this section first, do not probe. - **One POST per intended message.** Do not send a `"test"` payload to verify the endpoint — every successful POST forwards to Telegram, so probes spam the inbox. diff --git a/index.js b/index.js index c84e7c0..e732dc6 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +import LLMS_TXT from './llms.txt'; + export default { async fetch(request, env, ctx) { // Handle CORS preflight requests @@ -6,13 +8,29 @@ export default { status: 204, headers: { 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'POST, OPTIONS', + 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type', 'Access-Control-Max-Age': '86400', }, }); } + // Usage spec for AI agents. Read-only: GET never forwards to Telegram, + // so crawlers and link previewers cannot trigger a message. + if (request.method === 'GET' || request.method === 'HEAD') { + const { pathname } = new URL(request.url); + + if (pathname === '/llms.txt') { + return new Response(request.method === 'HEAD' ? null : LLMS_TXT, { + headers: { + 'Content-Type': 'text/plain; charset=utf-8', + 'Cache-Control': 'public, max-age=3600', + 'Access-Control-Allow-Origin': '*', + }, + }); + } + } + if (request.method !== 'POST') { return new Response('Method not allowed', { status: 405, diff --git a/llms.txt b/llms.txt new file mode 100644 index 0000000..f8d16a1 --- /dev/null +++ b/llms.txt @@ -0,0 +1,20 @@ +# miti-telegram + +> Cloudflare Worker that forwards a text message to Miti's Telegram inbox. Messages are sent with POST; there is no GET send endpoint. + +Send a message: + +``` +POST https://miti-telegram.miti99.workers.dev/ +Content-Type: application/json + +{"text": ""} +``` + +`application/x-www-form-urlencoded` with `text=` is also accepted. + +Responses: `{"success":true}` on success. `400` — missing `text`, or unsupported `Content-Type`. `405` — any method other than POST or OPTIONS; GET reaches only `/llms.txt` and cannot send. `500` — worker misconfiguration, not caller-fixable. + +## Optional + +- [Full rules for agents](https://github.com/tiennm99/miti-telegram#for-ai-agents--claude-code-routines): one POST per intended message, never probe the endpoint, never retry on 2xx.