OpenDialog Docs
opendialog.aiStart BuildingTalk to an expert
  • GETTING STARTED
    • Introduction
    • Getting ready
    • Billing and plans
    • Quick Start AI Agents
      • Quick Start AI Agent
      • The "Start from Scratch" AI Agent
        • Chat Management Conversation
        • Welcome Conversation
        • Topic Conversation
        • Global No Match Conversation
        • Supporting LLM Actions
        • Semantic Classifier: Query Classifier
      • A Process Handling AI Agent
  • STEP BY STEP GUIDES
    • AI Agent Creation Overview
    • Add a new topic of discussion
    • Use knowledge sources via RAG
    • Adding a structured conversation
    • Add a 3rd party integration
    • Test and tweak your AI Agent
    • Publish your AI Agent
  • CORE CONCEPTS
    • OpenDialog Approach
      • Designing Conversational AI Agents
    • OpenDialog Platform
      • Scenarios
        • Conversations
        • Scenes
        • Turns and intents
      • Language Services
      • OpenDialog Account Management
        • Creating and managing users
        • Deleting OpenDialog account
        • Account Security
    • OpenDialog Conversation Engine
    • Contexts and attributes
      • Contexts
      • Attributes
      • Attribute Management
      • Conditions and operators
      • Composite Attributes
  • CREATE AI APPLICATIONS
    • Designing your application
      • Conversation Design
        • Conversational Patterns
          • Introduction to conversational patterns
          • Building robust assistants
            • Contextual help
            • Restart
            • End chat
            • Contextual and Global No Match
            • Contextual FAQ
          • Openings
            • Anatomy of an opening
            • Transactional openings
            • Additional information
          • Authentication
            • Components
            • Example dialog
            • Using in OpenDialog
          • Information collection
            • Components
            • Example dialog
            • Using in OpenDialog
            • Additional information
          • Recommendations
            • Components
            • Example dialog
            • Additional information
          • Extended telling
            • Components
            • Example dialog
            • Additional information
          • Repair
            • Types of repair
            • User request not understood
            • Example dialog
            • Additional information
          • Transfer
            • Components
            • Example dialog
            • Additional information
          • Closing
            • Components
            • Example dialog
            • Using in OpenDialog
            • Additional information
        • Best practices
          • Use Case
          • Subject Matter Expertise
          • Business Goals
          • User needs
            • Primary research
            • Secondary research
            • Outcome: user profile
          • Assistant personality
          • Sample dialogs
          • Conversation structure
          • API Integration Capabilities
          • NLU modeling
          • Testing strategy
          • The team
            • What does a conversation designer do
          • Select resources
      • Message Design
        • Message editor
        • Constructing Messages
        • Message Conditions
        • Messages best practices
        • Subsequent Messages - Virtual Intents
        • Using Attributes in Messages
        • Using Markdown in messages
        • Message Types
          • Text Message
          • Image Message
          • Button Message
          • Date Picker Message
          • Audio Message
          • Form Message
          • Full Page Message
          • Conversation Handover message
          • Autocomplete Message
          • Address Autocomplete Message
          • List Message
          • Rich Message
          • Location Message
          • E-Sign Message
          • File Upload Message
          • Meta Messages
            • Progress Bar Message
          • Attribute Message
      • Webchat Interface design
        • Webchat Interface Settings
        • Webchat Controls
      • Accessibility
      • Inclusive design
    • Leveraging Generative AI
      • Language Services
        • Semantic Intent Classifier
          • OpenAI
          • Azure
          • Google Gemini
          • Output attributes
        • Retrieval Augmented Generation
        • Example-based intent classification [Deprecated]
      • Interpreters
        • Available interpreters
          • OpenDialog interpreter
          • Amazon Lex interpreter
          • Google Dialogflow
            • Google Dialogflow interpreter
            • Google Dialogflow Knowledge Base
          • OpenAI interpreter
        • Using a language service interpreter
        • Interpreter Orchestration
        • Troubleshooting interpreters
      • LLM Actions
        • OpenAI
        • Azure OpenAI
        • Output attributes
        • Using conversation history (memory) in LLM actions
        • LLM Action Analytics
    • 3rd party Integrations in your application
      • Webhook actions
      • Actions from library
        • Freshdesk Action
        • Send to Email Action
        • Set Attributes Action
      • Conversation Hand-off
        • Chatwoot
    • Previewing your application
    • Launching your application
    • Monitoring your application
    • Debugging your application
    • Translating your application
    • FAQ
    • Troubleshooting and Common Problems
  • Developing With OpenDialog
    • Integrating with OpenDialog
    • Actions
      • Webhook actions
      • LLM actions
    • WebChat
      • Chat API
      • WebChat authentication
      • User Tracking
      • Load Webchat within page Element
      • How to enable JavaScript in your browser
      • SDK
        • Methods
        • Events
        • Custom Components
    • External APIs
  • Release Notes
    • Version 3 Upgrade Guide
    • Release Notes
