jibtalk-core 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/jibtalk-core.js +5 -11
- package/dist/jibtalk-core.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface JibTalkOptions {
|
|
|
14
14
|
theme?: ThemeTypes;
|
|
15
15
|
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
16
16
|
primaryColor?: string;
|
|
17
|
-
customer?:
|
|
17
|
+
customer?: string;
|
|
18
18
|
conversationId?: string;
|
|
19
19
|
timestamp?: number;
|
|
20
20
|
signature?: string;
|
|
@@ -42,7 +42,7 @@ export declare class JibTalkCore {
|
|
|
42
42
|
connect(): void;
|
|
43
43
|
private initWidget;
|
|
44
44
|
open(options?: {
|
|
45
|
-
customer?:
|
|
45
|
+
customer?: string;
|
|
46
46
|
conversationId?: string;
|
|
47
47
|
timestamp?: number;
|
|
48
48
|
signature?: string;
|
|
@@ -50,8 +50,8 @@ export declare class JibTalkCore {
|
|
|
50
50
|
close(): void;
|
|
51
51
|
toggle(): void;
|
|
52
52
|
destroy(): void;
|
|
53
|
-
identify(user:
|
|
54
|
-
setUser(user:
|
|
53
|
+
identify(user: string, timestamp?: number, signature?: string): void;
|
|
54
|
+
setUser(user: string, timestamp?: number, signature?: string): void;
|
|
55
55
|
logout(): void;
|
|
56
56
|
sendMessage(content: string, parentMessageId?: string, file?: {
|
|
57
57
|
url: string;
|
package/dist/jibtalk-core.js
CHANGED
|
@@ -1455,7 +1455,7 @@ var Q = "\n#jibtalk-sdk-root {\n position: fixed;\n z-index: 9999;\n font-fam
|
|
|
1455
1455
|
constructor(e) {
|
|
1456
1456
|
this.apiKey = e.apiKey, this.backendUrl = typeof globalThis < "u" && globalThis.process?.env?.NEXT_PUBLIC_JIBTALK_BACKEND_URL || typeof window < "u" && window.JIBTALK_BACKEND_URL || "http://localhost:7000", this.theme = e.theme || "dark", this.position = e.position || "bottom-right", this.primaryColor = e.primaryColor || "#26A17B", this.locale = e.locale || "en", this.optionsCustomer = e.customer, this.optionsConvId = e.conversationId, this.optionsTimestamp = e.timestamp, this.optionsSignature = e.signature;
|
|
1457
1457
|
let t = typeof window < "u" ? localStorage.getItem("jibtalk_conversation_id") : null;
|
|
1458
|
-
this.currentConversation = t ? { id: t } : null, this.visitorId = e.customer
|
|
1458
|
+
this.currentConversation = t ? { id: t } : null, this.visitorId = e.customer || this.getVisitorId(), this.connect();
|
|
1459
1459
|
}
|
|
1460
1460
|
getVisitorId() {
|
|
1461
1461
|
if (typeof window > "u") return "";
|
|
@@ -1490,16 +1490,10 @@ var Q = "\n#jibtalk-sdk-root {\n position: fixed;\n z-index: 9999;\n font-fam
|
|
|
1490
1490
|
let e = localStorage.getItem("jibtalk_session_token");
|
|
1491
1491
|
e && (n.sessionToken = e);
|
|
1492
1492
|
}
|
|
1493
|
-
e ? (n.customer =
|
|
1494
|
-
id: e.id,
|
|
1495
|
-
name: e.name,
|
|
1496
|
-
email: e.email,
|
|
1497
|
-
avatar: e.avatar,
|
|
1498
|
-
metadata: e.metadata
|
|
1499
|
-
}, this.optionsTimestamp && (n.timestamp = this.optionsTimestamp), this.optionsSignature && (n.signature = this.optionsSignature)) : n.visitorId = this.visitorId, this.socket.emit("init_widget", n);
|
|
1493
|
+
e ? (n.customer = e, this.optionsTimestamp && (n.timestamp = this.optionsTimestamp), this.optionsSignature && (n.signature = this.optionsSignature)) : n.visitorId = this.visitorId, this.socket.emit("init_widget", n);
|
|
1500
1494
|
}
|
|
1501
1495
|
open(e) {
|
|
1502
|
-
this.isOpen || (this.isOpen = !0, this.unreadCount = 0, e && (e.customer && (this.visitorId = e.customer
|
|
1496
|
+
this.isOpen || (this.isOpen = !0, this.unreadCount = 0, e && (e.customer && (this.visitorId = e.customer, this.optionsCustomer = e.customer), e.conversationId && (this.optionsConvId = e.conversationId), e.timestamp && (this.optionsTimestamp = e.timestamp), e.signature && (this.optionsSignature = e.signature), this.initWidget(e.customer, e.conversationId)), this.emitStateChange());
|
|
1503
1497
|
}
|
|
1504
1498
|
close() {
|
|
1505
1499
|
this.isOpen && (this.isOpen = !1, this.emitStateChange(), this.emit("conversationClosed", this.currentConversation));
|
|
@@ -1511,7 +1505,7 @@ var Q = "\n#jibtalk-sdk-root {\n position: fixed;\n z-index: 9999;\n font-fam
|
|
|
1511
1505
|
console.log("Core SDK: destroy() called."), this.close(), this.socket &&= (this.socket.disconnect(), null), this.listeners.clear(), this.isConnected = !1, this.emitStateChange(), $ === this && ($ = null);
|
|
1512
1506
|
}
|
|
1513
1507
|
identify(e, t, n) {
|
|
1514
|
-
typeof window > "u" || (this.visitorId = e
|
|
1508
|
+
typeof window > "u" || (this.visitorId = e || this.visitorId, this.optionsCustomer = e, t && (this.optionsTimestamp = t), n && (this.optionsSignature = n), this.initWidget(e));
|
|
1515
1509
|
}
|
|
1516
1510
|
setUser(e, t, n) {
|
|
1517
1511
|
this.identify(e, t, n);
|
|
@@ -1577,7 +1571,7 @@ var Q = "\n#jibtalk-sdk-root {\n position: fixed;\n z-index: 9999;\n font-fam
|
|
|
1577
1571
|
});
|
|
1578
1572
|
}
|
|
1579
1573
|
updateOptions(e) {
|
|
1580
|
-
e.theme && (this.theme = e.theme), e.position && (this.position = e.position), e.primaryColor && (this.primaryColor = e.primaryColor), e.locale && (this.locale = e.locale), e.customer && (this.visitorId = e.customer
|
|
1574
|
+
e.theme && (this.theme = e.theme), e.position && (this.position = e.position), e.primaryColor && (this.primaryColor = e.primaryColor), e.locale && (this.locale = e.locale), e.customer !== void 0 && (e.customer ? (this.visitorId = e.customer, this.optionsCustomer = e.customer) : this.optionsCustomer = void 0), e.conversationId && (this.optionsConvId = e.conversationId), e.timestamp && (this.optionsTimestamp = e.timestamp), e.signature && (this.optionsSignature = e.signature), this.emitStateChange();
|
|
1581
1575
|
}
|
|
1582
1576
|
}, $ = null, Xe = (e) => typeof window > "u" ? null : (!$ && e ? $ = new Ye(e) : $ && e && $.updateOptions(e), $);
|
|
1583
1577
|
//#endregion
|
|
@@ -574,4 +574,4 @@
|
|
|
574
574
|
text-overflow: ellipsis;
|
|
575
575
|
white-space: nowrap;
|
|
576
576
|
}
|
|
577
|
-
`,Ye=()=>{if(typeof document>`u`)return;let e=`jibtalk-sdk-styles`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=Je,document.head.appendChild(t)}},Xe=class{socket=null;apiKey;backendUrl;visitorId;listeners=new Map;isOpen=!1;isConnected=!1;unreadCount=0;currentConversation=null;messages=[];workspaceName=``;workspaceSlug=``;theme=`dark`;position=`bottom-right`;primaryColor=`#26A17B`;locale=`en`;constructor(e){this.apiKey=e.apiKey,this.backendUrl=typeof globalThis<`u`&&globalThis.process?.env?.NEXT_PUBLIC_JIBTALK_BACKEND_URL||typeof window<`u`&&window.JIBTALK_BACKEND_URL||`http://localhost:7000`,this.theme=e.theme||`dark`,this.position=e.position||`bottom-right`,this.primaryColor=e.primaryColor||`#26A17B`,this.locale=e.locale||`en`,this.optionsCustomer=e.customer,this.optionsConvId=e.conversationId,this.optionsTimestamp=e.timestamp,this.optionsSignature=e.signature;let t=typeof window<`u`?localStorage.getItem(`jibtalk_conversation_id`):null;this.currentConversation=t?{id:t}:null,this.visitorId=e.customer
|
|
577
|
+
`,Ye=()=>{if(typeof document>`u`)return;let e=`jibtalk-sdk-styles`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=Je,document.head.appendChild(t)}},Xe=class{socket=null;apiKey;backendUrl;visitorId;listeners=new Map;isOpen=!1;isConnected=!1;unreadCount=0;currentConversation=null;messages=[];workspaceName=``;workspaceSlug=``;theme=`dark`;position=`bottom-right`;primaryColor=`#26A17B`;locale=`en`;constructor(e){this.apiKey=e.apiKey,this.backendUrl=typeof globalThis<`u`&&globalThis.process?.env?.NEXT_PUBLIC_JIBTALK_BACKEND_URL||typeof window<`u`&&window.JIBTALK_BACKEND_URL||`http://localhost:7000`,this.theme=e.theme||`dark`,this.position=e.position||`bottom-right`,this.primaryColor=e.primaryColor||`#26A17B`,this.locale=e.locale||`en`,this.optionsCustomer=e.customer,this.optionsConvId=e.conversationId,this.optionsTimestamp=e.timestamp,this.optionsSignature=e.signature;let t=typeof window<`u`?localStorage.getItem(`jibtalk_conversation_id`):null;this.currentConversation=t?{id:t}:null,this.visitorId=e.customer||this.getVisitorId(),this.connect()}getVisitorId(){if(typeof window>`u`)return``;let e=localStorage.getItem(`jibtalk_visitor_id`);return e||=localStorage.getItem(`vyou_visitor_id`),e||(e=`v_`+Math.random().toString(36).substring(2,11),localStorage.setItem(`jibtalk_visitor_id`,e)),e}connect(){typeof window>`u`||(this.socket&&this.socket.disconnect(),this.socket=Q(this.backendUrl),this.socket.on(`connect`,()=>{this.isConnected=!0,this.emit(`connected`),this.emitStateChange();let e=this.optionsCustomer,t=this.optionsConvId;this.initWidget(e,t)}),this.socket.on(`disconnect`,()=>{this.isConnected=!1,this.emit(`disconnected`),this.emitStateChange()}),this.socket.on(`session_ready`,e=>{this.currentConversation=e,this.messages=e.messages||[],this.workspaceName=e.workspaceName||``,this.workspaceSlug=e.workspaceSlug||``,typeof window<`u`&&(e.id&&localStorage.setItem(`jibtalk_conversation_id`,e.id),e.sessionToken&&localStorage.setItem(`jibtalk_session_token`,e.sessionToken)),this.emit(`conversationOpened`,e),this.emitStateChange()}),this.socket.on(`widget_ready`,e=>{this.workspaceName=e.workspaceName||``,this.workspaceSlug=e.workspaceSlug||``,this.currentConversation=null,this.messages=[],e.sessionExpired&&typeof window<`u`&&(localStorage.removeItem(`jibtalk_conversation_id`),localStorage.removeItem(`jibtalk_session_token`)),this.emitStateChange()}),this.socket.on(`receive_message`,e=>{this.messages.push(e),e.sender===`visitor`?this.emit(`messageSent`,e):(this.isOpen||this.unreadCount++,this.emit(`messageReceived`,e)),this.emitStateChange()}),this.socket.on(`typing_started`,e=>{this.emit(`typingStarted`,e)}),this.socket.on(`typing_stopped`,e=>{this.emit(`typingStopped`,e)}),this.socket.on(`error`,e=>{console.error(`JibTalk Socket error:`,e.message||e)}))}initWidget(e,t){if(!this.socket)return;let n={apiKey:this.apiKey},r=t||this.currentConversation?.id;if(r&&(n.conversationId=r,typeof window<`u`&&!e)){let e=localStorage.getItem(`jibtalk_session_token`);e&&(n.sessionToken=e)}e?(n.customer=e,this.optionsTimestamp&&(n.timestamp=this.optionsTimestamp),this.optionsSignature&&(n.signature=this.optionsSignature)):n.visitorId=this.visitorId,this.socket.emit(`init_widget`,n)}open(e){this.isOpen||(this.isOpen=!0,this.unreadCount=0,e&&(e.customer&&(this.visitorId=e.customer,this.optionsCustomer=e.customer),e.conversationId&&(this.optionsConvId=e.conversationId),e.timestamp&&(this.optionsTimestamp=e.timestamp),e.signature&&(this.optionsSignature=e.signature),this.initWidget(e.customer,e.conversationId)),this.emitStateChange())}close(){this.isOpen&&(this.isOpen=!1,this.emitStateChange(),this.emit(`conversationClosed`,this.currentConversation))}toggle(){console.log(`Core SDK: toggle() called. Current isOpen status:`,this.isOpen),this.isOpen?this.close():this.open()}destroy(){console.log(`Core SDK: destroy() called.`),this.close(),this.socket&&=(this.socket.disconnect(),null),this.listeners.clear(),this.isConnected=!1,this.emitStateChange(),$===this&&($=null)}identify(e,t,n){typeof window>`u`||(this.visitorId=e||this.visitorId,this.optionsCustomer=e,t&&(this.optionsTimestamp=t),n&&(this.optionsSignature=n),this.initWidget(e))}setUser(e,t,n){this.identify(e,t,n)}logout(){typeof window>`u`||(this.close(),localStorage.removeItem(`jibtalk_visitor_id`),localStorage.removeItem(`vyou_visitor_id`),localStorage.removeItem(`jibtalk_conversation_id`),localStorage.removeItem(`jibtalk_session_token`),this.optionsCustomer=void 0,this.optionsConvId=void 0,this.optionsTimestamp=void 0,this.optionsSignature=void 0,this.visitorId=this.getVisitorId(),this.currentConversation=null,this.messages=[],this.unreadCount=0,this.connect())}sendMessage(e,t,n){!e.trim()&&!n||!this.currentConversation||!this.socket||this.socket.emit(`send_message`,{sessionId:this.currentConversation.id,content:e,sender:`visitor`,visitorId:this.visitorId,parentMessageId:t,file:n})}startConversation(){this.socket&&this.socket.emit(`start_conversation`)}startTyping(){!this.socket||!this.currentConversation||this.socket.emit(`typing_started`,{sessionId:this.currentConversation.id,sender:`visitor`,visitorId:this.visitorId})}stopTyping(){!this.socket||!this.currentConversation||this.socket.emit(`typing_stopped`,{sessionId:this.currentConversation.id,sender:`visitor`,visitorId:this.visitorId})}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),console.log(`Core SDK: Listener added for event "${e}". Current count:`,this.listeners.get(e)?.size)}off(e,t){this.listeners.has(e)&&(this.listeners.get(e).delete(t),console.log(`Core SDK: Listener removed for event "${e}". Current count:`,this.listeners.get(e)?.size))}emit(e,...t){this.listeners.has(e)?(console.log(`Core SDK: Emitting event "${e}" to`,this.listeners.get(e).size,`listeners.`),this.listeners.get(e).forEach(n=>{try{n(...t)}catch(t){console.error(`Error in event listener for ${e}:`,t)}})):console.log(`Core SDK: Emitting event "${e}" but no listeners exist.`)}emitStateChange(){console.log(`Core SDK: emitStateChange() triggered. isOpen:`,this.isOpen,`isConnected:`,this.isConnected),this.emit(`stateChange`,{isOpen:this.isOpen,isConnected:this.isConnected,unreadCount:this.unreadCount,currentConversation:this.currentConversation,messages:this.messages,theme:this.theme,position:this.position,primaryColor:this.primaryColor,locale:this.locale,workspaceName:this.workspaceName,workspaceSlug:this.workspaceSlug})}updateOptions(e){e.theme&&(this.theme=e.theme),e.position&&(this.position=e.position),e.primaryColor&&(this.primaryColor=e.primaryColor),e.locale&&(this.locale=e.locale),e.customer!==void 0&&(e.customer?(this.visitorId=e.customer,this.optionsCustomer=e.customer):this.optionsCustomer=void 0),e.conversationId&&(this.optionsConvId=e.conversationId),e.timestamp&&(this.optionsTimestamp=e.timestamp),e.signature&&(this.optionsSignature=e.signature),this.emitStateChange()}},$=null;e.JibTalkCore=Xe,e.STYLES_CSS=Je,e.getJibTalkInstance=e=>typeof window>`u`?null:(!$&&e?$=new Xe(e):$&&e&&$.updateOptions(e),$),e.injectStyles=Ye});
|