App Schema
Your app schema is defined in the index.js
file. The app schema defines all the configurations as well as the plugins
that your app creates. The app schema is a defined in JSON format. When you scaffold an app, a default schema is
created.
{
"id": "YOUR_APP_NAME",
"version": "YOUR_APP_VERSION",
"platformVersion": "APP_PLATFORM_VERSION",
"authentication": "THE_AUTHENTICATION_SCHEMA",
"beforeRequest": "THE_BEFORE_REQUEST_SCHEMA",
"afterResponse": "THE_AFTER_REQUEST_SCHEMA",
"actions": "THE_ACTIONS_SCHEMA",
"messaging": "THE_MESSAGING_SCHEMA",
"resources": "THE_RESOURCES_SCHEMA"
}
PROPERTIES
PROPERTIES | DESCRIPTION | VALUE TYPE | DEFAULT VALUE |
---|---|---|---|
id | The identifier of your App | string | |
version | The version of your app | number | version specified in package.json |
platformVersion | The version of app-platform package you used to create the app | number | version specified in package.json of the @chatlayerai/app-platform in node modules. |
authentication | The authentication schema. This schema is used to authenticate the accounts which will be used in this app | Authentication Schema | {} |
beforeRequest | The schema of things to do before calling sdk.request method. They are the middlewares that you add before making any sdk request. | Array of functions | [] |
afterResponse | The schema of things to do after calling sdk.request | Array of functions | [] |
actions | The schema of plugins that you want to create which shows up in Action Dialogstate in chatlayer. | Actions Schema | {} |
messaging | The schema of sending and receiving messages from different channels like whatsapp, facebook messenger etc.. | Messaging Schema | {} |
resources | The schema of the resources that you want to provide to the app. This can be used later | Resources Schema | {} |
Example
const includeApiKey = (request, sdk, bundle) => {
if (bundle.authData.api_key) {
request.headers = {
...request.headers,
"Content-Type": "application/json",
Authorization: `Bearer ${bundle.authData.api_key}`,
};
}
return request;
};
const authenticationConfig = {
type: "custom",
test: (sdk, bundle) => {
return sdk
.request({
url: `https://${bundle.authData.host}/v2/agents`,
})
.then((res) => {
if (res.status === 400) {
throw new Error("Invalid region");
}
if (res.status === 401) {
throw new Error("Invalid API key");
}
});
},
connectionLabel: () => "FreshChat",
fields: [
{
key: "host",
label: "Region",
placeholder: "Choose your datacenter region",
default: "api.freshchat.com",
choices: {
"api.freshchat.com": "United States",
"api.eu.freshchat.com": "Europe",
"api.in.freshchat.com": "India",
"api.au.freshchat.com": "Australia",
},
},
{
key: "api_key",
label: "API Key",
required: true,
helpText:
"You can generate an API Key by login to your FreshChat account and navigating to Admin > API Tokens > Generate Token",
},
],
}
module.exports = {
version: require("./package.json").version,
platformVersion: require("@chatlayerai/app-platform").version,
id: "freshdesk-messaging",
authentication: authenticationConfig,
beforeRequest: [includeApiKey],
actions: {},
messaging,
resources: {},
};