xiaohongshu
xiaohongshu
inngest-workflow
Create Inngest workflows for durable execution. Use when building agent workflows, approval flows, scheduled tasks, or any multi-step async process.
Full skill instructions
Inngest is the only workflow engine for this platform. All durable execution goes through Inngest.
import { inngest } from './client'
export const handleInboundMessage = inngest.createFunction(
{
id: 'handle-inbound-message',
// Throttle prevents duplicate processing
throttle: {
key: 'event.data.conversationId',
limit: 1,
period: '10s',
},
},
{ event: 'front/inbound_received' },
async ({ event, step }) => {
const { conversationId, appId, senderEmail } = event.data
// Step 1: Gather context (retriable)
const context = await step.run('gather-context', async () => {
const [user, messages, app] = await Promise.all([
appRegistry.get(appId).integration.lookupUser(senderEmail),
front.conversations.listMessages(conversationId),
appRegistry.get(appId),
])
return { user, messages, app }
})
// Step 2: Agent reasoning (retriable)
const agentResult = await step.run('agent-reasoning', async () => {
return supportAgent.run({
messages: [{ role: 'user', content: buildPrompt(context) }],
context,
})
})
// Step 3: Handle approval or execute
if (agentResult.action?.requiresApproval) {
await step.run('request-approval', async () => {
await requestApproval({
action: agentResult.action,
conversationId,
appId,
agentReasoning: agentResult.reasoning,
})
})
} else if (agentResult.action) {
await step.run('execute-action', async () => {
await executeAction(agentResult.action)
})
}
// Step 4: Create draft response
if (agentResult.draftResponse) {
await step.run('create-draft', async () => {
await front.conversations.createDraft(conversationId, {
body: agentResult.draftResponse,
})
})
}
return { processed: true, action: agentResult.action }
}
)
throttle: {
key: 'event.data.conversationId',
limit: 1,
period: '10s',
}
⚠️ CRITICAL: Match Field Alignment
The match field MUST align with the field name in BOTH the triggering event AND the awaited event:
// Triggering workflow sends:
await inngest.send({
name: 'support/approval.requested',
data: { actionId: 'abc123', ... } // ← Field is "actionId"
})
// waitForEvent MUST use the same field:
const approval = await step.waitForEvent('approval-received', {
event: 'support/approval.decided',
match: 'data.actionId', // ✅ Matches triggering event's field name
timeout: '24h',
})
// Decision event MUST also use the same field:
await inngest.send({
name: 'support/approval.decided',
data: { actionId: 'abc123', approved: true } // ✅ Same field name
})
Common mistake:
// ❌ WRONG - field name mismatch
// Trigger has: data.actionId
// waitForEvent uses: match: 'data.approvalId' ← Never matches!
// Decision has: data.approvalId
const approval = await step.waitForEvent('approval-received', {
event: 'action/approved',
match: 'data.actionId',
timeout: '24h',
})
if (!approval) {
await step.run('handle-timeout', () => expireAction(actionId))
}
await step.sleep('wait-for-send', '5m')
await step.run('auto-send', () => sendDraft(draftId))
await step.invoke('process-refund', {
function: processRefundWorkflow,
data: { purchaseId, reason },
})
{source}/{entity}.{action}
Examples:
- front/inbound_received
- front/outbound_sent
- action/approved
- action/rejected
- stripe/refund.completed
CRITICAL: Use lazy initialization, not the singleton.
// ❌ BAD - singleton creates pool at import time, fails in serverless
import { database, ActionsTable } from '@skillrecordings/database'
// ✅ GOOD - lazy init inside step function
import { getDb, ActionsTable } from '@skillrecordings/database'
await step.run('create-action', async () => {
const db = getDb() // Pool created here, at runtime
await db.insert(ActionsTable).values({ ... })
})
Why: The database singleton calls mysql.createPool() at import time. In serverless/Turbopack builds, this fails because DATABASE_URL isn't available during static analysis.
Keep Inngest functions registered on Vercel serverless:
// app/api/cron/route.ts
import { headers } from 'next/headers'
export const dynamic = 'force-dynamic'
export async function GET() {
await headers()
const baseUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: 'http://localhost:3000'
await fetch(`${baseUrl}/api/inngest`, { method: 'PUT' })
return new Response(null, { status: 200 })
}
// vercel.json
{
"crons": [{ "path": "/api/cron", "schedule": "*/5 * * * *" }]
}
When fetching from external APIs (Front, Stripe), always provide fallback:
const context = await step.run('get-context', async () => {
const fallback = {
body: event.data.messageBody || '',
senderEmail: event.data.customerEmail || '',
}
try {
const data = await externalApi.fetch(id)
return data
} catch (error) {
console.warn('[workflow] API error, using fallback:', error)
return fallback
}
})
packages/core/src/inngest/client.tspackages/core/src/inngest/workflows/packages/core/src/inngest/events.tsapps/front/app/api/cron/route.tsFor full details, see:
docs/support-app-prd/65-workflows.mdxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience