Storage, timers and HTTP
These are host services. Each needs a capability in the manifest
that the owner granted; without it the call fails with NOT_GRANTED.
Storage (storage_bytes)
Section titled “Storage (storage_bytes)”A private key-value store per bot, kept on the host in its own database (never the community’s) and limited to the granted bytes.
bot.storage.setJSON('counter', 42);const n = bot.storage.getJSON<number>('counter'); // number | nullconst keys = bot.storage.keys('user:', { limit: 100 });bot.storage.delete('counter');use zaun_bot::storage;
storage::set("counter", &42u32.to_be_bytes())?;let bytes = storage::get("counter")?; // Option<Vec<u8>>let keys = storage::list_keys("user:", None, 100)?;storage::delete("counter")?;QUOTA_EXCEEDED means the grant is used up. Data survives restarts and updates, moves with the
community’s export, and is deleted when the bot is removed.
Timers (timers)
Section titled “Timers (timers)”const id = bot.timers.after(60_000, 'reminder:42'); // once, in 60 sconst tick = bot.timers.every(3_600_000, 'hourly'); // repeating, at least every secondbot.timers.cancel(id);bot.on('timer', ({ id, tag }) => bot.log.info('timer', id, tag));setTimeout and setInterval never fire in a bot: nothing runs between calls. Use these timers.
use zaun_bot::timers;
let id = timers::after(60_000, "reminder:42")?; // once, in 60 slet tick = timers::every(3_600_000, "hourly")?; // repeating, at least every secondtimers::cancel(id);Bot::on_timer(id, tag) runs when one fires.
Timers don’t survive a restart: store what matters and arm timers again when the bot starts (in
init/ready in TypeScript, in commands() in Rust).
HTTP (network)
Section titled “HTTP (network)”const res = bot.http.fetch('https://api.open-meteo.com/v1/forecast?latitude=30&longitude=31', { timeoutMs: 5_000 });const forecast = res.json<{ current?: unknown }>(); // HttpError (kind 'not-granted', …) when refusedThere is no global fetch in a bot; this is the only way out.
use zaun_bot::http::{fetch, Request};
let res = fetch(&Request { method: "GET".into(), url: "https://api.open-meteo.com/v1/forecast?latitude=30&longitude=31".into(), headers: vec![], body: None, timeout_ms: Some(5_000),})?;- Only
https://URLs, to hosts in both the bot’s grant and the operator’s ceiling. - The host resolves the name and refuses loopback, private, link-local and reserved addresses, so a bot can’t reach the host’s own network.
- Requests leave from the host: the remote server learns the host’s IP address, never a member’s. Owners see the list of hosts on the bot card before granting it.
- Responses are limited in size (4 MiB) and time.
- Bots have no sockets: this is the only way out.