Skip to content
Last updated

The Actions schema is the one which takes in a JSON string and adds dynamic UI on the Chatlayer Action Dialogs. These are also known as functional plugins or Data integrations. Each key in the schema is considered as a plugin in action dialog. And the value of that key will determine what UI components to show as well as what operation to do in there.

The type of Action Schema can be defined as

interface Actions {
    [key: string]: ActionSchemaValue
}

The ActionSchemaValue is a JSON object with following properties

Properties

PropertyDescriptionValue Type
idThe unique identifier of the pluginstring
displayThe value to be used to describe what the plugin doesActionSchemaValueDisplay
operationThe operation to do when the user executes this plugin. It is a json schema which defines what action to perform.OperationSchema
fieldsThe fields to show on the UI for user input. Can be considered as a form where the user can submit their data.Array of Fields schema

ActionSchemaValueDisplay

ActionSchemaValueDisplay is a JSON object with following properties.

PropertyDescriptionValue Type
labelThe label to show as the name of the plugin.string
descriptionThe description text to be shown to explain about the pluginstring

OperationSchema

This schema tells the App Integration framework what to do when the user executes this plugin. So this schema can be considered as the core of the action plugin. It describes the function that needs to run when this action plugin is executed. It has the following schema

PropertyDescriptionValue Type
performThe function to be executed when the user executes this action plugin. It takes in SDK object and bundle object as arguments.function

Example

{
  reply_ticket: {
    id: "reply_ticket",
    display: {
      label: "Add replies to a ticket",
      description:
        "Add replies to the ticket which sends an email to the ticket creator",
    },
    operation: {
      perform: async (sdk, bundle) => {
        let { ticket_no, body } = bundle.inputData;
        return sdk
          .request({
            method: "POST",
            url: `https://${bundle.authData.domain}.freshdesk.com/api/v2/tickets/${ticket_no}/reply`,
            body: {
              body,
            },
          })
          .then((res) => {
            if (res.status === 201) {
              return res.data;
            }
            throw new Error("Some thing went wrong");
          });
      },
    },
    fields: [
      {
        key: "ticket_no",
        label: "Ticket No",
        helpText:
          "Ticket Number ( Display ID) to which the reply has to be added.",
        required: true,
      },
      {
        key: "body",
        label: "Reply",
        type: "text",
        helpText: "The reply that needs to be added to the ticket.",
        required: true,
      },
    ],
  },
}
const actions = require("./src/actions");

module.exports = {
 ...
  actions: actions,
  ...
};