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.

ParamRequiredTypeDescription
[slug]optionalStringThe application slug

Note: instance method of Cobalt Returns: Promise.<Application> - The application details.

cobalt.getApp()  // to get a list of all apps
cobalt.getApp("slack")  // to get details of a single app, e.g. 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.

ParamRequiredTypeDescription
[slug]MandatoryStringThe application slug
PayloadOptionalObjectThe key value pairs of auth data

Note: instance method of Cobalt Returns: Promise.<Application> - The application details.

cobalt.connect("slack") // opens a new tab for oauth apps
cobalt.connect("twilio", {
  number: 1234567890,
  sid: "ACCOUNT_SID",
}) // saves the auth data for key based apps
// returns `true` if connection was successful

.disconnect()

Disconnect the specified application and remove any associated data from Cobalt.

ParamRequiredTypeDescription
[slug]MandatoryStringThe application slug
cobalt.disconnect("slack")
// no response

.config()

Returns the specified config, or creates one if it doesn’t exist.

ParamRequiredTypeDescription
payloadMandatoryconfigPayloadJson payload for config

The configPayload object.

NameTypeDescription
slugStringThe application slug
[config_id]StringUnique id for the config
labelsObject<string, Array<labels>>The dynamic label mappings
cobalt.config({
  slug: "slack",
  config_id: "OPTIONAL_ID_FOR_THIS_CONFIG",
  labels: {}, // optional dynamic 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.

ParamRequiredTypeDescription
payloadMandatoryupdateConfigPayloadJson payload for config

The updateConfigPayload configuration data for an application.

NameRequiredTypeDescription
slugMandatoryStringThe application slug.
[config_id]OptionalStringUnique ID for the config.
fieldsOptionalObjectA map of application fields and their values.
workflowsOptionalArray.<WorkflowPayload>Whether the workflow is enabled.

The WorkflowPayload data

NameRequiredTypeDescription
idMandatoryStringThe ID of the workflow.
enabled]MandatoryBooleanWhether the workflow is enabled
fieldsMandatoryObject<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.

ParamRequiredTypeDescription
slugMandatoryslugThe application slug.
configIdoptionalStringThe unique ID of the config.
cobalt.deleteConfig("slack", "OPTIONAL_ID_FOR_THIS_CONFIG")
// promise resolves if config is successfully deleted