We’ll use user onboarding as an example task. Let’s say your current process for onboarding a new user is SSH-ing into a production machine to run a script that updates the database, configures the account, and then sends a Slack message with information about the new user. We’ll automate this task.

Setting up the Onu SDK

You can use the Onu CLI to create a new Onu project (or add Onu to an existing Node.js project)

npx onu@latest init --language typescript

The CLI will create an onu/ directory for you. This is where all of you Onu tasks will live.

Creating a Task

Each task is defined as its own file within the onu/ directory. Every task file in this directory should export a Task as the default export. To learn all about how to write your Task configuration file in the Node SDK overview.

For now, you can copy and paste the snippet below. There are 3 steps:

  1. Onboard a demo user by making a request to Onu’s demo API
  2. Post to Slack notifying that a new user was added
  3. Return the response body to the execution page

onu/onboardUser.ts

// Demo task for the Getting Started Guide
import onu from "@onuhq/node";
import fetch from 'node-fetch';

const task = new onu.Task({
  name: "Getting Started Guide - Onboard a demo user",
  slug: 'create-account',
  input: {
    email: {
      type: "string",
      name: "Email",
    },
    accountType: {
      type: "select",
      name: "Account Type",
      options: ["basic", "pro"],
    },
  },
  run: async (input, context) => {
    const { email, accountType } = input;

    // You can import and use your project's existing code & business logic.
    // For the purposes of this demo, we'll just make a call to Onu's demo API
    const response = await fetch("https://demo.joinonu.com/api/onboard", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ email, accountType }),
    });

    const user = await response.json();

    return user;
  }
});

export default task;

Deploying your tasks

To deploy your tasks, you can use the onu deploy command.

npx onu@latest deploy

You can also self host your Onu instance. Documentation for self-hosting your Onu tasks is coming soon. In the meantime, you can reach out to us at founders@joinonu.com for instructions on how to self-host your Onu tasks.

Running a Task

Once you’ve created and deployed your task, you can access its UI on the Onu dashboard. The task page includes a few key elements:

  • The input form for the task
  • Task metadata
  • A list of the latest task executions.

From here you can run the task by clicking on the Run button in the top right corner.

After filling in the inputs and clicking Run, you’ll be taken to the task’s execution page. Here you can see the task’s output and whether the task succeeded or failed.

Editing a Task

To edit a task, simply edit the task’s configuration file and re-deploy your tasks to Onu.

(Optional) Integrations

Onu comes with a built-in Slack integration. To enable it, navigate to the Integrations tab on the Settings screen, find the Slack integration and click Connect. You’ll be redirected to a page asking you grant Onu permission to access your Slack workspace.