Powered by GitBook
On this page
  • Adding an event listener
  • Supported events
  1. Developing With OpenDialog
  2. WebChat
  3. SDK

Events

This section describes the events available on WebChat via the SDK

WebChat emits a number of events that you can listen to within your own application.

Adding an event listener

To add an event listener, use:

webchat.on('event_name':string, callback: Function)

Each listener will return a CustomEvent object with specific data nested in the event.detail object:

/**
* Add an event listener to the chat widget
* @function on
* @param {string} eventName - the event to listen for
* @param {Function} callback - the function to call when the event is triggered
* @returns {CustomEvent} - the event object with specific data in the event.detail object
*/

.on('loaded', (e: CustomEvent) => {
    console.log(e.detail) // the event data specific to WebChat
})

For convenience, all events return the element upon which the event was fired within the detail object. For additional return values, see the descriptions below.

Supported events

'loaded' - fired when the WebChat widget has initialised.

Returns a 'loaded' property with a Boolean value:

loaded: true


'openStateChanged' - fired when the WebChat widget is opened or closed.

Returns a String value:

enum openState {
  OPEN = 'open',
  CLOSED = 'closed'
}

return openState: openState.OPEN

'messageSent' - fired when the user sends a message.

Returns a message object:

export interface IMessagePayload {
  kind?: 'outgoing'
  author: string
  content: IMessageContent
  message_id: string
  notification: string
  user_id: string
  uuid?: string
  mode?: string
  modeInstance?: number
  partOfLastTemplate?: boolean
}

export interface IMessageContent {
  author: string
  callback_id?: string
  id: string
  mode?: string
  modeInstance?: number
  type: string
  user: Object
  data: {
    text: string
    date: string
    time: string
    value?: string
    [key: string]: any
  }
  escalating?: boolean
}

return message: IMessagePayload

'messageReceived' - fired when WebChat receives a message from the server.

Returns a message object:

export interface IMessage {
  kind?: 'incoming'
  first?: boolean
  last?: boolean
  author: string
  intent?: string
  type: string
  data: IMessageData
  uuid?: string
  authorAvatar?: string
  authorName?: string
  partOfLastTemplate?: boolean
}

export interface IMessageData {
  text: string | null
  meta?: {
    author?: {
      name?: string
      avatar?: string
      [key: string]: any
    }
    [key: string]: any
  }
  attribute_name: string | null
  date: string | null
  disable_text?: boolean
  hideavatar?: boolean
  hidetime?: boolean
  internal?: boolean
  time: string | null
  elements?: IElement[] | IElementsObject
  submit_text?: string
  [key: string]: any
}

return message: IMessage

'chatEnded' - fired when the user selects 'end chat' from the menu in the WebChat application

PreviousMethodsNextCustom Components

Last updated 8 months ago