Skip to content

Commit

Permalink
Add Crisp integration (#494)
Browse files Browse the repository at this point in the history
* Add initial code for crisp integration

* Update script

* Update configuration

* Add image, update package lock
  • Loading branch information
addisonschultz authored Jul 8, 2024
1 parent ac68b22 commit fc8b0e5
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 0 deletions.
3 changes: 3 additions & 0 deletions integrations/crisp/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@gitbook/eslint-config/integration"]
}
Binary file added integrations/crisp/assets/crisp-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added integrations/crisp/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions integrations/crisp/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: crisp
title: Crisp
icon: ./assets/icon.png
previewImages:
- ./assets/crisp-preview.png
description: Add the Crisp chat widget to your published GitBook content.
externalLinks:
- label: Website
url: https://crisp.chat/en/
visibility: public
script: ./src/index.ts
# The following scope(s) are available only to GitBook Staff
# See https://developer.gitbook.com/integrations/configurations#scopes
scopes:
- space:script:inject
- site:script:inject
organization: gitbook
contentSecurityPolicy:
script-src: |
client.crisp.chat;
style-src: |
client.crisp.chat;
https://client.crisp.chat
summary: |
# Overview
The Crisp integration for GitBook allows you to display the Crisp chat widget on your public documentation to connect and interact with your readers.
# How it works
Automatic chat widget on your documentation: Each of your connected GitBook spaces will fetch the Crisp chat widget script and inject it in your published content.
# Configure
You can configure the integration on single or multiple public spaces by navigating to the integrations in sub-navigation or org settings. You will then have to provide Crisp website ID to finish the configuration. This can be found in the URL from your Crisp dashboard.
categories:
- analytics
configurations:
space:
properties:
tracking_id:
type: string
title: Crisp Site ID
description: Available in the URL from your Crisp dashboard
required:
- tracking_id
site:
properties:
tracking_id:
type: string
title: Crisp Site ID
description: Available in the URL from your Crisp dashboard
required:
- tracking_id
18 changes: 18 additions & 0 deletions integrations/crisp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@gitbook/integration-crisp",
"version": "0.0.1",
"private": true,
"dependencies": {
"@gitbook/api": "*",
"@gitbook/runtime": "*"
},
"devDependencies": {
"@gitbook/cli": "*"
},
"scripts": {
"lint": "eslint ./src/**/*.ts",
"typecheck": "tsc --noEmit",
"publish-integrations-staging": "gitbook publish .",
"publish-integrations": "gitbook publish ."
}
}
44 changes: 44 additions & 0 deletions integrations/crisp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment,
} from '@gitbook/runtime';

import script from './script.raw.js';

type CrispRuntimeContext = RuntimeContext<
RuntimeEnvironment<
{},
{
tracking_id?: string;
}
>
>;

export const handleFetchEvent: FetchPublishScriptEventCallback = async (
event,
{ environment }: CrispRuntimeContext
) => {
const trackingId =
environment.siteInstallation?.configuration?.tracking_id ??
environment.spaceInstallation.configuration.tracking_id;
if (!trackingId) {
throw new Error(
`The Crisp Website ID is missing from the configuration (ID: ${
'spaceId' in event ? event.spaceId : event.siteId
}).`
);
}

return new Response(script.replace('<TO_REPLACE>', trackingId), {
headers: {
'Content-Type': 'application/javascript',
'Cache-Control': 'max-age=604800',
},
});
};

export default createIntegration<CrispRuntimeContext>({
fetch_published_script: handleFetchEvent,
});
11 changes: 11 additions & 0 deletions integrations/crisp/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function (d, s) {
const trackingID = '<TO_REPLACE>';
window.$crisp = [];
window.CRISP_WEBSITE_ID = trackingID;

d = document;
s = d.createElement('script');
s.src = 'https://client.crisp.chat/l.js';
s.async = 1;
d.getElementsByTagName('head')[0].appendChild(s);
})(window, document);
3 changes: 3 additions & 0 deletions integrations/crisp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@gitbook/tsconfig/integration.json"
}
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc8b0e5

Please sign in to comment.