Storage
A persistent key-value store for your automation scripts.
Storage is a persistent key-value store scoped to your organization. Your scripts can use it to remember data between executions.
What is it?
Each organization has its own storage — a simple key-value database where keys are strings and values are arbitrary JSON. Storage persists across all script executions, making it perfect for:
- Counters — subscriber count, command usage
- State tracking — current scene, last greeted user
- Configuration — custom responses, thresholds
- User data — points, preferences
Using storage in scripts
Inside your action code, import storage from "rawtoh":
Read a value
import { storage } from "rawtoh"
const count = await storage.get("sub_count")
// Returns the stored value, or undefined if the key doesn't existWrite a value
import { storage } from "rawtoh"
await storage.set("sub_count", 42)
await storage.set("last_user", { name: "alice", time: Date.now() })
// Values can be any JSON-serializable dataUpdate a value atomically
Two actions can run at the same time — two chat messages a few milliseconds apart, for instance. A get followed by a set would let one overwrite the other. storage.update() applies your function to the current value and writes the result only if nobody else wrote in between, retrying otherwise. It returns the value that was written.
import { storage } from "rawtoh"
// Read-modify-write in one step. The function receives the current value
// (undefined if the key does not exist) and returns the new one.
const count = await storage.update("sub_count", (n) => (n ?? 0) + 1)
await storage.update("seen_users", (list) => [...(list ?? []), "alice"])The function must be synchronous and side-effect free: it may be replayed on a write conflict. Don't await or call modules inside it.
Practical example
import { event, module, storage } from "rawtoh"
// Track how many times each user has used a command
const user = event.payload.username
const key = `cmd_count:${user}`
const count = await storage.update(key, (n) => (n ?? 0) + 1)
await module("twitch").request("chat.say", {
message: `@${user}, you've used this command ${count} times!`
})Managing storage in the UI
You can also view and edit storage entries directly from the dashboard. Go to the Storage page in the sidebar to:
- Browse all key-value pairs
- Create new entries
- Edit existing values with the JSON editor
- Delete entries
This is useful for setting up initial configuration, debugging script state, or manually adjusting values.
Tips
- Use prefixes to namespace your keys —
points:alice,config:greeting,state:current_scene. - Values are JSON — you can store objects and arrays, not just strings and numbers.
- Storage is organization-scoped — all scripts in the same organization share the same storage, which makes it easy to share data between automations.
- Reads are fast — don't hesitate to use storage in frequently-triggered actions.
- Counters and lists go through
update()— reserveset()for values that don't depend on what was there before.