Scenario

If the bot was not able to answer a user’s question, you can optionally show a contact support button which can be configured to either open a customizable form or call a custom callback function. The form can be configured to collect whatever information you would like and you may optionally include information about the user’s chat session which can then be turned into a support ticket. The callback function can be used to initiate a live chat.

Example

import { type InkeepAIChatSettings, type FormConfig } from "@inkeep/widgets";

const supportFormConfig: FormConfig = {
  heading: "Contact support",
  fields: [
    {
      type: "STANDARD_FIELD",
      label: "Name",
      name: "first_name",
      inputType: "TEXT",
    },
    {
      type: "STANDARD_FIELD",
      label: "Email",
      name: "email",
      inputType: "EMAIL",
      required: true,
    },
    {
      type: "INCLUDE_CHAT_SESSION",
      defaultValue: true,
    },
    {
      type: "STANDARD_FIELD",
      label: "Additional details",
      name: "additional_details",
      inputType: "TEXTAREA",
    },
  ],
  submitCallback: (values) => {
    // replace with your own api call to create a support ticket
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ success: true });
      }, 2000);
    });
  },
};

const inkeepAIChatSettings: InkeepAIChatSettings = {
  //... rest of inkeepAIChatSettings
  includeAIAnnotations: {
    shouldEscalateToSupport: true,
  },
  aiAnnotationPolicies: {
    shouldEscalateToSupport: [
      {
        threshold: "STANDARD", // "STRICT" or "STANDARD"
        action: {
          type: "SHOW_SUPPORT_BUTTON",
          label: "Contact Support",
          icon: { builtIn: "LuUsers" },
          action: {
            type: "OPEN_FORM",
            formConfig: supportFormConfig,
          },
        },
      },
    ],
  },
};

IncludeAIAnnotations

This is currently an enterprise preview feature.

PropertyTypeDescription
shouldEscalateToSupportbooleanWhether or not to include the shouldEscalateToSupport annotation.

AIAnnotationPolicies

Be sure to include the corresponding property in includeAIAnnotations.

PropertyTypeDescription
shouldEscalateToSupportShouldEscalateToSupportPolicy[]Policies for shouldEscalateToSupport.

ShouldEscalateToSupportPolicy

PropertyTypeDescription
threshold"STANDARD" | "STRICT"Support threshold. "STRICT" indicates that the bot is very confident about support escalation while "STANDARD" is lower threshold.
actionShowEscalateToSupportButtonActionAction to take when support escalation threshold is met.

ShowEscalateToSupportButtonAction

PropertyTypeDescription
type"SHOW_SUPPORT_BUTTON"Type of action.
labelstringButton label.
iconCustomIconIcon that goes next to the button label. See here for details.
actionOpenFormAction | InvokeCallbackActionType of action to take when button is clicked.

OpenFormAction

PropertyTypeDescription
type"OPEN_FORM"Type of action.
formConfigFormConfigCustom form configuration. See here for details.

InvokeCallbackAction

PropertyTypeDescription
type"INVOKE_CALLBACK"Type of action.
callback() => voidCallback to be invoked when the button is clicked.
shouldCloseModalbooleanDetermines whether the chat modal should close when the callback is invoked. Default is false.

FormConfig

PropertyTypeDescription
headingstringHeading of the form.
descriptionstringDescription of the form.
fields(FormField | IncludeChatSessionField)[]Required. Fields to include in the form. See here for details.
submitButtonLabelstringLabel for the form submit button. Default is Submit.
submitCallback(values: SubmitCallbackArgs) => Promise<{ success: boolean }>Required. Function that is called when the form is submitted. See here for details.
successConfirmationPageSuccessConfirmationPagePropsConfiguration for the confirmation page that is displayed when the form has successfully been submitted. See here for details.
closeFormActionBackToChatFormAction | ModalCloseFormActionThe type of close action that will be called when the button is clicked. Default is BackToChatFormAction. See here for details.

FormField

PropertyTypeDescription
type"STANDARD_FIELD"Required.
namestringRequired. Name of the input, this will be the key of the input's value in the form data, therefore it must be unique.
labelstringRequired. Label for the input.
inputTypeCHECKBOX | EMAIL | TEXT | TEXTAREARequired. Type of input to display.
placeholderstringPlaceholder text for the input.
requiredbooleanWhether or not the field is required. Default is false.
defaultValuestring | booleanDefault value to populate the input with.
isHiddenbooleanWhether or not to show the field in the form. Default is false.

IncludeChatSessionField

If this field is included in the form and the value is true, the arguments supplied to submitCallback will include the chat session information. If it is not included or the value is false, chatSession will be null. The name of this field in the form values will be include_chat_session. If you would like to automatically include the chat session information without showing this field in the form, set isHidden to true and defaultValue to true. If there is no chatSession data (because the user didn't ask any questions yet), this field will be automatically hidden and set to required: false.

PropertyTypeDescription
type"INCLUDE_CHAT_SESSION"Required.
labelstringLabel for the checkbox. Default is Include chat history.
requiredbooleanWhether or not the field is required. Default is false.
defaultValuebooleanDefault value to populate the input with. Default is false.
isHiddenbooleanWhether or not to show the field in the form. Default is false.

SubmitCallback

The submitCallback is called when the form is submitted. It will be called with the following arguments and should return a Promise that resolves to { success: boolean }.

PropertyTypeDescription
formDetailsFieldValuesAn object containing the form values where the key is the input name and the value is the input value.
chatSessionChatSession | nullDetails about the chat session, only included if include_chat_session is true. See here for details.
clientClientDetails about the client. See here for details.

ChatSession

PropertyTypeDescription
chatSessionIdstringId for the chat session.
messagesMessage[]Messages from the chat session.

Client

PropertyTypeDescription
currentUrlstringURL that the user was on when the form was submitted.

SuccessConfirmationPageProps

PropertyTypeDescription
headingstringThe success message heading. Default is Thank you!.
messagestringThe success message. Default is Your form has been submitted successfully..
successConfirmationButtonSuccessConfirmationButtonConfiguration for the button on the success confirmation page. If not included, the button will not be displayed.

SuccessConfirmationButton

PropertyTypeDescription
labelstringThe button label.
iconCustomIconThe icon to the left of the button label. See here for details.
closeFormActionBackToChatFormAction | ModalCloseFormActionThe type of close action that will be called when the button is clicked. Default is BackToChatFormAction. See here for details.

BackToChatFormAction

PropertyTypeDescription
type"BACK_TO_CHAT"Will navigate back to the AI Chat view.

ModalCloseFormAction

PropertyTypeDescription
type"CLOSE_MODAL"Will close the modal (not applicable for the EmbeddedChat).