step.ext.sendEvent()

Send one or more events from within a workflow. This is an Inngest-specific step extension that allows workflows to trigger other workflows or notify external systems.

Signature

step.ext.sendEvent(stepId: string, event: SentEvent): Promise<{ ids: string[] }>

Parameters

NameTypeDescription
stepIdstringUnique identifier for this step. Used for state persistence.
eventSentEventThe event to send. See SentEvent below.

SentEvent

PropertyTypeDescription
namestringRequired. The event name. Used to identify which workflows should be triggered.
dataRecord<string, unknown>Optional. Event payload. Must be JSON-serializable.
idstringOptional. Custom event ID. If not provided, one will be generated automatically.
tsnumberOptional. Event timestamp in milliseconds. Defaults to current time.
vstringOptional. Event version identifier.

Returns

Returns a promise that resolves to an object containing:

PropertyTypeDescription
idsstring[]Array of event IDs that were sent.

Examples

Send event to trigger another workflow:

const workflow = client.workflow(
  { id: "process-order" },
  async ({ input }, step) => {
    const order = await step.run("create-order", async () => {
      return await db.orders.create(input.data);
    });
    
    // Trigger warehouse workflow
    await step.ext.sendEvent("notify-warehouse", {
      name: "order.created",
      data: { orderId: order.id, items: order.items },
    });
    
    return order;
  }
);

Send multiple related events:

const workflow = client.workflow(
  { id: "user-signup" },
  async ({ input }, step) => {
    const user = await step.run("create-user", async () => {
      return await db.users.create({ email: input.data.email });
    });
    
    // Notify multiple systems
    await step.ext.sendEvent("notify-crm", {
      name: "user.created",
      data: { userId: user.id, email: user.email },
    });
    
    await step.ext.sendEvent("start-onboarding", {
      name: "onboarding.start",
      data: { userId: user.id },
    });
    
    return user;
  }
);