@go1/go1-embedding-js-sdk
v0.0.69
Published
A Javascript library to embed Go1 content into your website.
Downloads
226
Readme
Go1 Embedding JS SDK
A Javascript library to embed Go1 content into your website. Includes two-way messaging between your site and the Go1 content view.
This library is intended to be used with codebases that support CommonJS modules (e.g. esbuild, webpack, babel, and more.) If you are looking for a pure browser only implementation, please see our developer docs.
Installation
npm install @go1/go1-embedding-js-sdk
Usage
Prepare a <div>
in your HTML that will be the parent to the Go1 iframe and be sure to give it an id
. We'll use that id
later.
<body>
...
<div id="go1-chat-window" />
...
</body>
Run the go1Init
function from this library to insert the Go1 content view as a child of the <div>
.
import { go1Init } from '@go1/go1-embedding-js-sdk';
const onGo1MessageReceived = (message) => {
console.log('Received postMessage from Go1');
console.log(message);
};
const options = {
feature: 'ai-chat',
iframeParentId: 'go1-chat-window',
onGo1MessageReceived,
};
const sendMessageToGo1 = go1Init(options); // will insert the iframe as a child of `<div id="go1-chat-window" />`, and return a function with which to send messages to the iframe.
APIs
Types
export type OnGo1MessageReceived = (message: Go1Message) => void;
export type SendMessageToGo1 = (message: Go1Message) => void;
export type IframesMap = { [key: string]: HTMLIFrameElement };
export interface AdditionalInfoMessage {
additionalUserInfo?: AdditionalUserInfo;
featureAttributes?: FeatureAttributes;
themeInformation?: ThemeInformation;
}
export interface ThemeInformation {
/** Hex string, starting with a #. Example #0437F2 */
accent: string;
}
export type Go1MessageType =
| 'preview_start_content'
| 'preview_close'
| 'preview_add_content_success'
| 'preview_add_content_failure'
| 'preview_remove_content_success'
| 'preview_remove_content_failure'
| 'parent_show_preview'
| 'set_additional_embedding_data'
| 'go1_app_initialised'
| 'ott_required'
| 'search_result_selected'
| 'search_filter_toggle'
| 'pass_ott'
| 'logout',
| 'sync_content'
| 'inter_feature_navigation'
| 'side_drawer_open'
| 'side_drawer_close'
| 'swap_out_open'
| 'swap_out_close'
| 'play_content'
| 'go1pay_custom_data';
export interface Go1Message {
type: Go1MessageType;
payload?: any;
}
export type Experience = 'manager' | 'learner' | 'role-aware';
export interface FeatureAttributeCommon {
shouldSuppressPreview?: boolean;
experience?: Experience;
contentScope?: 'subscription' | 'library';
}
/**
* Used to configure the `ai-chat` feature
*/
export interface FeatureAttributesAIChat extends FeatureAttributeCommon {
intent?: 'skill_gap' | 'improve_skills' | 'next_role' | 'aspirations';
message?: string; // The desired message to start the chat, which will be shown to the user
existingSkills?: string[]; // max items 7, any more are discarded
desiredSkills?: string[]; // max items 7, any more are discarded
desiredRole?: string; // e.g. "Senior Account Manager"
showFooter?: boolean // Whether to show/hide the footer, defaults to true
}
/**
* Used to configure the `preview` feature
*/
export interface FeatureAttributesPreview extends FeatureAttributeCommon {
id: number;
startWith1Player?: boolean;
showFooter?: boolean;
contentRatingType?: 'no rating' | 'five star rating' | 'like rating';
}
/**
* Used to configure the `wallet` feature
*/
export interface FeatureAttributesWallet extends FeatureAttributeCommon {
walletMode: 'setup' | 'main';
deepLink?: string;
oneClickBuyUrl?: string;
}
export interface FeatureAttributesLearnerSearch extends FeatureAttributeCommon {
isGo1MobileApp?: boolean;
experience?: 'learner';
}
export interface FeatureAttributesLibrary extends FeatureAttributeCommon, FeatureAttributesRetirement {
libraryEmptyStateDescription?: string;
shouldShowLibraryTabs?: boolean;
}
export interface FeatureAttributesRetirement extends FeatureAttributeCommon {
shouldShowAlternativesSearchButton?: boolean;
shouldShowNotificationEmailRegisterSwitch?: boolean;
}
export interface FeatureAttributesSearch extends FeatureAttributeCommon {
searchTerm?: string; // If the embedding search feature includes a search term, the app will initialize with the pre-filled search term.
}
export interface FeatureAttributesMyPlaylists extends FeatureAttributesPreviewCommon {
playlistId?: number; // If embedding my-playlists feature with playlistId, the app will initialise with the specified playlistId page.
}
export interface FeatureAttributesMyLearning extends FeatureAttributeCommon {}
export type FeatureAttributes =
| FeatureAttributesAIChat
| FeatureAttributesPreview
| FeatureAttributesWallet
| FeatureAttributesLibrary
| FeatureAttributesSearch
| FeatureAttributesMyPlaylists
| FeatureAttributesMyLearning
| FeatureAttributesContentStatus;
export interface AdditionalUserInfo {
jobTitle: string;
}
export type FeatureType =
| 'ai-chat'
| 'content-hub'
| 'preview'
| 'library'
| 'search'
| 'wallet'
| 'content-retirement'
| 'my-playlists'
| 'activity-feed'
| 'my-learning'
| 'content-status';
export interface InitOptions {
/** Mandatory identifier for the embedded feature */
feature: FeatureType;
/** Optional element id to search for, and use as the parent for the Go1 content view (use either this or `iframeParentElement`, not both) */
iframeParentId?: string;
/** Optional element to use as the parent for the Go1 content view (use either this or `iframeParentId`, not both) */
iframeParentElement?: HTMLElement;
/** Optional parameters to configure the feature. See associated types for examples */
featureAttributes?: FeatureAttributes;
/** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
portalURL?: string;
/** Optional function that is invoked when the Go1 content view emits a message */
onGo1MessageReceived?: OnGo1MessageReceived;
/** Optional end user information that can enhance the context and provide a better experience. No PII is needed, please do not send any. */
additionalUserInfo?: AdditionalUserInfo;
/** Optional UI configuration */
themeInformation?: ThemeInformation;
/** Optional token that is used to pre-authorize the user without them needing to log in */
oneTimeToken?: string;
/** Optional Id that let us know which integration system users are coming from (will be required in the future)*/
integrationSystemId?: string;
/** Optional Id that let us know which integration system users are coming from, if using an intermediary system to embed */
presentingIntegrationSystemId?: string;
}
Function: go1Init
Initialize the Go1 content view and insert it into your web page. Establish messaging functions and configure the theme (UI).
function go1Init(options: InitOptions): SendMessageToGo1;
Usage
const onGo1MessageReceived = (message) => {
console.log('Received postMessage from Go1');
console.log(message);
};
const options = {
feature: 'ai-chat',
iframeParentId: 'go1-chat-window', // alternatively, you could provide `iframeParentElement` directly, instead of this prop
featureAttributes: {
experience: 'manager',
},
portalURL: 'learning-incorporated-usa.mygo1.com',
onGo1MessageReceived,
additionalUserInfo: {
jobTitle: 'Sales development representative',
},
themeInformation: {
accent: '#0437F2',
},
oneTimeToken: '907687a6e81a458190fe4c21f05ee689',
integrationSystemId: 'int_nI7rPykBRm0C',
};
const sendMessageToGo1 = go1Init(options);
Function: sendMessageToGo1
Send a message to the Go1 content view. Useful to control the user experience when an event starts on your website and the Go1 content view needs to be aware of it (and potentially perform other actions - this is feature
dependent.)
A currently supported message is update_experience
, this will update the experience Feature Attribute. An example of its usage is below.
function sendMessageToGo1(message: Go1Message): void;
Usage
const message = {
type: 'update_experience',
payload: { experience: 'learner' },
};
sendMessageToGo1(message);
Function: onGo1MessageReceived
Respond to events that have occurred in the Go1 content view. Useful to control the user experience when an event starts in the Go1 content view and your website needs to be aware of it.
Usage
const onGo1MessageReceived = (message) => {
switch (message.type) {
case 'enrolment_created': {
const { userId, courseId } = message.payload;
// perform appropriate actions for when a new enrolment is created
break;
}
case 'category_favourite_added': {
const { userId, category } = message.payload;
// perform appropriate actions for when a new category is favourited
break;
}
default:
break;
}
};
Support
https://www.go1.com/developers