Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bjornpagen/segflow

An open-source, self-hosted, full-code alternative to Customer.io. Write your user engagement logic in pure TypeScript and SQL (Drizzle ORM).
https://github.com/bjornpagen/segflow

campaigns email-marketing

Last synced: 8 days ago
JSON representation

An open-source, self-hosted, full-code alternative to Customer.io. Write your user engagement logic in pure TypeScript and SQL (Drizzle ORM).

Awesome Lists containing this project

README

        

# Segflow: Zero to Hero Guide

## What is Segflow?

Segflow lets you write marketing automation flows in pure code. Instead of clicking through complex UIs, you can:
- Define user segments with SQL queries
- Write campaign logic in TypeScript
- Create email templates in React
- Deploy everything with Git

Think "Infrastructure as Code", but for marketing automation. See the example in `examples/segflow.config.ts` for a complete example.

## Key Concepts

### Segments = SQL Queries
Define user groups with the full power of SQL:
```typescript
segments: {
'big-spenders': {
evaluator: (db) => db
.select({ id: schema.users.id })
.from(schema.users)
.innerJoin(schema.events, eq(schema.events.userId, schema.users.id))
.where(eq(schema.events.name, 'purchase'))
.groupBy(schema.users.id)
.having(sql`sum(${schema.events.attributes}->'$.amount') > 1000`)
}
}
```

### Campaigns = Generator Functions
Write complex flows with regular TypeScript:
```typescript
campaigns: {
'onboarding': {
segments: ['new-users'],
behavior: 'static',
flow: function* (ctx, rt) {
yield rt.sendEmail('welcome');
yield rt.wait({ days: 1 });

if (!ctx.user.profileCompleted) {
yield rt.sendEmail('complete-profile-reminder');
yield rt.wait({ days: 3 });
}

yield rt.wait({ days: 3 });
yield rt.sendEmail('feature-highlights');
}
}
}
```

### Templates = React Components
Design emails with familiar tools:
```tsx
templates: {
'welcome': {
subject: (user) => `Welcome ${user.name}!`,
component: ({ user }) => (