Skip to content
QwryAI
Documentation
Pages

Website Integration

Client-Side Custom Forms

Show your own forms inside the chat, defined in your page's JavaScript, and send the answers to your systems

Overview

A custom form Action shows a form inside the conversation when the agent needs structured details, such as a demo request or a return. You create the Action in the dashboard, and your website defines the form's fields in JavaScript. The visitor fills it in without leaving the chat, and QwryAI can send each submission to your webhook.

Key Benefits

  • Instant validation: visitors see what's missing before they submit.
  • Smoother conversations: the agent collects several details at once instead of one question at a time.
  • Full control: the fields, labels, options and messages are yours, and can change per visitor.

Prerequisites

Setup Guide

  1. Create your custom form Action

    In your agent, open Actions, select Create Action and choose Custom form.

    Create Action › Custom form.

Under General, enter an Action name and explain when the agent should show the form, with a few example questions. Then save.

Name the form and say when to use it.
  1. Register your form schema

    On your website, call registerFormSchema with a function named exactly like the Action. The function returns the form:

    JavaScript
    window.qwryai("registerFormSchema", {
      learn_more_form: async (args, user) => {
        return {
          fields: [
            {
              name: "name",
              label: "Full name",
              type: "text",
              placeholder: "Enter your full name",
              validation: { required: { value: true, message: "Name is required" } },
            },
            {
              name: "email",
              label: "Email address",
              type: "email",
              placeholder: "Enter your email",
              validation: { required: { value: true, message: "Email is required" } },
            },
            {
              name: "message",
              label: "Message",
              type: "textarea",
              placeholder: "How can we help you?",
              validation: { required: { value: true, message: "Please enter your message" } },
            },
          ],
          submitButtonText: "Send message",
          successMessage: "Thank you! We'll get back to you soon.",
          errorMessage: "Failed to send your message. Please try again.",
        };
      },
    });
  1. Webhooks (optional)

    To receive each submission on your own server, add a webhook under the Action's Webhooks step. See Webhooks Integration.

  2. Choose channels

    Under Channels, pick where the Action can run. The form can only appear where your website's code is loaded, such as the Chat bubble on your site.

    Channels: where the form can appear.

Function Parameters

Your form function receives the same two arguments as a client-side custom Action:

args object required

The inputs the agent collected for this Action, with the names you set under Inputs. Use them to fill in default values or decide which fields to show.

Inputs: values the agent passes to your form.

user object

Who the visitor is: user_id, user_hash, anon_user_id and user_metadata. user_id is set when the visitor is signed in with identity verification.

Complete Example

A profile form that uses several field types and pre-fills what's already known:

JavaScript
window.qwryai("registerFormSchema", {
  update_profile: async (args, user) => ({
    showLabels: true,
    submitButtonText: "Save profile",
    successMessage: "Your profile is updated.",
    errorMessage: "We couldn't save your profile. Please try again.",
    fields: [
      {
        name: "fullName",
        label: "Full name",
        type: "text",
        defaultValue: user.user_metadata.name || "",
        validation: {
          required: { value: true, message: "Enter your name" },
          minLength: { value: 2, message: "At least 2 characters" },
        },
      },
      {
        name: "phone",
        label: "Mobile number",
        type: "phone",
        placeholder: "+15551234567",
      },
      {
        name: "teamSize",
        label: "Team size",
        type: "number",
        validation: { min: { value: 1, message: "At least 1" }, max: { value: 5000, message: "At most 5,000" } },
      },
      {
        name: "plan",
        label: "Plan",
        type: "select",
        options: [
          { value: "starter", label: "Starter" },
          { value: "growth", label: "Growth" },
        ],
      },
      {
        name: "interests",
        label: "Interests",
        type: "groupmultiselect",
        options: {
          Support: [{ value: "helpdesk", label: "Helpdesk" }, { value: "voice", label: "Voice" }],
          Sales: [{ value: "outbound", label: "Outbound" }, { value: "leads", label: "Lead capture" }],
        },
      },
      {
        name: "avatar",
        label: "Profile photo",
        type: "image",
      },
      {
        name: "accountId",
        label: "Account",
        type: "text",
        defaultValue: user.user_id,
        disabled: true,
      },
    ],
  }),
});

