Mirra
Building with MirraScriptsEvents Reference

Flow Completion Events

React to completed flow executions for chaining and monitoring

Flow completion events fire when a flow (script) finishes execution. These events enable flow chaining, execution monitoring, and error alerting.


Event Types

flow.complete

The flow.complete event fires when any flow finishes execution, whether successful or failed. This event includes execution metadata, timing, and output data, making it useful for chaining flows together or monitoring automation health.

Event Type:

type: 'flow.complete'
source: 'flow'

Fields:

content.text (string)

Flow completion summary.

flow.flowId (string)

ID of the flow that completed.

flow.flowTitle (string)

Human-readable flow title.

flow.flowType ('user' | 'system')

Whether this is a user-created or system flow.

flow.scriptId (string | null)

Script ID if the flow used a script. Null for scriptless flows.

flow.scriptName (string | null)

Script name if applicable.

flow.executionId (string)

Unique execution identifier for this run.

flow.durationMs (number)

Execution duration in milliseconds.

flow.tokensConsumed (number)

Number of LLM tokens consumed during execution.

flow.success (boolean)

True if the flow completed successfully, false if it errored.

flow.errorMessage (string | null)

Error message if the flow failed. Null on success.

flow.triggeredBy (object)

What triggered this flow execution.

FieldTypeDescription
type'event' | 'schedule' | 'manual'How the flow was triggered
eventTypestring | undefinedSource event type if triggered by an event (e.g., 'call.ended')
sourceEventIdstring | undefinedID of the triggering event
data (FlowOutputData)

Output data from the flow execution. Structure depends on the flow type.

Example - Flow Chain:

export async function handler(event, context) {
  // Only react to successful completions of a specific flow
  if (!event.flow.success || event.flow.flowTitle !== 'Call Summarizer') {
    return { success: true, skipped: true };
  }
 
  // Chain into next flow - e.g., send summary to team
  await mirra.telegram.sendMessage({
    chatId: 'your-team-channel',
    text: `Flow "${event.flow.flowTitle}" completed in ${(event.flow.durationMs / 1000).toFixed(1)}s`
  });
 
  return { success: true };
}

Example - Error Monitor:

export async function handler(event, context) {
  // Alert on failed flows
  if (event.flow.success) {
    return { success: true, skipped: true };
  }
 
  await mirra.telegram.sendMessage({
    chatId: 'admin-alerts',
    text: `🚨 Flow Failed\n\nFlow: ${event.flow.flowTitle}\nExecution: ${event.flow.executionId}\nDuration: ${event.flow.durationMs}ms\nTokens: ${event.flow.tokensConsumed}\n\nError: ${event.flow.errorMessage}\n\nTriggered by: ${event.flow.triggeredBy.type}${event.flow.triggeredBy.eventType ? ` (${event.flow.triggeredBy.eventType})` : ''}`
  });
 
  return { success: true };
}

Example - Execution Logger:

export async function handler(event, context) {
  await mirra.google.sheets.appendRow({
    spreadsheetId: 'your-sheet-id',
    sheetName: 'Flow Executions',
    values: [
      new Date().toISOString(),
      event.flow.flowTitle,
      event.flow.executionId,
      event.flow.success ? 'Success' : 'Failed',
      event.flow.durationMs,
      event.flow.tokensConsumed,
      event.flow.triggeredBy.type,
      event.flow.errorMessage || ''
    ]
  });
 
  return { success: true };
}

Subscription Examples:

// All flow completions
{
  "eventType": "flow.complete"
}
 
// Only failures
{
  "eventType": "flow.complete",
  "conditions": [
    {
      "field": "flow.success",
      "operator": "equals",
      "value": false
    }
  ]
}
 
// Specific flow
{
  "eventType": "flow.complete",
  "conditions": [
    {
      "field": "flow.flowTitle",
      "operator": "equals",
      "value": "Call Summarizer"
    }
  ]
}
 
// Event-triggered flows only
{
  "eventType": "flow.complete",
  "conditions": [
    {
      "field": "flow.triggeredBy.type",
      "operator": "equals",
      "value": "event"
    }
  ]
}

See Also

On this page