Events & Callbacks

Listen to widget events and integrate with your application

Available Events

  • widget:opened - When the widget is opened
  • widget:closed - When the widget is closed
  • message:sent - When a message is sent
  • message:received - When a message is received
  • appointment:scheduled - When an appointment is booked

Example Usage

// Listen for widget events
window.addEventListener('aiworkers:widget:opened', (event) => {
  console.log('Widget opened', event.detail)
  // Track analytics, show notifications, etc.
})

window.addEventListener('aiworkers:appointment:scheduled', (event) => {
  console.log('Appointment scheduled', event.detail)
  const { appointmentId, scheduledAt } = event.detail
  // Sync with your calendar, send confirmation, etc.
})

Event Payload

{
  "type": "appointment:scheduled",
  "timestamp": "2025-01-15T10:30:00Z",
  "data": {
    "appointmentId": "uuid",
    "scheduledAt": "2025-01-20T14:00:00Z",
    "customerName": "John Doe"
  }
}