Develop a component for Virtual Agent

  • Release version: Zurich
  • Updated July 31, 2025
  • 3 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Develop a component for Virtual Agent

    This guide explains how to create custom components for ServiceNow's Virtual Agent to either display information or gather user input within the Virtual Agent client interface. Developing these components involves adding specific properties and actions to interact properly with the Virtual Agent during conversations.

    Show full answer Show less

    Types of Virtual Agent Components

    • Response Component: Displays information only, without user interaction. It requires a controlData property to receive initial data from the Virtual Agent server.
    • Input Component: Displays information and collects user input. It uses controlData for initial data, responseValue to capture user responses, and forceCloseControl to manage whether the component can accept input.

    Properties and Actions

    Input components emit user responses using the VACONTROL#VALUESENT action, which sends data back to the server. These properties and actions enable communication between the component and the Virtual Agent framework, ensuring smooth data flow during conversations.

    Input Component States and Behavior

    • Waiting for Input: The component displays controls (e.g., sliders, buttons) allowing the user to provide input. The component listens for actions like button clicks to capture and send user responses.
    • Handling Input: When a user confirms input, the component closes (disallows further input) and dispatches the response data to the server.
    • Closed: The component no longer accepts input, either because a response was provided or the conversation has ended. It then displays the user’s response for confirmation or record.

    Adding and Testing Custom Components

    After development and deployment, add your custom component to the Virtual Agent Designer via custom controls and definitions. Thoroughly test your component before deploying it to production to ensure it interacts correctly with the Virtual Agent client interface.

    Create a custom Virtual Agent component to gather input or display information in the Virtual Agent client interface.

    Types of Virtual Agent components

    To develop a component for Virtual Agent, add specific properties and actions to interact with the Virtual Agent client interface. The properties required depend on the type of component you are creating.

    Response component

    A response component only provides information to the user, and does not gather input or handle user interaction. For example, a card control that does not require user input and is only in the conversation once.A card control as an output component that does not require user input

    Add a property to your response component to handle the data sent by the Virtual Agent server.

    Table 1. Output component properties
    Property Description
    controlData Initial data that the Virtual Agent server sends to your component as the topic runs.

    Data type: JSON Object

    Input component

    An input component displays information and/or gathers user input. It includes the same property as the output component to handle data sent by the server, but has more possible states and requires user interaction.

    Table 2. Input component properties
    Property Description
    controlData Initial data that the Virtual Agent server sends to your component as the topic runs.

    Data type: JSON Object

    responseValue Data sent to the component from the user's response, either from the client directly, or from the server if there is a refresh. Only use in components that require user input.

    Data type: JSON Object

    forceCloseControl Flag that indicates whether the component can accept input. When true, the control closes and the user cannot interact with it. Monitor changes on the client to update this value. Only use in components that require user input.

    Data type: Boolean

    Use this action to emit data from user interaction.

    Table 3. Input component actions
    Action Description
    VA_CONTROL#VALUE_SENT Response data from the client to send to the server. Only use in components that require user input.

    Data type: JSON Object

    Input component states

    Because they accept data, input components must handle multiple states. The state flow is generally as follows:

    1. Virtual Agent shows the custom component in the waiting for input state.
    2. The user interacts with the component to provide input.
    3. The component closes and sends the responseValue property to the server.
    4. The server runs the server-side logic and sends the component with the user's input back to the client.
    Waiting for Input

    The initial state of a component waiting for user interaction. The controlData property is set, but the forceControlClosed property is false. This example shows a slider component in the waiting for input state.

    Component waiting for input.

    In this example, if the user has not provided a responseValue and the control is not closed, the slider and the input button display.

    const {controlClosed, sliderVal, sliderMin, sliderMax} = state;
    return (<div class={{"slider-chat": true}}>
        {responseValue ? null :  <Fragment>
        <div class={{"slider-label": true}}>{label}</div>
        {controlClosed ? null : <Fragment>
            <div class={{"slider-container": true}}>
                        <input on-change={onSliderChange} type="range" min={sliderMin} max={sliderMax} value={sliderVal} class={{"slider": true}} />
                <div class={{"slider-value": true}}>
                        {unitIcon && 
                         <div class={{"unit-icon": true}}><img src={unitIcon} /></div>
                         } 
                         {sliderVal} {unitName}
                    </div>
            <div class={{"button-container":true}}>
                <now-button variant="primary" label={buttonText || 'Confirm'} />
             </div></div></Fragment>}
    Handling Input

    In the previous example, the slider uses a now-button component, which the user clicks to confirm input and send it to the server. When the user clicks the button, the VA_CONTROL#VALUE_SENT action fires with the responseValue payload.

    'NOW_BUTTON#CLICKED': (data) => {
        const {updateState, dispatch, state: {sliderVal}} = data;
        updateState({controlClosed: true});
        dispatch('VA_CONTROL#VALUE_SENT', {
            value: {
                sliderVal
            }
        }); 
    }
    Closed

    A component that is closed can no longer accept user input. Components are generally closed because:

    • The user responded to the component. The component closes and the conversation continues.
    • The user ended the chat. The server does not wait for a response.

    For example, the slider component only renders the original prompt when in the closed state.

    Closed component that is no longer waiting on user input.

    Sending response

    After the user responds, the control is rendered again on the user's side of the conversation with the value of the responseValue property.

    Users response sent to the client.

    For example, the slider control uses this snippet to render the response.

    {responseValue && <div className="response-container slider-value">
       {unitIcon && 
       <div className="unit-icon"><img src={unitIcon} /></div>
       } 
       {returnVal} {unitName}
    </div>}

    Adding the component to Virtual Agent Designer

    After developing the component and deploying it to your instance, add it to Virtual Agent Designer using a custom control and definition. For more information, see Virtual Agent custom controls.