diff --git a/.changeset/odd-buttons-send.md b/.changeset/odd-buttons-send.md new file mode 100644 index 000000000..ba495f0b2 --- /dev/null +++ b/.changeset/odd-buttons-send.md @@ -0,0 +1,5 @@ +--- +'@gitbook/integration-freshdesk': major +--- + +Initial publish diff --git a/bun.lock b/bun.lock index 2e1c387c5..fec631982 100644 --- a/bun.lock +++ b/bun.lock @@ -122,6 +122,18 @@ "@gitbook/tsconfig": "workspace:*", }, }, + "integrations/freshdesk": { + "name": "@gitbook/integration-freshdesk", + "version": "0.1.0", + "dependencies": { + "@gitbook/api": "*", + "@gitbook/runtime": "*", + }, + "devDependencies": { + "@gitbook/cli": "workspace:*", + "@gitbook/tsconfig": "workspace:*", + }, + }, "integrations/front": { "name": "@gitbook/integration-front", "version": "1.0.0", @@ -531,7 +543,7 @@ }, "integrations/salesforce-chat": { "name": "@gitbook/integration-salesforce-chat", - "version": "0.1.0", + "version": "0.1.1", "dependencies": { "@gitbook/api": "*", "@gitbook/runtime": "*", @@ -1056,6 +1068,8 @@ "@gitbook/integration-formspree": ["@gitbook/integration-formspree@workspace:integrations/formspree"], + "@gitbook/integration-freshdesk": ["@gitbook/integration-freshdesk@workspace:integrations/freshdesk"], + "@gitbook/integration-front": ["@gitbook/integration-front@workspace:integrations/front"], "@gitbook/integration-fullstory": ["@gitbook/integration-fullstory@workspace:integrations/fullstory"], diff --git a/integrations/freshdesk/assets/freshworks-icon.png b/integrations/freshdesk/assets/freshworks-icon.png new file mode 100644 index 000000000..7288e4d5e Binary files /dev/null and b/integrations/freshdesk/assets/freshworks-icon.png differ diff --git a/integrations/freshdesk/assets/freshworks-visual.png b/integrations/freshdesk/assets/freshworks-visual.png new file mode 100644 index 000000000..e79afdba8 Binary files /dev/null and b/integrations/freshdesk/assets/freshworks-visual.png differ diff --git a/integrations/freshdesk/gitbook-manifest.yaml b/integrations/freshdesk/gitbook-manifest.yaml new file mode 100644 index 000000000..60499f77d --- /dev/null +++ b/integrations/freshdesk/gitbook-manifest.yaml @@ -0,0 +1,52 @@ +name: freshdesk +title: Freshdesk +icon: ./assets/freshworks-icon.png +previewImages: + - ./assets/freshworks-visual.png +description: Add the Freshdesk chat widget to your published GitBook content. +externalLinks: + - label: Website + url: https://freshdesk.com/ + - label: Documentation + url: https://support.freshdesk.com/support/solutions/articles/239273-set-up-your-help-widget +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 +organization: gitbook +contentSecurityPolicy: + font-src: | + freshdesk.com + https://widget.freshworks.com; + script-src: | + widget.freshworks.com; + style-src: | + freshdesk.com + https://widget.freshworks.com; +summary: | + # Overview + + The Freshdesk integration for GitBook allows you to display the Freshdesk 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 sites will fetch the Freshdesk chat widget script and inject it in your published content. + + # Configure + + You can configure the integration on single or multiple public sites by navigating to the integrations in sub-navigation or org settings. You will then have to provide Freshdesk widget ID to finish the configuration. This can be found in your Freshdesk dashboard, under the Widget section. + +categories: + - analytics +configurations: + site: + properties: + widget_id: + type: string + title: Freshdesk Widget ID + description: Available in your Freshdesk dashboard, under the Widget section + required: + - widget_id +target: site diff --git a/integrations/freshdesk/package.json b/integrations/freshdesk/package.json new file mode 100644 index 000000000..7c0c11960 --- /dev/null +++ b/integrations/freshdesk/package.json @@ -0,0 +1,19 @@ +{ + "name": "@gitbook/integration-freshdesk", + "version": "0.1.0", + "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/freshdesk/src/index.ts b/integrations/freshdesk/src/index.ts new file mode 100644 index 000000000..72f7a0d85 --- /dev/null +++ b/integrations/freshdesk/src/index.ts @@ -0,0 +1,42 @@ +import { + createIntegration, + FetchPublishScriptEventCallback, + RuntimeContext, + RuntimeEnvironment, +} from '@gitbook/runtime'; + +import script from './script.raw.js'; + +type FreshdeskRuntimeContext = RuntimeContext< + RuntimeEnvironment< + {}, + { + widget_id?: string; + } + > +>; + +export const handleFetchEvent: FetchPublishScriptEventCallback = async ( + event, + { environment }: FreshdeskRuntimeContext, +) => { + const widgetId = environment.siteInstallation?.configuration?.widget_id; + if (!widgetId) { + throw new Error( + `The Freshdesk Widget ID is missing from the configuration (ID: ${ + 'spaceId' in event ? event.spaceId : event.siteId + }).`, + ); + } + + return new Response((script as string).replaceAll('', widgetId), { + headers: { + 'Content-Type': 'application/javascript', + 'Cache-Control': 'max-age=604800', + }, + }); +}; + +export default createIntegration({ + fetch_published_script: handleFetchEvent, +}); diff --git a/integrations/freshdesk/src/script.raw.js b/integrations/freshdesk/src/script.raw.js new file mode 100644 index 000000000..a830ef1fb --- /dev/null +++ b/integrations/freshdesk/src/script.raw.js @@ -0,0 +1,21 @@ +window.fwSettings = { + widget_id: '', +}; +!(function () { + if ('function' != typeof window.FreshworksWidget) { + var n = function () { + n.q.push(arguments); + }; + n.q = []; + window.FreshworksWidget = n; + } +})(); + +(function () { + var s = document.createElement('script'); + s.type = 'text/javascript'; + s.src = 'https://widget.freshworks.com/widgets/.js'; + s.async = true; + s.defer = true; + document.getElementsByTagName('head')[0].appendChild(s); +})(); diff --git a/integrations/freshdesk/tsconfig.json b/integrations/freshdesk/tsconfig.json new file mode 100644 index 000000000..1a48f875b --- /dev/null +++ b/integrations/freshdesk/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@gitbook/tsconfig/integration.json" +}