Skip to content

Commit e74d4aa

Browse files
Salesforce chat integration (#1017)
* Initial scaffolding for integration for salesforce enhanced chat * Rename a bunch of stuff and shorten titles * Add changeset * Fix description * Remove unused field * Sort variable like in the original script * Remoe unused variable from index * Fix desc * Consistent var sorting * Add assets and update manifest * Fix assets urls * Update CSPs --------- Co-authored-by: Addison <[email protected]>
1 parent 81949ad commit e74d4aa

File tree

9 files changed

+247
-4
lines changed

9 files changed

+247
-4
lines changed

.changeset/chubby-things-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-salesforce-chat': patch
3+
---
4+
5+
Salesforce chat integration.

bun.lock

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
},
114114
"integrations/formspree": {
115115
"name": "@gitbook/integration-formspree",
116-
"version": "0.2.11",
116+
"version": "0.2.12",
117117
"dependencies": {
118118
"@gitbook/runtime": "workspace:*",
119119
},
@@ -529,6 +529,18 @@
529529
"@gitbook/tsconfig": "workspace:*",
530530
},
531531
},
532+
"integrations/salesforce-chat": {
533+
"name": "@gitbook/integration-salesforce-chat",
534+
"version": "0.1.0",
535+
"dependencies": {
536+
"@gitbook/api": "*",
537+
"@gitbook/runtime": "*",
538+
},
539+
"devDependencies": {
540+
"@gitbook/cli": "workspace:*",
541+
"@gitbook/tsconfig": "workspace:*",
542+
},
543+
},
532544
"integrations/salesviewer": {
533545
"name": "@gitbook/integration-salesviewer",
534546
"version": "1.0.0",
@@ -567,7 +579,7 @@
567579
},
568580
"integrations/slack": {
569581
"name": "@gitbook/integration-slack",
570-
"version": "2.5.2",
582+
"version": "2.5.3",
571583
"dependencies": {
572584
"@gitbook/api": "*",
573585
"@gitbook/runtime": "*",
@@ -701,7 +713,7 @@
701713
},
702714
"packages/api": {
703715
"name": "@gitbook/api",
704-
"version": "0.143.1",
716+
"version": "0.143.2",
705717
"dependencies": {
706718
"event-iterator": "^2.0.0",
707719
"eventsource-parser": "^3.0.0",
@@ -756,7 +768,7 @@
756768
},
757769
"packages/runtime": {
758770
"name": "@gitbook/runtime",
759-
"version": "0.21.0",
771+
"version": "0.22.0",
760772
"dependencies": {
761773
"@gitbook/api": "*",
762774
},
@@ -1106,6 +1118,8 @@
11061118

11071119
"@gitbook/integration-runllm-widget": ["@gitbook/integration-runllm-widget@workspace:integrations/runllm-widget"],
11081120

1121+
"@gitbook/integration-salesforce-chat": ["@gitbook/integration-salesforce-chat@workspace:integrations/salesforce-chat"],
1122+
11091123
"@gitbook/integration-salesviewer": ["@gitbook/integration-salesviewer@workspace:integrations/salesviewer"],
11101124

11111125
"@gitbook/integration-segment": ["@gitbook/integration-segment@workspace:integrations/segment"],
9.25 KB
Loading
441 KB
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: salesforce-chat
2+
title: Salesforce Service Cloud Chat
3+
organization: gitbook
4+
description: Add Salesforce Service Cloud Chat to your published GitBook content
5+
visibility: public
6+
script: ./src/index.ts
7+
icon: ./assets/salesforce-icon.png
8+
previewImages:
9+
- ./assets/salesforce-visual.png
10+
externalLinks:
11+
- label: Documentation
12+
url: https://help.salesforce.com/s/articleView?id=service.miaw_intro_landing.htm&type=5
13+
scopes:
14+
- site:script:inject
15+
- site:script:cookies
16+
contentSecurityPolicy:
17+
script-src: |
18+
https://service.force.com
19+
https://*.force.com
20+
https://*.salesforce.com
21+
https://*.salesforce-scrt.com;
22+
connect-src: |
23+
https://*.force.com
24+
https://*.salesforce.com
25+
https://*.salesforce-scrt.com
26+
wss://*.salesforce.com
27+
wss://*.salesforce-scrt.com;
28+
img-src: |
29+
data:
30+
blob:
31+
https://*.force.com
32+
https://*.salesforce.com
33+
https://*.salesforce-scrt.com;
34+
frame-src: |
35+
https://*.force.com
36+
https://*.salesforce.com
37+
https://*.salesforce-scrt.com;
38+
style-src: |
39+
'unsafe-inline';
40+
summary: |
41+
# Overview
42+
43+
This integration injects Salesforce Service Cloud Chat into your published GitBook site, enabling a Salesforce support chat for your users.
44+
45+
# Configure
46+
47+
Provide the required Salesforce identifiers and URLs from your Embedded Service deployment in Salesforce Setup.
48+
categories:
49+
- analytics
50+
configurations:
51+
site:
52+
properties:
53+
org_id:
54+
type: string
55+
title: Salesforce Org ID
56+
description: The Salesforce Org ID (e.g., 00DxxxxxxxxxxxxXXX)
57+
messaging_deployment_name:
58+
type: string
59+
title: Deployment Name
60+
description: Name of your Messaging Deployment
61+
embedded_service_site_url:
62+
type: string
63+
title: Embedded Service Site URL
64+
description: Your Embedded Service site URL (e.g., https://yourdomain.my.site.com/SiteServiceMessagingforWebXXXX)
65+
scrt2_url:
66+
type: string
67+
title: SCRT2 URL
68+
description: Secure chat resource URL (e.g., https://yourdomain.my.salesforce-scrt.com)
69+
required:
70+
- org_id
71+
- messaging_deployment_name
72+
- embedded_service_site_url
73+
- scrt2_url
74+
target: site
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@gitbook/integration-salesforce-chat",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@gitbook/api": "*",
7+
"@gitbook/runtime": "*"
8+
},
9+
"devDependencies": {
10+
"@gitbook/cli": "workspace:*",
11+
"@gitbook/tsconfig": "workspace:*"
12+
},
13+
"scripts": {
14+
"typecheck": "tsc --noEmit",
15+
"publish-integrations-staging": "gitbook publish .",
16+
"check": "gitbook check",
17+
"publish-integrations": "gitbook publish ."
18+
}
19+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
createIntegration,
3+
FetchPublishScriptEventCallback,
4+
RuntimeContext,
5+
RuntimeEnvironment,
6+
} from '@gitbook/runtime';
7+
8+
import script from './script.raw.js';
9+
10+
type SFSCEnvironment = RuntimeEnvironment<
11+
{},
12+
{
13+
org_id?: string;
14+
messaging_deployment_name?: string;
15+
embedded_service_site_url?: string;
16+
scrt2_url?: string;
17+
}
18+
>;
19+
20+
type SFSCContext = RuntimeContext<SFSCEnvironment>;
21+
22+
export const handleFetchEvent: FetchPublishScriptEventCallback = async (
23+
_event,
24+
{ environment }: SFSCContext,
25+
) => {
26+
const cfg = environment.siteInstallation?.configuration || {};
27+
28+
const required = [
29+
'org_id',
30+
'messaging_deployment_name',
31+
'embedded_service_site_url',
32+
'scrt2_url',
33+
] as const;
34+
35+
for (const key of required) {
36+
if (!cfg[key]) {
37+
return;
38+
}
39+
}
40+
41+
const replaced = (script as string)
42+
.replace(/<ORG_ID>/g, String(cfg.org_id))
43+
.replace(/<MESSAGING_DEPLOYMENT_NAME>/g, String(cfg.messaging_deployment_name))
44+
.replace(/<EMBEDDED_SERVICE_SITE_URL>/g, String(cfg.embedded_service_site_url))
45+
.replace(/<SCRT2_URL>/g, String(cfg.scrt2_url));
46+
47+
return new Response(replaced, {
48+
headers: {
49+
'Content-Type': 'application/javascript',
50+
'Cache-Control': 'max-age=604800',
51+
},
52+
});
53+
};
54+
55+
export default createIntegration<SFSCContext>({
56+
fetch_published_script: handleFetchEvent,
57+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(function () {
2+
var ORG_ID = '<ORG_ID>';
3+
var MESSAGING_DEPLOYMENT_NAME = '<MESSAGING_DEPLOYMENT_NAME>';
4+
var EMBEDDED_SERVICE_SITE_URL = '<EMBEDDED_SERVICE_SITE_URL>';
5+
var SCRT2_URL = '<SCRT2_URL>';
6+
7+
var w = window;
8+
var d = document;
9+
10+
function loadScript(src, onload) {
11+
var s = d.createElement('script');
12+
s.type = 'text/javascript';
13+
s.async = true;
14+
s.src = src;
15+
s.onload = onload;
16+
var x = d.getElementsByTagName('script')[0];
17+
x.parentNode.insertBefore(s, x);
18+
}
19+
20+
function initMessaging() {
21+
if (!w.embeddedservice_bootstrap) {
22+
return;
23+
}
24+
25+
w.embeddedservice_bootstrap.settings.language = 'en_US';
26+
27+
try {
28+
w.embeddedservice_bootstrap.init(
29+
ORG_ID,
30+
MESSAGING_DEPLOYMENT_NAME,
31+
EMBEDDED_SERVICE_SITE_URL,
32+
{
33+
scrt2URL: SCRT2_URL,
34+
},
35+
);
36+
} catch (err) {
37+
// initialization failed
38+
}
39+
}
40+
41+
function onMessagingLoaded() {
42+
if (!w.embeddedservice_bootstrap) {
43+
return;
44+
}
45+
initMessaging();
46+
}
47+
48+
function bootstrap() {
49+
if (w.embeddedservice_bootstrap) {
50+
onMessagingLoaded();
51+
return;
52+
}
53+
54+
loadScript(
55+
EMBEDDED_SERVICE_SITE_URL.replace(/\/$/, '') + '/assets/js/bootstrap.min.js',
56+
onMessagingLoaded,
57+
);
58+
59+
if (w.GitBook) {
60+
w.GitBook.addEventListener('unload', function () {
61+
w.embeddedservice_bootstrap = undefined;
62+
});
63+
}
64+
}
65+
66+
if (w.attachEvent) {
67+
w.attachEvent('onload', bootstrap);
68+
} else {
69+
w.addEventListener('load', bootstrap, false);
70+
}
71+
})();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@gitbook/tsconfig/integration.json"
3+
}

0 commit comments

Comments
 (0)