A message on your phone, and the secrets that send it
By the end of this lesson you will have the scheduled job sending a real message to Telegram or to your inbox, with the EODHD key and the delivery credentials stored only as repository secrets: not in the code, not in a log, not in your agent's context.
What you will see: on your phone, a message from your own bot listing the rules that fired, each with symbol, close, bar date and threshold, ending End-of-day data from EODHD APIs. In the run log, delivered: telegram, 1 message and no token anywhere.
The idea: delivery is the part with secrets
An alert printed to a terminal nobody watches is the cockpit again. This lesson adds a way to reach you, and two secrets come with it.
Telegram lands on your phone. Message @BotFather, send /newbot, choose a name and a username, and it returns a token. A bot cannot write first: you message it, and Telegram keeps that update for at most 24 hours. Calls look like https://api.telegram.org/bot<token>/METHOD; open getUpdates once in a browser and your message carries a chat object whose id is your chat id. Sending is sendMessage with chat_id and text, up to 4096 characters.
Email through Resend is one POST to https://api.resend.com/emails with a bearer key and from, to, subject and a body. Until you verify a domain, its test sender onboarding@resend.dev reaches only your own account's address, which is enough here. It also takes the Idempotency-Key header lesson 4 wants.
rules -> evaluate -> message -> deliver(), chosen by ALERT_DELIVERY
telegram TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID
email RESEND_API_KEY, ALERT_EMAIL_TO
Unset, ALERT_DELIVERY means console: the message prints to the terminal, which is what your local runs keep doing. If it says telegram and the token is missing, the job fails at the start, naming the variable. Falling back to the log is the mute alert: a green run whose message reached nobody.
Three rules for the secrets
You type them into the repository's secrets: Settings, Secrets and variables, Actions, or gh secret set NAME, which asks for the value. Use your own terminal: in Claude Code and Codex alike, a command typed after ! puts its output into the conversation. Each secret goes, as ${{ secrets.NAME }}, into the env of the one step that needs it.
They never appear in a logged URL. The Telegram token is in the path, the EODHD key in the query, which is why the starter has redactKey(). Log channel and status only.
Rotation changes a secret, not code. BotFather's /token issues a new token; a Resend key cannot be viewed again, so create one and delete the old; replace an exposed EODHD key in your account. Then gh secret set again.
Your agent. The starter's .claude/settings.json denies Claude Code's file tools any read of .env.local, and Codex has only rule 2 of AGENTS.md. Neither stops a script the agent runs: npm run alert:local loads the file on purpose. So AGENTS.md gets a rule: the agent runs the alert in mock mode only. The live run is yours.
A message to yourself is personal use. Closing prices posted to a group of a hundred people are redistribution, and that conversation starts on the licence page in this lesson's sources.
The prompt
Add delivery to the alert job. Plan first.
- src/lib/alerts/deliver.ts: deliver(message), chosen by ALERT_DELIVERY: console, the default when ALERT_DELIVERY is not set, so npm run alert and alert:local keep working as they are; telegram (TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, sendMessage as a JSON POST); email (RESEND_API_KEY, ALERT_EMAIL_TO, from onboarding@resend.dev).
- A channel that was asked for and has a missing variable exits non-zero before any fetch, naming it. Never fall back from it to console.
- One message per run listing every fired rule, nothing when nothing fired, ending "End-of-day data from EODHD APIs". Never log a URL or a header: log channel, status and message count.
- tests/alert-deliver.test.ts: a fake fetch; assert method, URL shape and body for both channels with made-up credentials, and that a missing variable fails.
- Workflow: drop EODHD_MOCK, set ALERT_DELIVERY to telegram, pass EODHD_API_KEY, TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID from secrets into the alert step's env only.
- AGENTS.md: the agent runs the alert job in mock mode only and never calls a delivery API with real credentials.
Do not ask me for a token and do not read .env.local.
What the agent should do. One module, one test file, the workflow's env block, a rule in AGENTS.md, and about ten lines in scripts/alert.ts. Reject a diff with anything shaped like a token, or a log line that prints a URL. Once this lesson is merged, the schedule is live: every weekday run spends one call per distinct symbol and sends real messages, so store the secrets before you merge, or the workflow goes red every weekday evening. Lesson 4 keeps this shape, one message per run, and changes only what goes into it.
Check it yourself
npm testpasses, with the delivery tests in it, andnpm run alert:localin mock mode, with noALERT_DELIVERYset, still prints its message to the terminal.- Run
gh secret set EODHD_API_KEY, the same forTELEGRAM_BOT_TOKENandTELEGRAM_CHAT_ID, thengh secret list: names and dates, never values. - Give one rule a threshold between the last two closes the previous run printed, so it fires on the next run. Then commit, push the branch, open a pull request and merge it:
git status # the files you expect, and no .env file and no token
git add -A
git commit -m "feat(alert): deliver by Telegram or email, secrets only from the environment"
- Run the workflow. The message arrives within minutes; the run spends one call per distinct symbol.
- Search the run's log for
api.telegram.org. It is not there. git grep -n "api.telegram.org/bot[0-9]"prints nothing.
Break it on purpose
Remove the TELEGRAM_CHAT_ID secret in the repository settings and run the workflow. It must go red, naming the variable, before spending a call. Green means the forbidden fallback is in the code. Put the secret back.
Compare with ours
git fetch upstream, then git diff upstream/ref/runs-without-you/3.
Our version, on branch ref/runs-without-you/3
const res = await fetchFn(`https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage`,
{ method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ chat_id: env.TELEGRAM_CHAT_ID, text }) });
if (!res.ok) throw new DeliveryError("telegram", res.status);
The error carries the channel and the status, never the URL, so nothing that logs it prints the token.
Try it now
Checkpoint: the alert now reaches you without you.
- The secrets are stored and the commit you made for the checks is merged:
gh secret list
git fetch origin
git log --oneline -1 origin/main -- src/lib/alerts/deliver.ts
- Keep a screenshot of the first real message: it is the artefact of this unit.
- Take the lesson check. It asks what a run should do when a credential is missing, and where a token leaks.