You can refer to the Cobalt’s GitHub repo for Javascript SDK here.
Install
First, install @cobaltio/cobalt-js
and via the terminal.
npm install --save @cobaltio/cobalt-js
Initialise
Import Cobalt
and initialise it.
import { Cobalt } from "@cobaltio/cobalt-js";
const cobalt = new Cobalt({ token: "COBALT_SESSION_TOKEN" });
.getApp()
Returns the application details for the specified application, provided the application is enabled in Cobalt. If no application is specified, it returns
all the enabled applications.
Param | Required | Type | Description |
---|
[slug] | optional | String | The application slug |
Note: instance method of Cobalt
Returns: Promise.<Application>
- The application details.
cobalt.getApp()
cobalt.getApp("slack")
Example Response:
{
"name": "Slack",
"icon": "https://cobalt-app-logos.s3.ap-south-1.amazonaws.com/slack/logo.png",
"description": "Slack is a platform for team communication: everything in one place, instantly searchable, available wherever you go. Offering instant messaging, document sharing and knowledge search for modern teams.",
"auth_type": "oauth2",
"type": "slack",
"app_id": "64c357c739ec788238ab5f95",
"tags": [
"Communication"
],
"version": {
"_v": "1.0.0",
"description": "Slack is a platform for team communication: everything in one place, instantly searchable, available wherever you go. Offering instant messaging, document sharing and knowledge search for modern teams."
},
"slug": "slack",
"reauth_required": false
}
.connect()
Returns the application details for the specified application, provided the application is enabled in Cobalt. If no application is specified, it returns all the enabled applications.
Param | Required | Type | Description |
---|
[slug] | Mandatory | String | The application slug |
Payload | Optional | Object | The key value pairs of auth data |
Note: instance method of Cobalt
Returns: Promise.<Application>
- The application details.
cobalt.connect("slack")
cobalt.connect("twilio", {
number: 1234567890,
sid: "ACCOUNT_SID",
})
// returns `true` if connection was successful
.disconnect()
Disconnect the specified application and remove any associated data from Cobalt.
Param | Required | Type | Description |
---|
[slug] | Mandatory | String | The application slug |
cobalt.disconnect("slack")
.config()
Returns the specified config, or creates one if it doesn’t exist.
Param | Required | Type | Description |
---|
payload | Mandatory | configPayload | Json payload for config |
The configPayload
object.
Name | Type | Description |
---|
slug | String | The application slug |
[config_id] | String | Unique id for the config |
labels | Object<string, Array<labels>> | The dynamic label mappings |
cobalt.config({
slug: "slack",
config_id: "OPTIONAL_ID_FOR_THIS_CONFIG",
labels: {},
})
Example response:
{
"slug": "slack",
"config_id": "OPTIONAL_ID_FOR_THIS_CONFIG",
"fields": [
{
"required": false,
"id": "64da0b57c9ae95561bb0a24d",
"name": "Channel",
"field_type": "select",
"options": [
{
"name": "general",
"value": "C044U7Q074J"
}
],
"labels": []
}
],
"workflows": [
{
"id": "64d1fac58716dc5065127ffe",
"name": "Send message in a channel",
"description": "",
"enabled": false,
"fields": [
{
"required": false,
"id": "64da0b57c9ae95561bb0a24f",
"name": "Channel",
"field_type": "select",
"options": [
{
"name": "general",
"value": "C044U7Q074J"
}
],
"labels": []
}
]
}
],
"field_errors": []
}
.updateConfig()
Update the specified config.
Param | Required | Type | Description |
---|
payload | Mandatory | updateConfigPayload | Json payload for config |
The updateConfigPayload
configuration data for an application.
Name | Required | Type | Description |
---|
slug | Mandatory | String | The application slug. |
[config_id] | Optional | String | Unique ID for the config. |
fields | Optional | Object | A map of application fields and their values. |
workflows | Optional | Array.<WorkflowPayload> | Whether the workflow is enabled. |
The WorkflowPayload
data
Name | Required | Type | Description |
---|
id | Mandatory | String | The ID of the workflow. |
enabled] | Mandatory | Boolean | Whether the workflow is enabled |
fields | Mandatory | Object<string, (string or number or boolean)> | A map of workflow fields and their values. |
cobalt.updateConfig({
slug: "slack",
config_id: "OPTIONAL_ID_FOR_THIS_CONFIG",
fields: {
"64da0b57c9ae95561bb0a24d": "C044U7Q074J"
},
workflows: [
{
id: "64d1fac58716dc5065127ffe",
enabled: true,
fields: {
"64da0b57c9ae95561bb0a24f": "C044U7Q074J"
}
}
]
})
Example response:
{
"slug": "slack",
"config_id": "OPTIONAL_ID_FOR_THIS_CONFIG",
"fields": [
{
"required": false,
"id": "64da0b57c9ae95561bb0a24d",
"name": "Channel",
"field_type": "select",
"options": [
{
"name": "general",
"value": "C044U7Q074J"
}
],
"labels": [],
value: "C044U7Q074J"
}
],
"workflows": [
{
"id": "64d1fac58716dc5065127ffe",
"name": "Send message in a channel",
"description": "",
"enabled": false,
"fields": [
{
"required": false,
"id": "64da0b57c9ae95561bb0a24f",
"name": "Channel",
"field_type": "select",
"options": [
{
"name": "general",
"value": "C044U7Q074J"
}
],
"labels": [],
value: "C044U7Q074J"
}
]
}
],
"field_errors": []
}
.deleteConfig()
Delete the specified config.
Param | Required | Type | Description |
---|
slug | Mandatory | slug | The application slug. |
configId | optional | String | The unique ID of the config. |
cobalt.deleteConfig("slack", "OPTIONAL_ID_FOR_THIS_CONFIG")
// promise resolves if config is successfully deleted