Skip to content

Step 4: Add Executor

Add an executor that sends a Slack notification whenever a Task is created.

Source code on GitHub

Configuration Files

Only change from Step 3: added executor to tailor.config.ts.

typescript
import { defineAuth, defineConfig, defineGenerators } from "@tailor-platform/sdk";
import { user } from "./src/db/user";

if (!process.env.WORKSPACE_ID) {
  throw new Error("WORKSPACE_ID environment variable is not set");
}

export default defineConfig({
  workspaceId: process.env.WORKSPACE_ID,
  name: "project-management",
  db: { "main-db": { files: [`./src/db/*.ts`] } },
  auth: defineAuth("main-auth", {
    userProfile: {
      type: user,
      usernameField: "email",
      attributes: {
        role: true,
      },
    },
    machineUsers: {
      manager: {
        attributes: { role: "MANAGER" },
      },
      staff: {
        attributes: { role: "STAFF" },
      },
      admin: {
        attributes: { role: "ADMIN" },
      },
    },
  }),
  resolver: { "main-resolver": { files: [`./src/resolver/*.ts`] } },
  executor: { files: ["./src/executor/*.ts"] },
});

export const generators = defineGenerators([
  "@tailor-platform/kysely-type",
  { distPath: `./src/generated/tailordb.ts` },
]);

createExecutor takes an object config with name, trigger, and operation. The trigger recordCreatedTrigger takes { type: task }. Available trigger context: newRecord (created), oldRecord/newRecord (updated), record (deleted).

typescript
import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk";
import { task } from "../db/task";

export default createExecutor({
  name: "new-task-slack-notification",
  description: "Send Slack notification when a new task is created",
  trigger: recordCreatedTrigger({
    type: task,
  }),
  operation: {
    kind: "webhook",
    url: "https://hooks.slack.com/services/yourSlackWebhookURL",
    headers: {
      "Content-Type": "application/json",
    },
    body: ({ newRecord }) => ({
      text: "New Task created :tada: " + newRecord.name,
    }),
  },
});

File Tree

project-management/
├── package.json
├── tsconfig.json
├── tailor.config.ts
└── src/
    ├── common/permission.ts
    ├── db/
    │   ├── user.ts
    │   ├── project.ts
    │   └── task.ts
    ├── generated/tailordb.ts
    ├── resolver/closeProject.ts
    └── executor/
        └── newTaskSlackNotification.ts    # New

Deploy

bash
npm run generate
npm run deploy

Verify

graphql
mutation {
  createTask(
    input: {
      name: "Test notification"
      description: "Testing executor"
      projectId: "your-project-id"
      status: TODO
      dueDate: "2025-12-31"
    }
  ) {
    id
    name
  }
}

Check your Slack channel for the notification. If it doesn't appear, verify the webhook URL is correct and test it directly:

bash
curl -X POST https://hooks.slack.com/services/YOUR_WEBHOOK_URL \
  -H "Content-Type: application/json" \
  -d '{"text": "Test message"}'

Additional Resources