Plugins | Settings
Give Feedback

Examples

Updated on September 21, 2021

This guide provides you with some plugin settings examples, as well as their associated schemas.

👉 Settings are stored per-website. This allows each subscribed website to customize the settings of a plugin that is used.

Example Plugin Settings

Let's consider 2 example plugins:

  1. A simple plugin forwarding messages to the Twilio API, therefore storing user's Twilio tokens;
  2. A more advanced plugin storing automated message replies (to any message sent by a user), which would store a list of replies and patterns to match on;

1. Simple Plugin (Twilio forwarding)

How this plugin works

This plugin forwards messages sent in Crisp to a phone number on Twilio. It needs to store access tokens for each website subscribed to the plugin. Access tokens will be different for each website.

The plugin can be either configured (ie. an Twilio token is set), or non-configured (no Twilio token is set). The settings schema thus needs to allow a null token, or a string token with a specific format.

Associated settings schema

{
  "$id": "crisp:service:api/_schema/plugin#urn:acme-inc.com:twilio-forward:0",
  "type": "object",

  "properties": {
    "access_token": {
      "type": ["string", "null"],
      "pattern": "^([a-z0-9]){24}$"
    }
  },

  "required": [
    "access_token"
  ]
}

Explanations:

  • This schema, for Plugin URN urn:acme-inc.com:twilio-forward:0, ensures that settings is an object with the required property access_token set.
  • The access_token property either has its value set to null, or set to a string matching regular expression ^([a-z0-9]){24}$. The token, if set, must be made of exactly 24 lowercase alphanumeric characters.

Example settings payload

{
  "access_token": "90984d15addbc9e3a9855aza"
}

2. Advanced Plugin (message replies)

How this plugin works

This plugin acquires a list of response messages to send to any message sent by a user, which matches the provided text pattern.

For instance, a website could configure 2 automated replies on either: Hello or Goodbye, answering respectively with: Hey there! or Bye!. We would use * as the wildcard character to match anything (eg. Hello* would also match Hello world).

To limit against plugin abuse, we will limit the maximum number of automated replies to 100. At any time, the user can remove all their automated replies, therefore we allow the number of replies to be 0.

Associated settings schema

{
  "$id": "crisp:service:api/_schema/plugin#urn:acme-inc.com:message-replies:0",
  "type": "object",

  "properties": {
    "replies": {
      "type": "array",

      "items": {
        "type": "object",

        "properties": {
          "pattern": {
            "type": "string",
            "pattern": "^(.+)$"
          },

          "response": {
            "type": "string",
            "pattern": "(.+)"
          }
        },

        "required": [
          "pattern",
          "response"
        ]
      },

      "maxItems": 100
    }
  },

  "required": [
    "replies"
  ],

  "additionalProperties": false
}

Explanations:

  • This schema, for Plugin URN urn:acme-inc.com:message-replies:0, ensures that settings is an object with the required property replies set.
  • The replies property is an array, which can be empty or hold up to 100 values.
  • Each value in replies is an object, which contains required keys pattern and response, both non-empty strings.

Example settings payload

{
  "replies": [
    {
      "pattern": "Hello*",
      "response": "Hey there!"
    },

    {
      "pattern": "Goodbye*",
      "response": "Bye!"
    }
  ]
}

Configuring The Settings Schema

To configure the settings schema for a plugin, go to the Marketplace, then to your plugin, then Settings, and insert your JSON Schema as such:

The plugin schema can be configured in the Settings tab