Actions schema

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

Copy
Copied
interface Actions {
    [key: string]: ActionSchemaValue
}

The ActionSchemaValue is a JSON object with following properties

Properties

Property Description Value Type
id The unique identifier of the plugin string
display The value to be used to describe what the plugin does ActionSchemaValueDisplay
operation The operation to do when the user executes this plugin. It is a json schema which defines what action to perform. OperationSchema
fields The 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.

Property Description Value Type
label The label to show as the name of the plugin. string
description The description text to be shown to explain about the plugin string

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

Property Description Value Type
perform The function to be executed when the user executes this action plugin. It takes in SDK object and bundle object as arguments. function

Example

actions.jsindex.js
Copy
Copied
{
  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,
      },
    ],
  },
}
Copy
Copied
const actions = require("./src/actions");

module.exports = {
 ...
  actions: actions,
  ...
};
We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.