Skip to content

Commit b0cf492

Browse files
Merge branch 'main' into front/fix-dark-light-mode
2 parents b23fa55 + d565165 commit b0cf492

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

.changeset/dull-seas-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-freshdesk': minor
3+
---
4+
5+
Update Freshdesk configuration options

integrations/freshdesk/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @gitbook/integration-freshdesk
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Switch configuration from widget ID to full widget URL, and inject that URL directly to support regional Freshworks widget domains.
8+
39
## 1.0.0
410

511
### Major Changes

integrations/freshdesk/gitbook-manifest.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ organization: gitbook
1919
contentSecurityPolicy:
2020
font-src: |
2121
freshdesk.com
22-
https://widget.freshworks.com;
22+
*.freshworks.com;
2323
script-src: |
24-
widget.freshworks.com;
24+
*.freshworks.com;
2525
style-src: |
2626
freshdesk.com
27-
https://widget.freshworks.com;
27+
*.freshworks.com;
2828
summary: |
2929
# Overview
3030
@@ -36,7 +36,7 @@ summary: |
3636
3737
# Configure
3838
39-
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.
39+
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 the full Freshdesk widget URL to finish the configuration. You can find this in your Freshworks account from the Embed Widget option.
4040
4141
categories:
4242
- analytics
@@ -45,8 +45,8 @@ configurations:
4545
properties:
4646
widget_id:
4747
type: string
48-
title: Freshdesk Widget ID
49-
description: Available in your Freshdesk dashboard, under the Widget section
48+
title: Widget URL
49+
description: Paste either your Freshdesk widget ID or the full widget URL from Freshworks Embed Widget.
5050
required:
5151
- widget_id
5252
target: site

integrations/freshdesk/src/index.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,53 @@ type FreshdeskRuntimeContext = RuntimeContext<
1616
>
1717
>;
1818

19+
function parseWidgetConfiguration(
20+
widgetInput?: string,
21+
): { widgetId: string; widgetURL: string } | null {
22+
if (!widgetInput?.trim()) {
23+
return null;
24+
}
25+
26+
const value = widgetInput.trim();
27+
28+
try {
29+
const parsedURL = new URL(value);
30+
const widgetId = parsedURL.pathname.match(/\/widgets\/([^/]+)\.js$/)?.[1];
31+
if (!widgetId) {
32+
return null;
33+
}
34+
35+
return {
36+
widgetId,
37+
widgetURL: parsedURL.toString(),
38+
};
39+
} catch {
40+
return {
41+
widgetId: value,
42+
widgetURL: `https://widget.freshworks.com/widgets/${value}.js`,
43+
};
44+
}
45+
}
46+
1947
export const handleFetchEvent: FetchPublishScriptEventCallback = async (
2048
event,
2149
{ environment }: FreshdeskRuntimeContext,
2250
) => {
23-
const widgetId = environment.siteInstallation?.configuration?.widget_id;
24-
if (!widgetId) {
51+
const widgetInput = environment.siteInstallation?.configuration?.widget_id;
52+
const widgetConfig = parseWidgetConfiguration(widgetInput);
53+
if (!widgetConfig) {
2554
throw new Error(
26-
`The Freshdesk Widget ID is missing from the configuration (ID: ${
55+
`The Freshdesk widget configuration is invalid. Expected a widget ID or a full URL ending with /widgets/<widget_id>.js (ID: ${
2756
'spaceId' in event ? event.spaceId : event.siteId
2857
}).`,
2958
);
3059
}
3160

32-
return new Response((script as string).replaceAll('<TO_REPLACE>', widgetId), {
61+
const scriptContent = (script as string)
62+
.replaceAll('<WIDGET_ID>', widgetConfig.widgetId)
63+
.replaceAll('<WIDGET_URL>', widgetConfig.widgetURL);
64+
65+
return new Response(scriptContent, {
3366
headers: {
3467
'Content-Type': 'application/javascript',
3568
'Cache-Control': 'max-age=604800',

integrations/freshdesk/src/script.raw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
window.fwSettings = {
2-
widget_id: '<TO_REPLACE>',
2+
widget_id: '<WIDGET_ID>',
33
};
44
!(function () {
55
if ('function' != typeof window.FreshworksWidget) {
@@ -14,7 +14,7 @@ window.fwSettings = {
1414
(function () {
1515
var s = document.createElement('script');
1616
s.type = 'text/javascript';
17-
s.src = 'https://widget.freshworks.com/widgets/<TO_REPLACE>.js';
17+
s.src = '<WIDGET_URL>';
1818
s.async = true;
1919
s.defer = true;
2020
document.getElementsByTagName('head')[0].appendChild(s);

0 commit comments

Comments
 (0)