-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial code for crisp integration * Update script * Update configuration * Add image, update package lock
- Loading branch information
1 parent
ac68b22
commit fc8b0e5
Showing
9 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@gitbook/eslint-config/integration"] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@gitbook/tsconfig/integration.json" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.