Tutorial: post new sign-ups to Slack
Know the moment someone joins your app. You will give each member a profile row that the platform creates at sign-up, add one workflow that posts the new member to a Slack channel and notifies your admins in the app, and test it with a dry run before anything reaches Slack. It builds on the todo tutorial, and works the same on any app with a sign-up role.
1. Connect Slack
- In Slack, create an app for your workspace, give its bot the
chat:writescope, install it and copy the bot token (xoxb-…). - Invite the bot to the channel (
/invite @your-bot) and copy the channel id from the channel's details, for exampleC0123456789. - Store the token for the project. The credentials are sealed and never shown again:
Withoutintegrations { "project_id": "…", "action": "connect", "piece": "slack", "credentials": { "bot_token": "xoxb-…", "channel": "C0123456789" } }envthe connection holds for dev and production, which needs a token with the deploy scope ("env": "dev"needs only apply). The project secretsSLACK_BOT_TOKENandSLACK_CHANNELwork instead of a connection. - Send one message now to prove it works (it really posts):
integrations { "project_id": "…", "action": "call", "piece": "slack", "piece_action": "send_channel_message", "input": { "channel": "C0123456789", "text": "Hello from Tick" } }
2. The files
Tick has no row per member yet, so there is nothing for a workflow to start on. These files add one, plus an admin role to notify. Ask your agent ("When a new member signs up, post 'New sign-up: name (email)' to Slack channel C0123456789 and notify admins in the app") or write them yourself:
app.config.ts
// app.config.ts: Tick, now with a profile row per member and an admin role.
import { defineApp } from "@appbricx/define";
export default defineApp({
brand: { name: "Tick", tagline: "Your list, nobody else's", color: "#2563EB" },
locale: { language: "en-GB", timezone: "Europe/London" },
auth: { signup: { as: ["member"] }, admin: "admin" },
roles: {
member: { kind: "consumer", label: "Member", profile: { table: "member_profile", create: true } },
admin: { kind: "staff", label: "Admin" },
},
});
db/schema/member_profile.sql
-- db/schema/member_profile.sql: the platform inserts a row for every new member.
create table if not exists member_profile (
id uuid primary key default gen_random_uuid(),
user_id uuid unique,
name text not null,
email ctx.email,
created_at timestamptz not null default now()
);
comment on column member_profile.email is '@pii';
db/access/member_profile.sql
-- db/access/member_profile.sql: members see their own row; admins see everyone.
drop policy if exists member_profile_self on member_profile;
create policy member_profile_self on member_profile for select using (user_id = (select ctx.uid()));
drop policy if exists member_profile_admin on member_profile;
create policy member_profile_admin on member_profile for select using ((select ctx.has_role('admin')));
workflows/signup.ts
// workflows/signup.ts: every new member goes to Slack and to the admins' notifications.
import { on } from "@appbricx/workflows";
type Profile = { id: string; name: string; email: string | null };
export const newMember = on.created<Profile>("member_profile", async ({ row }, step) => {
const text = "New sign-up: " + row.name + (row.email ? " (" + row.email + ")" : "");
const posted = await step.run("post to Slack", async () => {
try {
await step.ctx.integrations.call("slack", { action: "send_channel_message", channel: "C0123456789", text });
return true;
} catch (e) {
// Not connected yet, or Slack refused: log it and still notify the admins.
step.ctx.log("Slack: " + (e instanceof Error ? e.message : String(e)));
return false;
}
});
await step.send.notify("new-signup", { role: "admin", vars: { name: row.name } });
return { posted };
});
messages/notify/new-signup.md
---
title: "New sign-up: {{name}}"
link: /
vars:
name: string
sample:
name: Test Person
---
{{name}} just joined Tick.
profile: { table: "member_profile", create: true }: when someone signs up (or first signs in with Google, or is invited as a member), the platform inserts their row withuser_id,nameandemail. Every othernot nullcolumn needs a default, or the check fails at that line ofapp.config.ts.on.created("member_profile")starts once per new row, after the insert commits.- The Slack call is inside
step.run, so a retry of the run doesn't post twice. Itscatchkeeps the run going when Slack isn't connected or refuses the message: the admins are still notified and the run log says why Slack was skipped. auth.admin: "admin"gives the built-in admin sign-in the new staff role, so there is someone to notify on day one.
3. Check, apply, and test without a real sign-up
appbricx push <project-id> tick --check
appbricx push <project-id> tick --applyThen run the workflow once on a made-up row. Nothing is posted, written or notified; you see what would be:
workflows { "project_id": "…", "action": "dry_run", "id": "newmember",
"row": { "id": "00000000-0000-4000-8000-000000000001",
"name": "Test Person", "email": "test@example.com" } }
// effects: integrations.call slack send_channel_message "New sign-up: Test Person (test@example.com)",
// the new-signup notification to role adminThen for real: sign up on the preview's /signup page (or screenshot with fill and click steps on it). Slack shows the message, the admin sees the notification, and logs { "workflow": "newmember" } shows the run with what Slack answered.
4. Publish
deploy. With the connection from step 1 holding for both environments, every real sign-up on production posts to the channel. Connect again with "env": "prod" to give production its own bot or channel.
Gotchas
- Use the channel id, not its name, and invite the bot to private channels, or Slack refuses the message.
- Code outside
step.runruns again on a retry. Anything that talks to the outside world goes inside a step. - Every write starts the workflow, whoever makes it: a sign-up, an invite, an
edit_rowsinsert or a SQL insert. Use the dry run to test, not fake rows on production. - Don't post private data to a busy channel. Name and email may already be more than you want there.