Join Discord

Enter your email to get updates
What is Membrane?
Membrane is a hosted TypeScript runtime specifically designed to build personal automation tools and interact with APIs more easily.
FEATURES
EXAMPLES
example-hn-follow
This example shows how to use the hn Driver to follow users on Hacker News and get notifications (email or SMS) when they post something new.
Set up a "cron-job" timer that invokes check periodically.
Store "last seen" in state for persistence.
Send yourself an text message
import { nodes, root, state } from "membrane";
const { hn, sms } = nodes;

export function setup() {
  root.check.$cron("30 35 * * * *");
}

export async function follow({ username }) {
  const { id, submitted } = await hn.users
    .one({ id: username })
    .$query(`{ id submitted { items { id } } }`);
  const lastSeen = submitted?.items?.[0]?.id ?? 0;
  state[username] = { id, lastSeen };
}

export async function check() {
  for (const [username, { lastSeen }] of Object.entries(state)) {
    const items = await hn.users
      .one({ id: username })
      .submitted.items.$query(`{ id }`);

    const latest = (items ?? [])[0];
    if (latest?.id! > (lastSeen as number)) {
      const url = `https://news.ycombinator.com/item?id=${latest.id}`;
      await sms.send({ message: `New HN post from ${username}: ${url}` })
      state[username] = latest.id!;
    }
  }
}
Install From VS Code
Dev Blog