Skip to content

Full tutorial

MySocial

Build a complete automation, organized into stages.

This is a condensed version of the full walkthrough. It shows the recommended structure: a state machine of stages, each mapping a recognized screen to the action that advances it.

Structure

Split the automation into a stage per screen. On each step, detect the current screen, then dispatch its handler.

src/main.ts
import { detectStage } from "./stages";
import { handlers } from "./handlers";

export async function run() {
  for (let step = 0; step < 50; step++) {
    const stage = await detectStage();
    const handler = handlers[stage];
    if (!handler) {
      await agent.control.finish("failed", "Unknown screen: " + stage);
      return;
    }
    const done = await handler();
    if (done) return agent.control.finish("success");
  }
}

Stages & handlers

src/handlers.ts
export const handlers: Record<string, () => Promise<boolean>> = {
  async login() {
    await agent.actions.tap({ text: "Log in" });
    return false;
  },
  async home() {
    await agent.info.log("Reached home");
    return true; // success
  },
};