@iai-lib/any-chat-widget 0.1.0-alpha.29 → 0.1.0-alpha.30
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.
|
@@ -7611,8 +7611,8 @@ async function pl({
|
|
|
7611
7611
|
contentHtmlTemplate: n`
|
|
7612
7612
|
<style>
|
|
7613
7613
|
.btn {
|
|
7614
|
-
background-color:
|
|
7615
|
-
color:
|
|
7614
|
+
background-color: var(--iai-chat-i-message-user-bg);
|
|
7615
|
+
color: var(--iai-chat-i-message-user-fg);
|
|
7616
7616
|
border: none;
|
|
7617
7617
|
padding: 10px 20px;
|
|
7618
7618
|
text-align: center;
|
|
@@ -7625,7 +7625,8 @@ async function pl({
|
|
|
7625
7625
|
}
|
|
7626
7626
|
|
|
7627
7627
|
.btn-no {
|
|
7628
|
-
background-color:
|
|
7628
|
+
background-color: var(--iai-chat-i-message-assistant-bg);
|
|
7629
|
+
color: var(--iai-chat-i-message-assistant-fg);
|
|
7629
7630
|
}
|
|
7630
7631
|
</style>
|
|
7631
7632
|
<div class="my-4">
|
|
@@ -477,8 +477,8 @@ Please report this to https://github.com/markedjs/marked.`,i){const n="<p>An err
|
|
|
477
477
|
`}function Jo(i){return async function({id:t,params:n,chatWindow:s}){s.setInputDisabled(!0);const r={...n.guestCardId&&{guestCardId:n.guestCardId},...n.customerFirstName&&{firstName:n.customerFirstName},...n.customerLastName&&{lastName:n.customerLastName},...n.customerEmail&&{email:n.customerEmail},...n.customerPhoneNumber&&{phone:n.customerPhoneNumber},...n.desiredMoveInDate&&{moveInDate:n.desiredMoveInDate}},a=document.createElement("iai-chat-iframe-modal");a.title="Schedule a Tour",a.src=`${i}?${new URLSearchParams(r).toString()}`,a.showHeader=!1;const o=()=>{a.remove(),window.removeEventListener("beforeunload",u),s.setInputDisabled(!1)},l=async({detail:p})=>{if(p.type!=="tourScheduled")return;const{tourType:c,tourDate:g,tourTime:O}=p;o(),s.addMessage({role:"system",content:"Your tour has been scheduled!"}),await s.sendFunctionCallResponse(t,{status:"scheduled",tourType:c,tourDate:g,tourTime:O},!0)},d=async()=>{o(),s.addMessage({role:"system",content:"Tour Scheduler Closed"}),await s.sendFunctionCallResponse(t,{status:"canceled"},!0)},u=async()=>{o(),s.addMessage({role:"system",content:"Tour Scheduler Closed"})};a.addEventListener("message-received",l),a.addEventListener("close",d),window.addEventListener("beforeunload",u),document.body.appendChild(a),s.addMessage({role:"system",content:"Tour Scheduler Opened"})}}function Ks(i){return{all:i=i||new Map,on:function(e,t){var n=i.get(e);n?n.push(t):i.set(e,[t])},off:function(e,t){var n=i.get(e);n&&(t?n.splice(n.indexOf(t)>>>0,1):i.set(e,[]))},emit:function(e,t){var n=i.get(e);n&&n.slice().map(function(s){s(t)}),(n=i.get("*"))&&n.slice().map(function(s){s(e,t)})}}}class Qo{constructor(e){this.chatWsUrl=e,this._emitter=Ks(),this.on=this._emitter.on.bind(this._emitter),this.off=this._emitter.off.bind(this._emitter),this.reconnectCodes=new Set([1006]),this.reconnectAttempts=0,this.maxReconnectAttempts=10}connect(){const e=new WebSocket(this.chatWsUrl);e.onopen=async()=>{this.reconnectAttempts=0,e.send(JSON.stringify({type:"ready"}))},e.onmessage=t=>{const n=JSON.parse(t.data);this._emitter.emit(n.type,n.data)},e.onclose=t=>{console.log("Disconnected: ",t.code,t.reason||"No reason provided"),this._emitter.emit("disconnected",t),this.reconnectCodes.has(t.code)&&this.reconnectAttempts<this.maxReconnectAttempts&&(console.log("Reconnecting..."),this._emitter.emit("reconnecting"),this.reconnectAttempts++,setTimeout(()=>this.connect(),this.reconnectAttempts*1e3))},e.onerror=t=>{console.log("Error:",t),this._emitter.emit("error",t)},this.ws=e}reconnect(){this.reconnectAttempts=0,this.connect()}disconnect(){var e;(e=this.ws)==null||e.close()}destroy(){this.disconnect(),this._emitter.all.clear()}}var Pn;(i=>{(e=>{e.TEXT="TEXT"})(i.MessageType||(i.MessageType={})),(e=>{e.DELIVERED="DELIVERED",e.READ="READ",e.FAILED="FAILED"})(i.AcknowledgeType||(i.AcknowledgeType={})),(e=>{e.GENERIC="GENERIC",e.SMS="SMS",e.RCS="RCS",e.FACEBOOK="FACEBOOK",e.TWITTER="TWITTER",e.WHATSAPP="WHATSAPP",e.WECHAT="WECHAT",e.QQMOBILE="QQMOBILE",e.APPLE_BUSINESS_CHAT="APPLE_BUSINESS_CHAT",e.SKYPE="SKYPE",e.SNAPCHAT="SNAPCHAT",e.VIBER="VIBER",e.LINE="LINE",e.TELEGRAM="TELEGRAM",e.KAKAO="KAKAO"})(i.ContentType||(i.ContentType={})),(e=>{e.SYSTEM="SYSTEM",e.USER="USER"})(i.ConversationEventOrigin||(i.ConversationEventOrigin={})),(e=>{e.PENDING="PENDING",e.ACTIVE="ACTIVE",e.TERMINATED="TERMINATED"})(i.ConversationStatus||(i.ConversationStatus={}))})(Pn||(Pn={}));const Yo=Pn.AcknowledgeType,Go="Anyone Home",Xo="IB Chat Leasing - Development";let el="https://five9.ah.inhabit.work";const tl="https://five9.ah.inhabit.work".replace("http","ws").replace(/\/$/,""),Gt=class Gt{constructor(){Ii(this,Se,void 0);Ii(this,st,void 0);this._emitter=Ks(),this.on=this._emitter.on.bind(this._emitter),this.off=this._emitter.off.bind(this._emitter),De(this,Se,null),De(this,st,null),this.conversationStarted=!1}serialize(){return JSON.stringify({sessionToken:this.sessionToken,conversationId:this.conversationId,conversationStarted:this.conversationStarted})}static deserialize(e){const t=JSON.parse(e),n=new Gt;return t.sessionToken&&n.setSession(t.sessionToken),t.conversationId&&n.setConversationId(t.conversationId),n.conversationStarted=t.conversationStarted||!1,n}static generateBaseUrl(e){return`https://${e}/appsvcs/rs/svc`}async createSession(){const e=await fetch(`${Gt.generateBaseUrl("app-scl.five9.com")}/auth/anon?cookieless=true`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({tenantName:Go})});return De(this,Se,await e.json()),Dn(this,Se)}setSession(e){De(this,Se,e)}setConversationId(e){De(this,st,e),this.five9WebSocket&&(this.five9WebSocket.destroy(),this.five9WebSocket=void 0,e&&this.connectToWebSocket())}connect(){if(!this.sessionToken)throw new Error("Session not created");if(!this.conversationId)throw new Error("Conversation not started");this.connectToWebSocket()}connectToWebSocket(){if(!this.conversationId)throw new Error("Conversation not started");this.five9WebSocket&&this.five9WebSocket.destroy();const e=new Qo(`${tl}/conversations/${this.conversationId}/ws`);e.on("*",(t,n)=>{this._emitter.emit(t,n)}),e.on("conversationCreated",t=>{this.conversationStarted=!0,console.log("Conversation Created:",t)}),e.on("conversationAccepted",t=>{console.log("Conversation Accepted:",t)}),e.on("agentJoined",t=>{console.log("Agent Joined:",t)}),e.on("agentTransferredConversation",t=>{console.log("Agent Transferred Conversation:",t)}),e.on("conversationTransferredToGroup",t=>{console.log("Conversation Transferred To Group:",t)}),e.on("agentLeftConversation",t=>{console.log("Agent Left Conversation:",t)}),e.on("agentTyping",t=>{console.log("Agent Typing:",t)}),e.on("message",async t=>{console.log("Message:",t),await this.acknowledgeMessage({messages:[{messageId:t.messageId,type:Yo.READ}]})}),e.on("conversationTerminated",t=>{console.log("Conversation Terminated:",t)}),e.on("error",t=>{console.log("Error:",t)}),this.five9WebSocket=e,e.connect()}async authenticatedFetch(e,t={}){const{sessionToken:n}=this;if(!n)throw new Error("Session not found");e=e.startsWith("/")?e:`/${e}`;const s=n.metadata.dataCenters[0].apiUrls[0].host,r=await fetch(`${Gt.generateBaseUrl(s)}${e}`,{...t,headers:{...t.headers,"Content-Type":"application/json",Accept:"application/json",Authorization:n.tokenId,farmId:n.context.farmId}});return r.status===204?null:r.json()}async getMetadata(){if(!this.sessionToken)throw new Error("Session not created");return this.authenticatedFetch("/auth/metadata",{method:"GET"})}async createConversation(e){if(!this.sessionToken)throw new Error("Session not created");const t=e.contact||{};Object.keys(t).forEach(r=>{const a=r;t[a]||delete t[a]});const n={...e,campaignName:Xo,tenantId:this.tenantId,callbackUrl:el};console.log("body",n);const s=await this.authenticatedFetch("/conversations",{method:"POST",body:JSON.stringify(n)});return this.setConversationId(s.id),s}async sendMessage(e){const{conversationId:t,conversationStarted:n}=this;if(!t||!n)throw new Error("Conversation not started");const s={messageType:Pn.MessageType.TEXT,message:e};await this.authenticatedFetch(`/conversations/${t}/messages`,{method:"POST",body:JSON.stringify(s)})}async sendTyping(){const{conversationId:e}=this;if(!e)throw new Error("Conversation not started");await this.authenticatedFetch(`/conversations/${e}/messages/typing`,{method:"PUT"})}async acknowledgeMessage(e){const{conversationId:t}=this;if(!t)throw new Error("Conversation not started");await this.authenticatedFetch(`/conversations/${t}/messages/acknowledge`,{method:"PUT",body:JSON.stringify(e)})}async terminateConversation(){const{conversationId:e}=this;if(!e)throw new Error("Conversation not started");await this.authenticatedFetch(`/conversations/${e}/terminate`,{method:"POST"}),this.destroy()}destroy(){this.five9WebSocket&&this.five9WebSocket.destroy(),De(this,Se,null),De(this,st,null)}get sessionToken(){return Dn(this,Se)}get conversationId(){return Dn(this,st)}get dataCenter(){var e;return(e=this.sessionToken)==null?void 0:e.metadata.dataCenters[0]}get apiUrl(){var e;return(e=this.dataCenter)==null?void 0:e.apiUrls[0].host}get tenantId(){var e;return(e=this.sessionToken)==null?void 0:e.orgId}get tokenId(){var e;return(e=this.sessionToken)==null?void 0:e.tokenId}get farmId(){var e;return(e=this.sessionToken)==null?void 0:e.context.farmId}};Se=new WeakMap,st=new WeakMap;let Nn=Gt;function Yt(i){return`any-${i||"main"}-chatSession`}async function nl({id:i,params:e,chatWindow:t,html:n}){t=t;const s=async()=>{t.removeMessage("transferMessageId"),await t.sendFunctionCallResponse(i,{transfer:"Declined"},!0),t.setInputDisabled(!1)},r=async()=>{t.setInputDisabled(!0),t.removeMessage("transferMessageId"),t.addMessage({role:"system",content:"Please wait while we connect you to a live agent"}),t.chatManager.stopInactivityTimers();const a=new Nn;await a.createSession();const{summary:o,subject:l,...d}=e;await a.createConversation({contact:d,attributes:{Question:l,"AI Summary":o}}),localStorage.setItem(Yt(t.cleanOptions.config.historyKey),a.serialize()),Js(t,a)};t.addMessage({id:"transferMessageId",role:"system",contentHtmlTemplate:n`
|
|
478
478
|
<style>
|
|
479
479
|
.btn {
|
|
480
|
-
background-color:
|
|
481
|
-
color:
|
|
480
|
+
background-color: var(--iai-chat-i-message-user-bg);
|
|
481
|
+
color: var(--iai-chat-i-message-user-fg);
|
|
482
482
|
border: none;
|
|
483
483
|
padding: 10px 20px;
|
|
484
484
|
text-align: center;
|
|
@@ -491,7 +491,8 @@ Please report this to https://github.com/markedjs/marked.`,i){const n="<p>An err
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
.btn-no {
|
|
494
|
-
background-color:
|
|
494
|
+
background-color: var(--iai-chat-i-message-assistant-bg);
|
|
495
|
+
color: var(--iai-chat-i-message-assistant-fg);
|
|
495
496
|
}
|
|
496
497
|
</style>
|
|
497
498
|
<div class="my-4">
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iai-lib/any-chat-widget",
|
|
3
3
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
4
|
-
"version": "0.1.0-alpha.
|
|
4
|
+
"version": "0.1.0-alpha.30",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"@iai-lib/chat-widget": "^1.0.0-alpha.33",
|
|
38
38
|
"mitt": "^3.0.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "fbaed248458ff45f3df1a50687716d49559486b4"
|
|
41
41
|
}
|