diff --git a/integrations/salesmartly/CHANGELOG.md b/integrations/salesmartly/CHANGELOG.md new file mode 100644 index 000000000..8b0689de2 --- /dev/null +++ b/integrations/salesmartly/CHANGELOG.md @@ -0,0 +1,7 @@ +# @gitbook/integration-salesmartly + +## 0.0.1 + +### Patch Changes + +- The first submission of the project, integrating salesmartly components diff --git a/integrations/salesmartly/assets/icon.png b/integrations/salesmartly/assets/icon.png new file mode 100644 index 000000000..a69cb2a04 Binary files /dev/null and b/integrations/salesmartly/assets/icon.png differ diff --git a/integrations/salesmartly/assets/salesmartly-preview.png b/integrations/salesmartly/assets/salesmartly-preview.png new file mode 100644 index 000000000..36a6560e0 Binary files /dev/null and b/integrations/salesmartly/assets/salesmartly-preview.png differ diff --git a/integrations/salesmartly/gitbook-manifest.yaml b/integrations/salesmartly/gitbook-manifest.yaml new file mode 100644 index 000000000..e4fdb3349 --- /dev/null +++ b/integrations/salesmartly/gitbook-manifest.yaml @@ -0,0 +1,66 @@ +name: salesmartly +title: Salesmartly +icon: ./assets/icon.png +organization: XKKpOzQCRtNWW2u1zORS +description: Add the Salesmartly chat widget to your published GitBook content +previewImages: + - ./assets/salesmartly-preview.png +externalLinks: + - label: Documentation + url: https://www.gitbook.com/integrations/salesmartly +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: + - site:script:inject + - site:script:cookies +contentSecurityPolicy: + script-src: | + https://assets.salesmartly.com + https://client.salesmartly.com + https://api.salesmartly.com + https://srz.salesmartly.com; + style-src: | + 'unsafe-inline' + assets.salesmartly.com; + img-src: | + data: + blob: + assets-cdn.salesmartly.com + assets.salesmartly.com + connect-src: | + wss://msg-ws.salesmartly.com + assets.salesmartly.com + form-action: | + msg.salesmartly.com + assets.salesmartly.com + media-src: | + assets-cdn.salesmartly.com + assets.salesmartly.com; + font-src: | + assets.salesmartly.com +summary: | + # Overview + + The Salesmartly integration for GitBook allows you to display the Salesmartly 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 Salesmartly 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 Application ID to finish the configuration. +categories: + - analytics +configurations: + site: + properties: + app_id: + type: string + title: Application ID + description: You can find it in your Salesmartly account. + required: + - app_id +target: site diff --git a/integrations/salesmartly/package.json b/integrations/salesmartly/package.json new file mode 100644 index 000000000..3175a1515 --- /dev/null +++ b/integrations/salesmartly/package.json @@ -0,0 +1,19 @@ +{ + "name": "@gitbook/integration-Salesmartly", + "version": "0.5.2", + "private": true, + "dependencies": { + "@gitbook/api": "*", + "@gitbook/runtime": "*" + }, + "devDependencies": { + "@gitbook/cli": "workspace:*", + "@gitbook/tsconfig": "workspace:*" + }, + "scripts": { + "typecheck": "tsc --noEmit", + "publish-integrations-staging": "gitbook publish .", + "check": "gitbook check", + "publish-integrations": "gitbook publish ." + } +} diff --git a/integrations/salesmartly/src/index.ts b/integrations/salesmartly/src/index.ts new file mode 100644 index 000000000..d4e6a11de --- /dev/null +++ b/integrations/salesmartly/src/index.ts @@ -0,0 +1,39 @@ +import { + createIntegration, + FetchPublishScriptEventCallback, + RuntimeContext, + RuntimeEnvironment, +} from '@gitbook/runtime'; + +import script from './script.raw.js'; + +type IntercomRuntimeContext = RuntimeContext< + RuntimeEnvironment< + {}, + { + app_id?: string; + } + > +>; + +export const handleFetchEvent: FetchPublishScriptEventCallback = async ( + event, + { environment }: IntercomRuntimeContext, +) => { + const appId = environment.siteInstallation?.configuration?.app_id; + + if (!appId) { + return; + } + + return new Response((script as string).replace('<TO_REPLACE>', appId), { + headers: { + 'Content-Type': 'application/javascript', + 'Cache-Control': 'max-age=604800', + }, + }); +}; + +export default createIntegration<IntercomRuntimeContext>({ + fetch_published_script: handleFetchEvent, +}); diff --git a/integrations/salesmartly/src/script.raw.js b/integrations/salesmartly/src/script.raw.js new file mode 100644 index 000000000..9b96ee7f8 --- /dev/null +++ b/integrations/salesmartly/src/script.raw.js @@ -0,0 +1,14 @@ +(function () { + const APP_ID = '<TO_REPLACE>'; + + var w = window; + + var d = document; + + var s = d.createElement('script'); + s.type = 'text/javascript'; + s.async = true; + s.src = 'https://assets.salesmartly.com/js/' + APP_ID + '.js'; + var x = d.getElementsByTagName('script')[0]; + x.parentNode.insertBefore(s, x); +})(); diff --git a/integrations/salesmartly/tsconfig.json b/integrations/salesmartly/tsconfig.json new file mode 100644 index 000000000..1a48f875b --- /dev/null +++ b/integrations/salesmartly/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@gitbook/tsconfig/integration.json" +}