API Reference

Form Schema

PropertyTypeDefaultDescription
fieldsarrayrequiredThe form's fields, in order.
submitButtonTextstring"Submit"The submit button's text.
showLabelsbooleanfalseShow each field's label above it. Without labels, the placeholder guides the visitor.
successMessagestring"Form submitted successfully"Shown after a successful submission.
errorMessagestring"Error submitting form"Shown when the submission fails.

Field Schema

PropertyTypeDescription
namestringRequired. The field's key in the submitted data. Must be unique in the form.
typestringRequired. One of the field types.
labelstringThe field's label. Defaults to name.
placeholderstringHint text inside the field. Defaults to the label.
defaultValueanyThe field's starting value.
disabledbooleanShows the field read-only. Disabled fields aren't validated.
validationobjectRules the visitor's answer must meet. See Validation Rules.
optionsarray or objectThe choices for selection fields.

Field Types

Text Input Fields
  • text: a single line of text.
  • textarea: several lines of text.
  • email: an email address, checked for a valid format.
  • phone: a phone number in international format, such as +15551234567.
Numeric Fields
  • number: a number. Use min and max to limit it.
Selection Fields
  • select: pick one option.
  • multiselect: pick several options.
  • groupselect: pick one option from named groups.
  • groupmultiselect: pick several options from named groups.

For select and multiselect, options is a list of { value, label }. For the grouped types, options is an object whose keys are the group names and whose values are lists of { value, label }.

File Upload Fields
  • image: an image upload. JPEG, PNG, GIF and WebP files of up to 2 MB are accepted. The submitted data holds the uploaded image's address.

Validation Rules

Each rule is an object with a value and an optional message shown when the rule fails.

Basic Validation
JavaScript
validation: {
  required: { value: true, message: "This field is required" },
  pattern: { value: "^[A-Z]{2}-\\d{5}$", message: "Use the format SL-20417" },
}
Length Validation
JavaScript
validation: {
  minLength: { value: 2, message: "At least 2 characters" },
  maxLength: { value: 80, message: "At most 80 characters" },
}
Numeric Validation
JavaScript
validation: {
  min: { value: 1, message: "At least 1" },
  max: { value: 100, message: "At most 100" },
}
Error Handling

Set defaultErrorMessage for any rule without its own message, and for format checks on email, phone, number and image fields:

JavaScript
validation: {
  required: { value: true },
  defaultErrorMessage: "Please check this field",
}

Without one, the form shows Please enter a valid value.

Advanced Configuration

Webhooks Integration

  1. Open the Action's Webhooks step

    Open your custom form Action and go to Webhooks: Send form data to webhook (optional).

    Webhooks: send each submission to your server.
  2. Add your endpoint

    Enter your endpoint's address under Webhook URL and select Create webhook. QwryAI creates a signing secret for it; copy it with Copy secret and keep it on your server.

    Each submission is sent as a {action name}_custom_form.submit event:

    JSON
    {
      "eventType": "learn_more_form_custom_form.submit",
      "chatbotId": "<agentId>",
      "payload": {
        "conversationId": "fd5ae9e1-9b30-4503-b346-ccd4d7ef16a3",
        "data": {
          "name": "Maya Chen",
          "email": "maya@example.com",
          "message": "Can we get a demo for a team of 12?"
        },
        "error": null
      }
    }

    error holds a message when an image upload failed. To check the x-qwryai-signature header, see the Webhook API Guide.

Troubleshooting

The form doesn't appear
  • Check that the key in registerFormSchema matches the Action's name exactly.
  • Make sure the registration code runs on the page where you're testing, after the embed code.
  • Test on your website, not in the Playground.
  • If the agent reaches the Action and nothing is registered, the browser console shows Form [name] not found.
Validation doesn't work
  • Each rule needs a value, such as required: { value: true }.
  • pattern takes a regular expression as a string; escape backslashes.
  • Disabled fields are never validated.
Options don't show
  • select and multiselect take a list of { value, label }.
  • The grouped types take an object of lists, keyed by group name.

Next Steps

Explore the documentation