Parameters
connectorSlug
:string
The URL Slug of the connector as configured in your Xkit dashboard, e.g.slack
.
Returns
Promise<Connection | ConnectionShell>
A Promise
that resolves to a Connection
object or a ConnectionShell
in the case that no Connection exists.
getConnectionOrConnector
calls the API in a way that makes it easier to handle the case when a user has not yet installed a given connector.
getConnection would return a 404
error, but this function will always return something that looks like a Connection
object, even if the user has not yet installed it.
In these cases, only the connection
property will be defined, and the others (enabled
, authorization
) will be undefined.
const slackConnection = await xkit.getConnectionOrConnector("slack")
if (slackConnection.enabled === true) {
console.log("installed slack!")
} else if (slackConnection.enabled === false) {
console.log("disabled slack installation :(")
} else {
console.log("they haven't installed slack yet!")
}