This guide provides you with some plugin settings examples, as well as their associated schemas.
Example Plugin Settings
Let's consider 2 example plugins:
- A simple plugin forwarding messages to the Twilio API, therefore storing user's Twilio tokens;
- 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 propertyaccess_tokenset. - The
access_tokenproperty either has its value set tonull, or set to astringmatching 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).
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 propertyrepliesset. - The
repliesproperty is anarray, which can be empty or hold up to100values. - Each value in
repliesis anobject, which contains required keyspatternandresponse, 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:
