Portfolio

Engineering notes

A haze and rain bot on Telegram that costs me nothing to run

How SkyBrief sends each user a weather and air-quality report at their own local time using one Cloudflare Workers cron job, a small database and a backup data source, all on the free plan.

By Vincent Teo · Updated

Haze season, then rain season

If you were in the Klang Valley in September and October 2026, you remember the haze. On 18 September Johan Setia hit an API of 193 and parts of KL were in the 160s. The air did not properly clear until late October. Then the year-end rain arrived, right on schedule.

Every morning I was opening one app for the weather, another for the air quality, and sometimes a news site to see if there was a warning. I wanted one message, before I leave the house, that tells me whether to bring a mask, an umbrella, or both.

So I built SkyBrief, a Telegram bot that sends exactly that.

From a script for me to a bot for anyone

The first version was a Python script. A scheduled GitHub Action ran it once a day and it sent the report to me, and only me.

It worked, but I wanted two things it could not do: let other people use it with their own city and their own time, and answer when someone types a command. I had also never touched Cloudflare Workers and wanted an excuse to try a proper cron job there. So I rewrote the whole thing in TypeScript.

One alarm clock for everyone

Here is the problem. One user wants the report at 8:30am in Kuala Lumpur. Another wants 7am in a different timezone. You cannot create a separate scheduled job per person on a free plan.

The answer is a single job that runs every minute. Each time it wakes up it asks one question: whose local time has just reached the time they chose? Those people get their report. Everyone else waits for a later minute.

A few details make this hold up in real life. Before sending, the bot marks in the database that today's report for that user has been claimed, so two runs can never send it twice. If the bot was down at exactly 8:30, it still delivers for up to two hours afterwards instead of silently skipping the day. And each run handles at most 8 reports, because the free plan limits how many outgoing requests one run can make. Anyone left over is served a minute later, least overdue first, so one user whose send keeps failing cannot hold up the queue.

When the weather service is down

Free data sources go down sometimes. If the main one, Open-Meteo, does not answer, SkyBrief switches to MET Norway and adds a small note at the bottom of the report saying it used the backup. I would rather tell you than pretend nothing happened.

Air quality comes from the nearest real monitoring station when there is one within 40 km with a reading under three hours old. Otherwise it falls back to a modelled estimate.

For Malaysia it also shows official MetMalaysia warnings. That feed does not include coordinates, so warnings are matched by state and district name. When the bot is not sure of your district it shows the warning anyway. A missed flood warning is worse than one extra message.

Still free

The whole thing runs on Cloudflare's free plan: the Worker, the small database, and a job that fires 1,440 times a day. There is no server to pay for and nothing to restart.

It answers in English, Malay and Chinese, and there are about 250 automated tests that run before every deploy. Around five people use it at the moment, mostly people I know. That is a small number, and I am fine with that. I built it for my own mornings first.

What it does not do

The name has "AI" in it, but there is no AI model inside. It is honest weather data, formatted well. Warnings only cover Malaysia, and the bot is not a replacement for official alerts. The air quality number uses the US scale, not Malaysia's official API reading, so it will not match the news exactly. And because the data is hourly, "rain soon" means within an hour or two, not in ten minutes.

The idea and the backend logic are mine. I used an AI assistant to make it sturdier: proper fallbacks, fewer bugs, and checking that every endpoint behaves.

Try it on Telegram, or read the code on GitHub.

Analytics cookies

I'd like to use Google Analytics to see which pages are useful. It sets cookies and is off unless you accept. Privacy policy