mirror of
https://github.com/tiennm99/miti-telegram.git
synced 2026-10-11 03:13:41 +00:00
feat: serve llms.txt so agents can discover the send API
Adds an llmstxt.org-format usage spec at the repo root, bundled into the worker as a text module and served at GET /llms.txt. /llms.txt is the only GET route; all other GETs still return 405, so crawlers and link previews cannot trigger a Telegram message.
This commit is contained in:
1 parent
4f0aa4b384
commit
3513f8abb9
3 files changed
+41
-1
No files matched your search
@@ -18,6 +18,8 @@ The worker forwards `text` to Telegram as-is (no prepended metadata). For reques
|
|||||||
|
|
||||||
### For AI agents / Claude Code routines
|
### 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.
|
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.
|
- **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.
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import LLMS_TXT from './llms.txt';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async fetch(request, env, ctx) {
|
async fetch(request, env, ctx) {
|
||||||
// Handle CORS preflight requests
|
// Handle CORS preflight requests
|
||||||
@@ -6,13 +8,29 @@ export default {
|
|||||||
status: 204,
|
status: 204,
|
||||||
headers: {
|
headers: {
|
||||||
'Access-Control-Allow-Origin': '*',
|
'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-Allow-Headers': 'Content-Type',
|
||||||
'Access-Control-Max-Age': '86400',
|
'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') {
|
if (request.method !== 'POST') {
|
||||||
return new Response('Method not allowed', {
|
return new Response('Method not allowed', {
|
||||||
status: 405,
|
status: 405,
|
||||||
|
|||||||
@@ -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": "<your message>"}
|
||||||
|
```
|
||||||
|
|
||||||
|
`application/x-www-form-urlencoded` with `text=<your message>` 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.
|
||||||
Reference in new issue
Block a user