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
  • Initialise
  • Destroy
  • Refresh
  • Restart
  • Open
  • Close
  • Send Message
  1. Developing With OpenDialog
  2. WebChat
  3. SDK

Methods

This section describes the methods available on the WebChat SDK

The WebChat SDK provides the following methods that allow you to interact with your chat widget programmatically:

  • .init()

  • .destroy()

  • .refresh()

  • .restart()

  • .open()

  • .close()

  • .sendMessage()


Initialise

Initialise an instance of WebChat using your preferred settings and - optionally - a set of custom components and an existing user ID:

/**
* Initialise the chat widget with settings and custom components
* @function init
* @param {Object} [settings={}] - settings object (optional)
* @param {Array} [customComponents=[]] - array of custom components (optional)
* @param {?string} [userId] - uuid for the user (optional)
*/

.init(settings, customComponents, userId)

If you do not provide a settings object, WebChat will look for one on the window.openDialogSettings object. If that's not present either, initialisation will fail. At a bare minimum, the settings object MUST include the following:

const settings = {
  url: 'your_bot_url', // The base URL for API requests. Tells WebChat where to get your conversation data from
  appKey: 'your_app_key', // Authenticates your requests
  sdkEnabled: true, // Enables the SDK. Otherwise an iframe widget will load on page load
  user: {
    custom: {
      selected_scenario: your_scenario_id // The specific sceanrio you want to load in your bot
    }
  }
}

Destroy

Destroy an existing WebChat widget:

/**
* Destroy the chat widget
* @function destroy
*/

.destroy()

Refresh

Refresh your WebChat widget with new settings. Does not change the conversation in any way. Calling refresh() will make a new call out to the /chatApi-config endpoint to ensure that any other interface settings affected by your changes are also updated. Your new settings will then be applied over those received from the server.

/**
* Refresh the chat widget with new settings
* @function refresh
* @param {Object} [settings={}] - settings object. Will be merged with existing settings
*/

.refresh(settings)

Restart

Restart your WebChat widget with new settings, a new starting intent, and/or a new user. Restart is distinct from Refresh because it affects the current conversational state.

The first parameter - clearUser: Boolean - determines whether to refresh the conversation from the beginning with the same user, or whether to clear all user data and start again from the very beginning. In both instances, the message list will be cleared ready for a new conversation to begin (note that this does not clear the user history, so if you retain the current user and they refresh the page then, depending on your settings, they may see the previous conversational history rendered)

If you provide an openIntent: string parameter, you can tell WebChat where to restart the conversation from. This success relies a little on your conversation design as this intent needs to be available at the point of request.

The parameter userId: 'string' is only applicable where clearUser === true and will allow you to restart the conversation with a given user.

/**
* Restart the chat widget
* @function restart
* @param {boolean} [clearUser=false] - clear the user (optional)
* @param {Object} [settings={}] - settings object. Will be merged with existing settings (optional)
* @param {?string} [userId] - uuid for the user. Only applicable where clearUser is true (optional)
* @param {?string} [openIntent] - openIntent for the chat widget (optional)
*/

.restart(true, settings, userId, openIntent)

Open

Opens the WebChat widget. The current open state of the widget is exposed on the instance and can be interrogated by calling webchat.openState

/**
* Open the chat widget
* @function open
*/

.open()

Close

Closes the WebChat widget. The current open state of the widget is exposed on the instance and can be interrogated by calling webchat.openState

/**
* Close the chat widget
* @function close
*/

.close()

Send Message

Send a message to chatApi through the WebChat widget. Note that the success of this functionality is very much dependent on your conversation design. The correct intent needs to be available to the conversation engine at the point of requesting!

export interface IPostMessage {
  text: string
  type?: string
  callback?: string
  value?: string
  escalating?: boolean,
  data?: any
}

/**
* Send a message through the chat widget
* @function sendMessage
* @param {IPostMessage} msg - message object.
*/

.sendMessage(msg)
PreviousSDKNextEvents

Last updated 8 months ago