@getnexorai/sdk 0.1.4 → 0.1.5

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { initChat } from './chunk-WUUXZIQN.js';
1
+ import { initChat } from './chunk-EGZR7CCR.js';
2
2
 
3
3
  // src/errors.ts
4
4
  var NexorError = class extends Error {
@@ -1,4 +1,4 @@
1
- var Nexor=(function(exports){'use strict';var te=class extends Error{constructor(n){super(n),this.name="NexorError";}},U=class extends te{constructor(n){var t;super(n.message),this.name="NexorAPIError",this.status=n.status,this.code=(t=n.code)!=null?t:Ht(n.status),this.body=n.body,this.requestId=n.requestId;}},ne=class extends U{constructor(n){super({status:401,code:"unauthorized",...n}),this.name="NexorAuthError";}},re=class extends U{constructor(n){super({status:400,code:"validation_error",...n}),this.name="NexorValidationError";}},X=class extends te{constructor(n,t){super(n),this.name="NexorNetworkError",this.cause=t;}};function Ht(e){return e===400?"validation_error":e===401?"unauthorized":e===403?"forbidden":e===404?"not_found":e===409?"conflict":e===422?"unprocessable_entity":e===429?"rate_limited":e>=500?"server_error":"http_error"}var Pt="https://api.getnexor.ai",At=3e4,Ot=2,qt="0.1.0";function rt(e){var i,l,u,c;if(!e||typeof e.apiKey!="string"||e.apiKey.trim()==="")throw new Error("Nexor SDK: `apiKey` is required. Get one in the dashboard at https://app.getnexor.ai");let n=(i=e.fetch)!=null?i:typeof globalThis!="undefined"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0;if(!n)throw new Error("Nexor SDK: no global fetch found. Pass a `fetch` implementation via init() or upgrade to Node 18+.");let t=`nexor-sdk-js/${qt}${e.userAgentSuffix?` ${e.userAgentSuffix}`:""}`;return {apiKey:e.apiKey.trim(),baseUrl:Ft((l=e.baseUrl)!=null?l:Pt),timeoutMs:(u=e.timeoutMs)!=null?u:At,maxRetries:(c=e.maxRetries)!=null?c:Ot,fetchImpl:n,userAgent:t}}async function E(e,n){var m,a,x,p,f,I,L,H,M;let t=Kt(e.baseUrl,n.path,n.query),i={"X-API-Key":e.apiKey,Accept:"application/json","User-Agent":e.userAgent};(m=n.options)!=null&&m.idempotencyKey&&(i["Idempotency-Key"]=n.options.idempotencyKey);let l;n.body!==void 0&&(i["Content-Type"]="application/json",l=JSON.stringify(n.body));let u=(x=(a=n.options)==null?void 0:a.timeoutMs)!=null?x:e.timeoutMs,c=(f=(p=n.options)==null?void 0:p.maxRetries)!=null?f:e.maxRetries,o;for(let N=0;N<=c;N++){let S=new AbortController,b=(I=n.options)==null?void 0:I.signal,P=()=>S.abort();b&&(b.aborted?S.abort():b.addEventListener("abort",P));let q=setTimeout(()=>S.abort(),u);try{let w=await e.fetchImpl(t,{method:n.method,headers:i,body:l,signal:S.signal});clearTimeout(q),b==null||b.removeEventListener("abort",P);let O=(L=w.headers.get("x-request-id"))!=null?L:void 0;if(w.ok){if(w.status===204)return;let F=await w.text();if(!F)return;try{return JSON.parse(F)}catch(K){throw new U({status:w.status,message:"Failed to parse JSON response",body:F,requestId:O})}}let j=await Ut(w),Q=(H=Bt(j))!=null?H:`HTTP ${w.status}`,$=Dt(w.status,Q,j,O);if($t(w.status)&&N<c){await nt(tt(N,w)),o=$;continue}throw $}catch(w){if(clearTimeout(q),b==null||b.removeEventListener("abort",P),w instanceof U)throw w;let O=w instanceof Error&&(w.name==="AbortError"||/abort/i.test(w.message));if(O&&(b!=null&&b.aborted))throw w;if(o=w,N<c){await nt(tt(N));continue}throw new X(O?`Request timed out after ${u}ms`:`Network error: ${(M=w==null?void 0:w.message)!=null?M:String(w)}`,w)}}throw o!=null?o:new X("Request failed")}function Dt(e,n,t,i){return e===401||e===403?new ne({message:n,body:t,requestId:i}):e===400||e===422?new re({message:n,body:t,requestId:i}):new U({status:e,message:n,body:t,requestId:i})}function Bt(e){if(!e||typeof e!="object")return;let n=e;if(typeof n.message=="string")return n.message;if(typeof n.error=="string")return n.error}async function Ut(e){try{let n=await e.text();if(!n)return null;try{return JSON.parse(n)}catch(t){return n}}catch(n){return null}}function $t(e){return e===429||e>=500&&e<=599}function tt(e,n){if(n){let i=n.headers.get("retry-after");if(i){let l=Number(i);if(!Number.isNaN(l)&&l>0)return Math.min(l*1e3,1e4)}}return 300*2**e+Math.floor(Math.random()*200)}function nt(e){return new Promise(n=>setTimeout(n,e))}function Ft(e){return e.endsWith("/")?e.slice(0,-1):e}function Kt(e,n,t){let i=n.startsWith("/")?n:`/${n}`,l=zt(t);return `${e}${i}${l?`?${l}`:""}`}function zt(e){if(!e)return "";let n=[];for(let[t,i]of Object.entries(e))if(i!=null)if(Array.isArray(i)){if(i.length===0)continue;n.push(`${encodeURIComponent(t)}=${encodeURIComponent(i.join(","))}`);}else n.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(i))}`);return n.join("&")}var R="/api/public",Z=class{constructor(n){this.cfg=rt(n);}createLead(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads`,body:{...n,skip_first_message:true},options:t})}createLeadsBulk(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads`,body:n.map(i=>({...i,skip_first_message:true})),options:t})}updateLead(n,t,i){return E(this.cfg,{method:"PUT",path:`${R}/leads/${encodeURIComponent(n)}`,body:t,options:i})}getLead(n,t){return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}`,options:t})}getLeadHistory(n,t={},i){let l=Array.isArray(t.channel)?t.channel:t.channel?[t.channel]:void 0;return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}/history`,query:{channel:l,limit:t.limit,offset:t.offset},options:i})}isLeadPaused(n,t={},i){return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}/is_paused`,query:{workflow_id:t.workflow_id},options:i})}stopAutomation(n,t,i){return E(this.cfg,{method:"POST",path:`${R}/leads/${encodeURIComponent(n)}/automation/stop`,body:t,options:i})}resumeAutomation(n,t,i){return E(this.cfg,{method:"POST",path:`${R}/leads/${encodeURIComponent(n)}/automation/resume`,body:t,options:i})}syncLeadTags(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads/tags`,body:n,options:t})}listLeadMeetings(n,t={},i){let l=Array.isArray(t.status)?t.status.join(","):t.status;return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}/meetings`,query:{status:l},options:i})}listWorkflows(n){return E(this.cfg,{method:"GET",path:`${R}/workflows`,options:n})}listCampaigns(n){return E(this.cfg,{method:"GET",path:`${R}/campaigns`,options:n})}listTemplates(n={},t){return E(this.cfg,{method:"GET",path:`${R}/templates`,query:{status:n.status,category:n.category},options:t})}sendMessage(n,t){return E(this.cfg,{method:"POST",path:`${R}/messages`,body:n,options:t})}createMeeting(n,t){return E(this.cfg,{method:"POST",path:`${R}/meetings`,body:n,options:t})}createMeetingNotes(n,t){return E(this.cfg,{method:"POST",path:`${R}/meeting-notes`,body:n,options:t})}getChatConfig(n,t){return E(this.cfg,{method:"GET",path:`${R}/chat/config`,query:{workflow_id:n},options:t})}chat(n,t){return E(this.cfg,{method:"POST",path:`${R}/chat`,body:n,options:t})}requestContact(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads`,body:n,options:t})}};function at(e){var n,t,i,l,u,c,o,m,a,x,p,f,I,L,H,M,N,S,b,P,q,w,O,j,Q,$,F,K,ie,ge,xe,be,Ce,V,le,G,D,_e,ye,ce,de,we,ue,pe,he,ve,ee;return {workflowId:e.workflowId,title:(n=e.title)!=null?n:"Chat with us",subtitle:(t=e.subtitle)!=null?t:"We typically reply in a few minutes",openingMessage:e.openingMessage,greeting:(i=e.greeting)!=null?i:"Hi there! \u{1F44B} How can we help?",errorText:(l=e.errorText)!=null?l:"Sorry, something went wrong. Please try again in a moment.",disabledText:(u=e.disabledText)!=null?u:"Chat isn't available right now. Please reach us on another channel.",locale:(c=e.locale)!=null?c:typeof navigator!="undefined"?navigator.language:void 0,accentColor:(o=e.accentColor)!=null?o:"#111827",accentTextColor:(m=e.accentTextColor)!=null?m:"#ffffff",showBranding:(a=e.showBranding)!=null?a:true,inputPlaceholder:(x=e.inputPlaceholder)!=null?x:"Type a message\u2026",showRestart:(p=e.showRestart)!=null?p:true,restartLabel:(f=e.restartLabel)!=null?f:"Start over",position:(I=e.position)!=null?I:"bottom-right",openOnLoad:(L=e.openOnLoad)!=null?L:false,channels:Vt(e.channels),requestContact:Jt((H=e.channels)==null?void 0:H.requestContact),debounceMs:(M=e.debounceMs)!=null?M:700,splitReplies:(N=e.splitReplies)!=null?N:true,splitDelayMs:(S=e.splitDelayMs)!=null?S:0,requestTimeoutMs:(b=e.requestTimeoutMs)!=null?b:6e4,container:e.container,systemPrompt:e.systemPrompt,clientPrompt:e.clientPrompt,lead:e.lead,capture:{fields:(q=(P=e.capture)==null?void 0:P.fields)!=null?q:["first_name","email"],mode:(O=(w=e.capture)==null?void 0:w.mode)!=null?O:"before",createLeadOnSubmit:(Q=(j=e.capture)==null?void 0:j.createLeadOnSubmit)!=null?Q:false,label:(F=($=e.capture)==null?void 0:$.label)!=null?F:"Tell us a bit about you to get started:",submitLabel:(ie=(K=e.capture)==null?void 0:K.submitLabel)!=null?ie:"Start chat",placeholders:(xe=(ge=e.capture)==null?void 0:ge.placeholders)!=null?xe:{},phoneCountryCode:(Ce=(be=e.capture)==null?void 0:be.phoneCountryCode)!=null?Ce:"",phoneCountries:(le=(V=e.capture)==null?void 0:V.phoneCountries)!=null?le:[],errorMessages:{required:(_e=(D=(G=e.capture)==null?void 0:G.errorMessages)==null?void 0:D.required)!=null?_e:"Please complete this field.",email:(de=(ce=(ye=e.capture)==null?void 0:ye.errorMessages)==null?void 0:ce.email)!=null?de:"Enter a valid email address.",phone:(pe=(ue=(we=e.capture)==null?void 0:we.errorMessages)==null?void 0:ue.phone)!=null?pe:"Enter a valid phone number, including the country code."}},metadata:e.metadata,resumeText:(he=e.resumeText)!=null?he:"Continuing your conversation",resumeWithNameText:(ve=e.resumeWithNameText)!=null?ve:"Continuing as {name}",startOverText:(ee=e.startOverText)!=null?ee:"Start over",onOpen:e.onOpen,onClose:e.onClose,onMessage:e.onMessage,onLeadCaptured:e.onLeadCaptured,onError:e.onError}}var Wt=["whatsapp","call","email","instagram","chat"],jt={whatsapp:"WhatsApp",call:"Call",email:"Email",instagram:"Instagram",chat:"Chat"};function Vt(e){var o,m;if(!e)return [];let n=(o=e.order)!=null?o:Wt,t=a=>{var x,p;return (p=(x=e.labels)==null?void 0:x[a])!=null?p:jt[a]},i=new Set(e.requestContact?(m=e.requestContact.channels)!=null?m:["call","email"]:[]),l=a=>({key:a,href:null,external:false,action:"contact",label:t(a)}),u=new Set,c=[];for(let a of n)if(!u.has(a))switch(u.add(a),a){case "whatsapp":{if(i.has("whatsapp")){c.push(l(a));break}if(!e.whatsapp)break;let x=e.whatsapp.replace(/[^\d]/g,"");if(!x)break;let p=e.whatsappText?`?text=${encodeURIComponent(e.whatsappText)}`:"";c.push({key:a,href:`https://wa.me/${x}${p}`,external:true,label:t(a)});break}case "call":{if(i.has("call")){c.push(l(a));break}if(!e.call)break;let x=e.call.replace(/[^\d+]/g,"");if(!x)break;c.push({key:a,href:`tel:${x}`,external:false,label:t(a)});break}case "email":{if(i.has("email")){c.push(l(a));break}if(!e.email)break;c.push({key:a,href:`mailto:${e.email}`,external:false,label:t(a)});break}case "instagram":{if(!e.instagram)break;let x=/^https?:\/\//i.test(e.instagram)?e.instagram:`https://instagram.com/${e.instagram.replace(/^@/,"")}`;c.push({key:a,href:x,external:true,label:t(a)});break}case "chat":{if(e.chat===false)break;c.push({key:a,href:null,external:false,label:t(a)});break}}return c.every(a=>a.key==="chat")?[]:c}var Gt={call:"Request a call",email:"Request an email",whatsapp:"Request a message"},Yt={call:"Leave your details and we'll call you. We need this to reach you.",email:"Leave your details and we'll email you. We need this to reach you.",whatsapp:"Leave your details and we'll message you. We need this to reach you."},Xt={call:"Request call",email:"Request email",whatsapp:"Request message"},Zt={call:"Thanks! We'll call you shortly.",email:"Thanks! We'll email you shortly.",whatsapp:"Thanks! We'll message you shortly."};function Jt(e){var i,l;if(!e)return;let n=e.channels&&e.channels.length?e.channels:["call","email"],t=(u,c)=>{var m;let o={};for(let a of n)o[a]=(m=u==null?void 0:u[a])!=null?m:c[a];return o};return {channels:n,title:t(e.title,Gt),subtitle:t(e.subtitle,Yt),submitLabel:t(e.submitLabel,Xt),successText:t(e.successText,Zt),doneLabel:(i=e.doneLabel)!=null?i:"Done",errorText:(l=e.errorText)!=null?l:"Something went wrong. Please try again."}}function ke(e){if(e.capture.mode==="skip")return false;if(e.lead){let n=e.lead;return e.capture.fields.some(t=>!n[t])}return true}var ot="nexor.chat.session_id";function st(){let e=Date.now();try{let t=lt();if(t&&e-t.ts<2592e6)return Ae(t.id,e),t.id}catch(t){}let n=`sess_${Qt(16)}`;try{Ae(n,e);}catch(t){}return n}function it(){try{let e=lt();e&&Ae(e.id,Date.now());}catch(e){}}function lt(){let e=window.localStorage.getItem(ot);if(!e)return null;try{let n=JSON.parse(e);if(n&&typeof n.id=="string"&&typeof n.ts=="number")return n}catch(n){}return e.startsWith("sess_")?{id:e,ts:Date.now()}:null}function Ae(e,n){window.localStorage.setItem(ot,JSON.stringify({id:e,ts:n}));}function Qt(e){let n=new Uint8Array(e);if(typeof crypto!="undefined"&&crypto.getRandomValues)crypto.getRandomValues(n);else for(let t=0;t<e;t++)n[t]=Math.floor(Math.random()*256);return Array.from(n,t=>t.toString(16).padStart(2,"0")).join("")}function Oe(e){let n=(e||"").trim();return n.length<6||n.length>254?false:/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(n)}var en={first_name:"first_name",name:"first_name",lead_first_name:"first_name",last_name:"last_name",lastname:"last_name",lead_last_name:"last_name",full_name:"full_name",fullname:"full_name",email:"email",phone:"phone"};function ae(e){return e==null?"":String(e).trim()}function tn(e,n){if(!e)return "";switch(n){case "first_name":return ae(e.first_name);case "last_name":return ae(e.last_name);case "full_name":return [ae(e.first_name),ae(e.last_name)].filter(Boolean).join(" ");case "email":return ae(e.email);case "phone":return ae(e.phone);default:return ""}}function ct(e,n){return typeof e!="string"||!e?"":e.replace(/\{\{\s*([a-zA-Z_]+)\s*\}\}/g,(i,l)=>{let u=en[l.toLowerCase()];return u?tn(n,u):i}).replace(/[ \t]+([,.!?;:])/g,"$1").replace(/[ \t]{2,}/g," ").replace(/^[ \t]*[,;:][ \t]*/gm,"").replace(/[ \t]+$/gm,"").trim()}var dt={iso:"CL",name:"Chile",dial:"+56",flag:"\u{1F1E8}\u{1F1F1}",nsn:[9,9]},me=[dt,{iso:"MX",name:"M\xE9xico",dial:"+52",flag:"\u{1F1F2}\u{1F1FD}",nsn:[10,10]},{iso:"AR",name:"Argentina",dial:"+54",flag:"\u{1F1E6}\u{1F1F7}",nsn:[10,11]},{iso:"CO",name:"Colombia",dial:"+57",flag:"\u{1F1E8}\u{1F1F4}",nsn:[10,10]},{iso:"PE",name:"Per\xFA",dial:"+51",flag:"\u{1F1F5}\u{1F1EA}",nsn:[9,9]},{iso:"BR",name:"Brasil",dial:"+55",flag:"\u{1F1E7}\u{1F1F7}",nsn:[10,11]},{iso:"EC",name:"Ecuador",dial:"+593",flag:"\u{1F1EA}\u{1F1E8}",nsn:[8,9]},{iso:"UY",name:"Uruguay",dial:"+598",flag:"\u{1F1FA}\u{1F1FE}",nsn:[8,8]},{iso:"US",name:"United States",dial:"+1",flag:"\u{1F1FA}\u{1F1F8}",nsn:[10,10]},{iso:"ES",name:"Espa\xF1a",dial:"+34",flag:"\u{1F1EA}\u{1F1F8}",nsn:[9,9]},{iso:"GB",name:"United Kingdom",dial:"+44",flag:"\u{1F1EC}\u{1F1E7}",nsn:[10,10]}];function W(e){return e.nsn[1]}function J(e){if(!e)return;let n=e.toUpperCase();return me.find(t=>t.iso===n)}function nn(e){if(!e)return;let n=e.startsWith("+")?e:`+${e.replace(/^\+?/,"")}`;return me.find(t=>t.dial===n)}function fe(e){let n=(e||"").trim();return nn(n)||J(n)||dt}var ut=(e,n)=>`
1
+ var Nexor=(function(exports){'use strict';var te=class extends Error{constructor(n){super(n),this.name="NexorError";}},U=class extends te{constructor(n){var t;super(n.message),this.name="NexorAPIError",this.status=n.status,this.code=(t=n.code)!=null?t:At(n.status),this.body=n.body,this.requestId=n.requestId;}},ne=class extends U{constructor(n){super({status:401,code:"unauthorized",...n}),this.name="NexorAuthError";}},re=class extends U{constructor(n){super({status:400,code:"validation_error",...n}),this.name="NexorValidationError";}},Z=class extends te{constructor(n,t){super(n),this.name="NexorNetworkError",this.cause=t;}};function At(e){return e===400?"validation_error":e===401?"unauthorized":e===403?"forbidden":e===404?"not_found":e===409?"conflict":e===422?"unprocessable_entity":e===429?"rate_limited":e>=500?"server_error":"http_error"}var Ht="https://api.getnexor.ai",Pt=3e4,Ot=2,qt="0.1.0";function rt(e){var s,l,u,c;if(!e||typeof e.apiKey!="string"||e.apiKey.trim()==="")throw new Error("Nexor SDK: `apiKey` is required. Get one in the dashboard at https://app.getnexor.ai");let n=(s=e.fetch)!=null?s:typeof globalThis!="undefined"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0;if(!n)throw new Error("Nexor SDK: no global fetch found. Pass a `fetch` implementation via init() or upgrade to Node 18+.");let t=`nexor-sdk-js/${qt}${e.userAgentSuffix?` ${e.userAgentSuffix}`:""}`;return {apiKey:e.apiKey.trim(),baseUrl:Ft((l=e.baseUrl)!=null?l:Ht),timeoutMs:(u=e.timeoutMs)!=null?u:Pt,maxRetries:(c=e.maxRetries)!=null?c:Ot,fetchImpl:n,userAgent:t}}async function E(e,n){var m,a,x,p,f,I,L,A,M;let t=zt(e.baseUrl,n.path,n.query),s={"X-API-Key":e.apiKey,Accept:"application/json","User-Agent":e.userAgent};(m=n.options)!=null&&m.idempotencyKey&&(s["Idempotency-Key"]=n.options.idempotencyKey);let l;n.body!==void 0&&(s["Content-Type"]="application/json",l=JSON.stringify(n.body));let u=(x=(a=n.options)==null?void 0:a.timeoutMs)!=null?x:e.timeoutMs,c=(f=(p=n.options)==null?void 0:p.maxRetries)!=null?f:e.maxRetries,o;for(let N=0;N<=c;N++){let S=new AbortController,b=(I=n.options)==null?void 0:I.signal,H=()=>S.abort();b&&(b.aborted?S.abort():b.addEventListener("abort",H));let q=setTimeout(()=>S.abort(),u);try{let w=await e.fetchImpl(t,{method:n.method,headers:s,body:l,signal:S.signal});clearTimeout(q),b==null||b.removeEventListener("abort",H);let O=(L=w.headers.get("x-request-id"))!=null?L:void 0;if(w.ok){if(w.status===204)return;let F=await w.text();if(!F)return;try{return JSON.parse(F)}catch(z){throw new U({status:w.status,message:"Failed to parse JSON response",body:F,requestId:O})}}let j=await Ut(w),Q=(A=Bt(j))!=null?A:`HTTP ${w.status}`,$=Dt(w.status,Q,j,O);if($t(w.status)&&N<c){await nt(tt(N,w)),o=$;continue}throw $}catch(w){if(clearTimeout(q),b==null||b.removeEventListener("abort",H),w instanceof U)throw w;let O=w instanceof Error&&(w.name==="AbortError"||/abort/i.test(w.message));if(O&&(b!=null&&b.aborted))throw w;if(o=w,N<c){await nt(tt(N));continue}throw new Z(O?`Request timed out after ${u}ms`:`Network error: ${(M=w==null?void 0:w.message)!=null?M:String(w)}`,w)}}throw o!=null?o:new Z("Request failed")}function Dt(e,n,t,s){return e===401||e===403?new ne({message:n,body:t,requestId:s}):e===400||e===422?new re({message:n,body:t,requestId:s}):new U({status:e,message:n,body:t,requestId:s})}function Bt(e){if(!e||typeof e!="object")return;let n=e;if(typeof n.message=="string")return n.message;if(typeof n.error=="string")return n.error}async function Ut(e){try{let n=await e.text();if(!n)return null;try{return JSON.parse(n)}catch(t){return n}}catch(n){return null}}function $t(e){return e===429||e>=500&&e<=599}function tt(e,n){if(n){let s=n.headers.get("retry-after");if(s){let l=Number(s);if(!Number.isNaN(l)&&l>0)return Math.min(l*1e3,1e4)}}return 300*2**e+Math.floor(Math.random()*200)}function nt(e){return new Promise(n=>setTimeout(n,e))}function Ft(e){return e.endsWith("/")?e.slice(0,-1):e}function zt(e,n,t){let s=n.startsWith("/")?n:`/${n}`,l=Kt(t);return `${e}${s}${l?`?${l}`:""}`}function Kt(e){if(!e)return "";let n=[];for(let[t,s]of Object.entries(e))if(s!=null)if(Array.isArray(s)){if(s.length===0)continue;n.push(`${encodeURIComponent(t)}=${encodeURIComponent(s.join(","))}`);}else n.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(s))}`);return n.join("&")}var R="/api/public",X=class{constructor(n){this.cfg=rt(n);}createLead(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads`,body:{...n,skip_first_message:true},options:t})}createLeadsBulk(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads`,body:n.map(s=>({...s,skip_first_message:true})),options:t})}updateLead(n,t,s){return E(this.cfg,{method:"PUT",path:`${R}/leads/${encodeURIComponent(n)}`,body:t,options:s})}getLead(n,t){return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}`,options:t})}getLeadHistory(n,t={},s){let l=Array.isArray(t.channel)?t.channel:t.channel?[t.channel]:void 0;return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}/history`,query:{channel:l,limit:t.limit,offset:t.offset},options:s})}isLeadPaused(n,t={},s){return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}/is_paused`,query:{workflow_id:t.workflow_id},options:s})}stopAutomation(n,t,s){return E(this.cfg,{method:"POST",path:`${R}/leads/${encodeURIComponent(n)}/automation/stop`,body:t,options:s})}resumeAutomation(n,t,s){return E(this.cfg,{method:"POST",path:`${R}/leads/${encodeURIComponent(n)}/automation/resume`,body:t,options:s})}syncLeadTags(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads/tags`,body:n,options:t})}listLeadMeetings(n,t={},s){let l=Array.isArray(t.status)?t.status.join(","):t.status;return E(this.cfg,{method:"GET",path:`${R}/leads/${encodeURIComponent(n)}/meetings`,query:{status:l},options:s})}listWorkflows(n){return E(this.cfg,{method:"GET",path:`${R}/workflows`,options:n})}listCampaigns(n){return E(this.cfg,{method:"GET",path:`${R}/campaigns`,options:n})}listTemplates(n={},t){return E(this.cfg,{method:"GET",path:`${R}/templates`,query:{status:n.status,category:n.category},options:t})}sendMessage(n,t){return E(this.cfg,{method:"POST",path:`${R}/messages`,body:n,options:t})}createMeeting(n,t){return E(this.cfg,{method:"POST",path:`${R}/meetings`,body:n,options:t})}createMeetingNotes(n,t){return E(this.cfg,{method:"POST",path:`${R}/meeting-notes`,body:n,options:t})}getChatConfig(n,t){return E(this.cfg,{method:"GET",path:`${R}/chat/config`,query:{workflow_id:n},options:t})}chat(n,t){return E(this.cfg,{method:"POST",path:`${R}/chat`,body:n,options:t})}requestContact(n,t){return E(this.cfg,{method:"POST",path:`${R}/leads`,body:n,options:t})}};function at(e){var n,t,s,l,u,c,o,m,a,x,p,f,I,L,A,M,N,S,b,H,q,w,O,j,Q,$,F,z,ie,ge,xe,be,Ce,V,le,G,D,_e,ye,ce,de,we,ue,pe,he,ve,ee;return {workflowId:e.workflowId,title:(n=e.title)!=null?n:"Chat with us",subtitle:(t=e.subtitle)!=null?t:"We typically reply in a few minutes",openingMessage:e.openingMessage,greeting:(s=e.greeting)!=null?s:"Hi there! \u{1F44B} How can we help?",errorText:(l=e.errorText)!=null?l:"Sorry, something went wrong. Please try again in a moment.",disabledText:(u=e.disabledText)!=null?u:"Chat isn't available right now. Please reach us on another channel.",locale:(c=e.locale)!=null?c:typeof navigator!="undefined"?navigator.language:void 0,accentColor:(o=e.accentColor)!=null?o:"#111827",accentTextColor:(m=e.accentTextColor)!=null?m:"#ffffff",showBranding:(a=e.showBranding)!=null?a:true,inputPlaceholder:(x=e.inputPlaceholder)!=null?x:"Type a message\u2026",showRestart:(p=e.showRestart)!=null?p:true,restartLabel:(f=e.restartLabel)!=null?f:"Start over",position:(I=e.position)!=null?I:"bottom-right",openOnLoad:(L=e.openOnLoad)!=null?L:false,channels:Vt(e.channels),requestContact:Jt((A=e.channels)==null?void 0:A.requestContact),debounceMs:(M=e.debounceMs)!=null?M:700,splitReplies:(N=e.splitReplies)!=null?N:true,splitDelayMs:(S=e.splitDelayMs)!=null?S:0,requestTimeoutMs:(b=e.requestTimeoutMs)!=null?b:6e4,container:e.container,systemPrompt:e.systemPrompt,clientPrompt:e.clientPrompt,lead:e.lead,capture:{fields:(q=(H=e.capture)==null?void 0:H.fields)!=null?q:["first_name","email"],mode:(O=(w=e.capture)==null?void 0:w.mode)!=null?O:"before",createLeadOnSubmit:(Q=(j=e.capture)==null?void 0:j.createLeadOnSubmit)!=null?Q:false,label:(F=($=e.capture)==null?void 0:$.label)!=null?F:"Tell us a bit about you to get started:",submitLabel:(ie=(z=e.capture)==null?void 0:z.submitLabel)!=null?ie:"Start chat",placeholders:(xe=(ge=e.capture)==null?void 0:ge.placeholders)!=null?xe:{},phoneCountryCode:(Ce=(be=e.capture)==null?void 0:be.phoneCountryCode)!=null?Ce:"",phoneCountries:(le=(V=e.capture)==null?void 0:V.phoneCountries)!=null?le:[],errorMessages:{required:(_e=(D=(G=e.capture)==null?void 0:G.errorMessages)==null?void 0:D.required)!=null?_e:"Please complete this field.",email:(de=(ce=(ye=e.capture)==null?void 0:ye.errorMessages)==null?void 0:ce.email)!=null?de:"Enter a valid email address.",phone:(pe=(ue=(we=e.capture)==null?void 0:we.errorMessages)==null?void 0:ue.phone)!=null?pe:"Enter a valid phone number, including the country code."}},metadata:e.metadata,resumeText:(he=e.resumeText)!=null?he:"Continuing your conversation",resumeWithNameText:(ve=e.resumeWithNameText)!=null?ve:"Continuing as {name}",startOverText:(ee=e.startOverText)!=null?ee:"Start over",onOpen:e.onOpen,onClose:e.onClose,onMessage:e.onMessage,onLeadCaptured:e.onLeadCaptured,onError:e.onError}}var Wt=["whatsapp","call","email","instagram","chat"],jt={whatsapp:"WhatsApp",call:"Call",email:"Email",instagram:"Instagram",chat:"Chat"};function Vt(e){var o,m;if(!e)return [];let n=(o=e.order)!=null?o:Wt,t=a=>{var x,p;return (p=(x=e.labels)==null?void 0:x[a])!=null?p:jt[a]},s=new Set(e.requestContact?(m=e.requestContact.channels)!=null?m:["call","email"]:[]),l=a=>({key:a,href:null,external:false,action:"contact",label:t(a)}),u=new Set,c=[];for(let a of n)if(!u.has(a))switch(u.add(a),a){case "whatsapp":{if(s.has("whatsapp")){c.push(l(a));break}if(!e.whatsapp)break;let x=e.whatsapp.replace(/[^\d]/g,"");if(!x)break;let p=e.whatsappText?`?text=${encodeURIComponent(e.whatsappText)}`:"";c.push({key:a,href:`https://wa.me/${x}${p}`,external:true,label:t(a)});break}case "call":{if(s.has("call")){c.push(l(a));break}if(!e.call)break;let x=e.call.replace(/[^\d+]/g,"");if(!x)break;c.push({key:a,href:`tel:${x}`,external:false,label:t(a)});break}case "email":{if(s.has("email")){c.push(l(a));break}if(!e.email)break;c.push({key:a,href:`mailto:${e.email}`,external:false,label:t(a)});break}case "instagram":{if(!e.instagram)break;let x=/^https?:\/\//i.test(e.instagram)?e.instagram:`https://instagram.com/${e.instagram.replace(/^@/,"")}`;c.push({key:a,href:x,external:true,label:t(a)});break}case "chat":{if(e.chat===false)break;c.push({key:a,href:null,external:false,label:t(a)});break}}return c.every(a=>a.key==="chat")?[]:c}var Gt={call:"Request a call",email:"Request an email",whatsapp:"Request a message"},Yt={call:"Leave your details and we'll call you. We need this to reach you.",email:"Leave your details and we'll email you. We need this to reach you.",whatsapp:"Leave your details and we'll message you. We need this to reach you."},Zt={call:"Request call",email:"Request email",whatsapp:"Request message"},Xt={call:"Thanks! We'll call you shortly.",email:"Thanks! We'll email you shortly.",whatsapp:"Thanks! We'll message you shortly."};function Jt(e){var s,l;if(!e)return;let n=e.channels&&e.channels.length?e.channels:["call","email"],t=(u,c)=>{var m;let o={};for(let a of n)o[a]=(m=u==null?void 0:u[a])!=null?m:c[a];return o};return {channels:n,title:t(e.title,Gt),subtitle:t(e.subtitle,Yt),submitLabel:t(e.submitLabel,Zt),successText:t(e.successText,Xt),doneLabel:(s=e.doneLabel)!=null?s:"Done",errorText:(l=e.errorText)!=null?l:"Something went wrong. Please try again."}}function ke(e){if(e.capture.mode==="skip")return false;if(e.lead){let n=e.lead;return e.capture.fields.some(t=>!n[t])}return true}var ot="nexor.chat.session_id";function st(){let e=Date.now();try{let t=lt();if(t&&e-t.ts<2592e6)return Pe(t.id,e),t.id}catch(t){}let n=`sess_${Qt(16)}`;try{Pe(n,e);}catch(t){}return n}function it(){try{let e=lt();e&&Pe(e.id,Date.now());}catch(e){}}function lt(){let e=window.localStorage.getItem(ot);if(!e)return null;try{let n=JSON.parse(e);if(n&&typeof n.id=="string"&&typeof n.ts=="number")return n}catch(n){}return e.startsWith("sess_")?{id:e,ts:Date.now()}:null}function Pe(e,n){window.localStorage.setItem(ot,JSON.stringify({id:e,ts:n}));}function Qt(e){let n=new Uint8Array(e);if(typeof crypto!="undefined"&&crypto.getRandomValues)crypto.getRandomValues(n);else for(let t=0;t<e;t++)n[t]=Math.floor(Math.random()*256);return Array.from(n,t=>t.toString(16).padStart(2,"0")).join("")}var en=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;function Oe(e){let n=(e||"").trim();if(n.length<6||n.length>254)return false;let t=n.lastIndexOf("@");if(t<1)return false;let s=n.slice(0,t),l=n.slice(t+1);return s.length>64||s.startsWith(".")||s.endsWith(".")||s.includes("..")||l.includes("..")||!/\.[a-zA-Z]{2,}$/.test(l)?false:en.test(n)}var tn={first_name:"first_name",name:"first_name",lead_first_name:"first_name",last_name:"last_name",lastname:"last_name",lead_last_name:"last_name",full_name:"full_name",fullname:"full_name",email:"email",phone:"phone"};function ae(e){return e==null?"":String(e).trim()}function nn(e,n){if(!e)return "";switch(n){case "first_name":return ae(e.first_name);case "last_name":return ae(e.last_name);case "full_name":return [ae(e.first_name),ae(e.last_name)].filter(Boolean).join(" ");case "email":return ae(e.email);case "phone":return ae(e.phone);default:return ""}}function ct(e,n){return typeof e!="string"||!e?"":e.replace(/\{\{\s*([a-zA-Z_]+)\s*\}\}/g,(s,l)=>{let u=tn[l.toLowerCase()];return u?nn(n,u):s}).replace(/[ \t]+([,.!?;:])/g,"$1").replace(/[ \t]{2,}/g," ").replace(/^[ \t]*[,;:][ \t]*/gm,"").replace(/[ \t]+$/gm,"").trim()}var dt={iso:"CL",name:"Chile",dial:"+56",flag:"\u{1F1E8}\u{1F1F1}",nsn:[9,9]},me=[dt,{iso:"MX",name:"M\xE9xico",dial:"+52",flag:"\u{1F1F2}\u{1F1FD}",nsn:[10,10]},{iso:"AR",name:"Argentina",dial:"+54",flag:"\u{1F1E6}\u{1F1F7}",nsn:[10,11]},{iso:"CO",name:"Colombia",dial:"+57",flag:"\u{1F1E8}\u{1F1F4}",nsn:[10,10]},{iso:"PE",name:"Per\xFA",dial:"+51",flag:"\u{1F1F5}\u{1F1EA}",nsn:[9,9]},{iso:"BR",name:"Brasil",dial:"+55",flag:"\u{1F1E7}\u{1F1F7}",nsn:[10,11]},{iso:"EC",name:"Ecuador",dial:"+593",flag:"\u{1F1EA}\u{1F1E8}",nsn:[8,9]},{iso:"UY",name:"Uruguay",dial:"+598",flag:"\u{1F1FA}\u{1F1FE}",nsn:[8,8]},{iso:"US",name:"United States",dial:"+1",flag:"\u{1F1FA}\u{1F1F8}",nsn:[10,10]},{iso:"ES",name:"Espa\xF1a",dial:"+34",flag:"\u{1F1EA}\u{1F1F8}",nsn:[9,9]},{iso:"GB",name:"United Kingdom",dial:"+44",flag:"\u{1F1EC}\u{1F1E7}",nsn:[10,10]}];function W(e){return e.nsn[1]}function J(e){if(!e)return;let n=e.toUpperCase();return me.find(t=>t.iso===n)}function rn(e){if(!e)return;let n=e.startsWith("+")?e:`+${e.replace(/^\+?/,"")}`;return me.find(t=>t.dial===n)}function fe(e){let n=(e||"").trim();return rn(n)||J(n)||dt}var ut=(e,n)=>`
2
2
  .nexor-chat,
3
3
  .nexor-chat * {
4
4
  box-sizing: border-box;
@@ -843,7 +843,7 @@ textarea.nexor-chat__input {
843
843
  <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
844
844
  <path d="M4 5.5C4 4.67 4.67 4 5.5 4h13c.83 0 1.5.67 1.5 1.5v9c0 .83-.67 1.5-1.5 1.5H9l-4 4V5.5Z"
845
845
  stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
846
- </svg>`,rn={whatsapp:`
846
+ </svg>`,an={whatsapp:`
847
847
  <svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
848
848
  <path d="M.057 24l1.687-6.163a11.867 11.867 0 0 1-1.587-5.946C.16 5.335 5.495 0 12.05 0a11.817 11.817 0 0 1 8.413 3.488 11.824 11.824 0 0 1 3.48 8.414c-.003 6.557-5.338 11.892-11.893 11.892a11.9 11.9 0 0 1-5.688-1.448L.057 24zm6.597-3.807c1.676.995 3.276 1.591 5.392 1.592 5.448 0 9.886-4.434 9.889-9.885.002-5.462-4.415-9.89-9.881-9.892-5.452 0-9.887 4.434-9.889 9.884a9.82 9.82 0 0 0 1.5 5.245l-.999 3.648 3.738-.981zm11.387-5.464c-.074-.124-.272-.198-.57-.347-.297-.149-1.758-.868-2.031-.967-.272-.099-.47-.149-.669.149-.198.297-.768.967-.941 1.165-.173.198-.347.223-.644.074-.297-.149-1.255-.462-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.297-.347.446-.521.151-.172.2-.296.3-.495.099-.198.05-.372-.025-.521-.075-.148-.669-1.611-.916-2.206-.242-.579-.487-.501-.669-.51l-.57-.01c-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.263.489 1.694.626.712.226 1.36.194 1.872.118.571-.085 1.758-.719 2.006-1.413.248-.695.248-1.29.173-1.414z"/>
849
849
  </svg>`,call:`
@@ -858,7 +858,7 @@ textarea.nexor-chat__input {
858
858
  <rect x="3.5" y="3.5" width="17" height="17" rx="5" stroke="currentColor" stroke-width="1.8"/>
859
859
  <circle cx="12" cy="12" r="4" stroke="currentColor" stroke-width="1.8"/>
860
860
  <circle cx="17.2" cy="6.8" r="1.2" fill="currentColor"/>
861
- </svg>`,chat:mt};function ft(e){let n=document.createElement("div");n.className="nexor-chat__launcher-wrap";let t=e.channels.length>0,{fan:i,channelButtons:l}=t?an(e.channels):{fan:null,channelButtons:[]};i&&n.appendChild(i);let u=document.createElement("button");u.type="button",u.className="nexor-chat__launcher",u.setAttribute("aria-label",t?"Contact us":"Open chat"),t&&(u.setAttribute("aria-haspopup","true"),u.setAttribute("aria-expanded","false")),u.innerHTML=mt;let c=document.createElement("span");return c.className="nexor-chat__unread",c.style.display="none",u.appendChild(c),n.appendChild(u),{wrap:n,el:u,badge:c,fan:i,channelButtons:l}}function an(e){let n=document.createElement("div");n.className="nexor-chat__channels",n.setAttribute("role","menu");let t=[];for(let i of e){let l=document.createElement("div");l.className="nexor-chat__channel-item";let u=document.createElement("span");u.className="nexor-chat__channel-label",u.textContent=i.label;let c;if(i.href===null){let o=document.createElement("button");o.type="button",c=o;}else {let o=document.createElement("a");o.href=i.href,i.external&&(o.target="_blank",o.rel="noopener noreferrer"),c=o;}c.className=`nexor-chat__channel nexor-chat__channel--${i.key}`,c.setAttribute("role","menuitem"),c.setAttribute("aria-label",i.label),c.innerHTML=rn[i.key],l.appendChild(u),l.appendChild(c),n.appendChild(l),t.push({key:i.key,el:c,action:i.action});}return {fan:n,channelButtons:t}}function gt(e){let n=document.createElement("div");n.className="nexor-chat__panel",n.setAttribute("role","dialog"),n.setAttribute("aria-label",e.title);let{header:t,closeBtn:i,restartBtn:l,titleEl:u,subtitleEl:c,subtitleTextEl:o}=on(e),m=sn(),{form:a,input:x,send:p}=hn(e),f=e.showBranding?fn():null,I={},L=null,H=null,M=null,N=null;if(ke(e)){let b=ln(e,I);L=b.view,H=b.form,M=b.error,N=b.phoneCountry;}let S=e.requestContact?pn(e):null;return n.setAttribute("data-view",L?"capture":"chat"),n.appendChild(t),L&&n.appendChild(L),S&&n.appendChild(S.view),n.appendChild(m),n.appendChild(a),f&&n.appendChild(f),{el:n,closeBtn:i,restartBtn:l,headerTitle:u,headerSubtitle:c,headerSubtitleText:o,body:m,form:a,input:x,send:p,captureView:L,captureForm:H,captureError:M,phoneCountry:N,captureInputs:I,contact:S}}function on(e){var a;let n=document.createElement("div");n.className="nexor-chat__header";let t=document.createElement("div"),i=document.createElement("p");i.className="nexor-chat__title",i.textContent=e.title,t.appendChild(i);let l=document.createElement("p");l.className="nexor-chat__subtitle";let u=document.createElement("span");u.className="nexor-chat__status-dot",u.setAttribute("aria-hidden","true");let c=document.createElement("span");c.className="nexor-chat__subtitle-text",c.textContent=(a=e.subtitle)!=null?a:"",l.appendChild(u),l.appendChild(c),e.subtitle||(l.hidden=true),t.appendChild(l),n.appendChild(t);let o=null;e.showRestart&&(o=document.createElement("button"),o.type="button",o.className="nexor-chat__restart",o.setAttribute("aria-label",e.restartLabel),o.title=e.restartLabel,o.innerHTML=`
861
+ </svg>`,chat:mt};function ft(e){let n=document.createElement("div");n.className="nexor-chat__launcher-wrap";let t=e.channels.length>0,{fan:s,channelButtons:l}=t?on(e.channels):{fan:null,channelButtons:[]};s&&n.appendChild(s);let u=document.createElement("button");u.type="button",u.className="nexor-chat__launcher",u.setAttribute("aria-label",t?"Contact us":"Open chat"),t&&(u.setAttribute("aria-haspopup","true"),u.setAttribute("aria-expanded","false")),u.innerHTML=mt;let c=document.createElement("span");return c.className="nexor-chat__unread",c.style.display="none",u.appendChild(c),n.appendChild(u),{wrap:n,el:u,badge:c,fan:s,channelButtons:l}}function on(e){let n=document.createElement("div");n.className="nexor-chat__channels",n.setAttribute("role","menu");let t=[];for(let s of e){let l=document.createElement("div");l.className="nexor-chat__channel-item";let u=document.createElement("span");u.className="nexor-chat__channel-label",u.textContent=s.label;let c;if(s.href===null){let o=document.createElement("button");o.type="button",c=o;}else {let o=document.createElement("a");o.href=s.href,s.external&&(o.target="_blank",o.rel="noopener noreferrer"),c=o;}c.className=`nexor-chat__channel nexor-chat__channel--${s.key}`,c.setAttribute("role","menuitem"),c.setAttribute("aria-label",s.label),c.innerHTML=an[s.key],l.appendChild(u),l.appendChild(c),n.appendChild(l),t.push({key:s.key,el:c,action:s.action});}return {fan:n,channelButtons:t}}function gt(e){let n=document.createElement("div");n.className="nexor-chat__panel",n.setAttribute("role","dialog"),n.setAttribute("aria-label",e.title);let{header:t,closeBtn:s,restartBtn:l,titleEl:u,subtitleEl:c,subtitleTextEl:o}=sn(e),m=ln(),{form:a,input:x,send:p}=mn(e),f=e.showBranding?gn():null,I={},L=null,A=null,M=null,N=null;if(ke(e)){let b=cn(e,I);L=b.view,A=b.form,M=b.error,N=b.phoneCountry;}let S=e.requestContact?hn(e):null;return n.setAttribute("data-view",L?"capture":"chat"),n.appendChild(t),L&&n.appendChild(L),S&&n.appendChild(S.view),n.appendChild(m),n.appendChild(a),f&&n.appendChild(f),{el:n,closeBtn:s,restartBtn:l,headerTitle:u,headerSubtitle:c,headerSubtitleText:o,body:m,form:a,input:x,send:p,captureView:L,captureForm:A,captureError:M,phoneCountry:N,captureInputs:I,contact:S}}function sn(e){var a;let n=document.createElement("div");n.className="nexor-chat__header";let t=document.createElement("div"),s=document.createElement("p");s.className="nexor-chat__title",s.textContent=e.title,t.appendChild(s);let l=document.createElement("p");l.className="nexor-chat__subtitle";let u=document.createElement("span");u.className="nexor-chat__status-dot",u.setAttribute("aria-hidden","true");let c=document.createElement("span");c.className="nexor-chat__subtitle-text",c.textContent=(a=e.subtitle)!=null?a:"",l.appendChild(u),l.appendChild(c),e.subtitle||(l.hidden=true),t.appendChild(l),n.appendChild(t);let o=null;e.showRestart&&(o=document.createElement("button"),o.type="button",o.className="nexor-chat__restart",o.setAttribute("aria-label",e.restartLabel),o.title=e.restartLabel,o.innerHTML=`
862
862
  <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
863
863
  <path d="M4 5v5h5M20 19v-5h-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
864
864
  <path d="M19 10a7 7 0 0 0-12-3L4 10M5 14a7 7 0 0 0 12 3l3-3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
@@ -867,15 +867,15 @@ textarea.nexor-chat__input {
867
867
  <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
868
868
  <path d="M6 6l12 12M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
869
869
  </svg>
870
- `,n.appendChild(m),{header:n,closeBtn:m,restartBtn:o,titleEl:i,subtitleEl:l,subtitleTextEl:c}}function sn(){let e=document.createElement("div");return e.className="nexor-chat__body",e}function ln(e,n){let t=document.createElement("div");t.className="nexor-chat__capture-view";let{form:i,error:l,phoneCountry:u}=cn(e,n);return t.appendChild(i),{view:t,form:i,error:l,phoneCountry:u}}var xt={first_name:"First name",last_name:"Last name",email:"Email",phone:"Phone"};function cn(e,n){var a,x,p;let t=document.createElement("form");t.className="nexor-chat__capture",t.noValidate=true;let i=null,l=document.createElement("p");l.className="nexor-chat__capture-label",l.textContent=e.capture.label,t.appendChild(l);let u=e.capture.fields,c=f=>{var I;return (I=e.capture.placeholders[f])!=null?I:xt[f]};if(u.includes("first_name")||u.includes("last_name")){let f=document.createElement("div");f.className="nexor-chat__capture-row",u.includes("first_name")&&(n.first_name=oe("first_name",c("first_name"),"text",(a=e.lead)==null?void 0:a.first_name),f.appendChild(n.first_name)),u.includes("last_name")&&(n.last_name=oe("last_name",c("last_name"),"text",(x=e.lead)==null?void 0:x.last_name),f.appendChild(n.last_name)),f.childElementCount>0&&t.appendChild(f);}if(u.includes("email")&&(n.email=oe("email",c("email"),"email",(p=e.lead)==null?void 0:p.email),t.appendChild(n.email)),u.includes("phone")){let f=bt(e,c("phone"));n.phone=f.input,i=f.select,t.appendChild(f.wrap);}let o=document.createElement("p");o.className="nexor-chat__capture-error",o.setAttribute("role","alert"),o.hidden=true,t.appendChild(o);let m=document.createElement("button");return m.type="submit",m.className="nexor-chat__capture-submit",m.textContent=e.capture.submitLabel,t.appendChild(m),{form:t,error:o,phoneCountry:i}}function dn(e){if(!e.length)return me;let n=e.map(t=>J(t)).filter(t=>!!t);return n.length?n:me}function bt(e,n){var o;let t=document.createElement("div");t.className="nexor-chat__phone";let i=dn(e.capture.phoneCountries),l=fe(e.capture.phoneCountryCode),u=document.createElement("select");u.className="nexor-chat__phone-country",u.name="phone_country",u.setAttribute("aria-label","Country code");for(let m of i){let a=document.createElement("option");a.value=m.iso,a.textContent=`${m.flag} ${m.dial}`,m.iso===l.iso&&(a.selected=true),u.appendChild(a);}let c=document.createElement("input");if(c.name="phone",c.type="tel",c.inputMode="numeric",c.autocomplete="tel-national",c.placeholder=n,c.className="nexor-chat__input nexor-chat__phone-number",c.maxLength=W(l),(o=e.lead)!=null&&o.phone){let m=String(e.lead.phone).replace(/\D/g,""),a=l.dial.replace(/\D/g,""),x=m.startsWith(a)?m.slice(a.length):m;c.value=x.slice(0,c.maxLength);}return t.appendChild(u),t.appendChild(c),{wrap:t,select:u,input:c}}function pn(e){var H,M,N,S;let n=e.requestContact,t=document.createElement("div");t.className="nexor-chat__contact-view",t.setAttribute("data-state","form");let i=document.createElement("form");i.className="nexor-chat__capture nexor-chat__contact-form",i.noValidate=true;let l={},u=b=>{var P;return (P=e.capture.placeholders[b])!=null?P:xt[b]},c=document.createElement("div");c.className="nexor-chat__capture-row",l.first_name=oe("first_name",u("first_name"),"text",(H=e.lead)==null?void 0:H.first_name),l.last_name=oe("last_name",u("last_name"),"text",(M=e.lead)==null?void 0:M.last_name),c.appendChild(l.first_name),c.appendChild(l.last_name),i.appendChild(c),l.email=oe("email",u("email"),"email",(N=e.lead)==null?void 0:N.email),i.appendChild(l.email);let o=bt(e,u("phone"));l.phone=o.input;let m=o.select;i.appendChild(o.wrap);let a=document.createElement("p");a.className="nexor-chat__capture-error",a.setAttribute("role","alert"),a.hidden=true,i.appendChild(a);let x=document.createElement("button");x.type="submit",x.className="nexor-chat__capture-submit",i.appendChild(x),t.appendChild(i);let p=document.createElement("div");p.className="nexor-chat__contact-success";let f=document.createElement("div");f.className="nexor-chat__contact-success-icon",f.innerHTML=`
870
+ `,n.appendChild(m),{header:n,closeBtn:m,restartBtn:o,titleEl:s,subtitleEl:l,subtitleTextEl:c}}function ln(){let e=document.createElement("div");return e.className="nexor-chat__body",e}function cn(e,n){let t=document.createElement("div");t.className="nexor-chat__capture-view";let{form:s,error:l,phoneCountry:u}=dn(e,n);return t.appendChild(s),{view:t,form:s,error:l,phoneCountry:u}}var xt={first_name:"First name",last_name:"Last name",email:"Email",phone:"Phone"};function dn(e,n){var a,x,p;let t=document.createElement("form");t.className="nexor-chat__capture",t.noValidate=true;let s=null,l=document.createElement("p");l.className="nexor-chat__capture-label",l.textContent=e.capture.label,t.appendChild(l);let u=e.capture.fields,c=f=>{var I;return (I=e.capture.placeholders[f])!=null?I:xt[f]};if(u.includes("first_name")||u.includes("last_name")){let f=document.createElement("div");f.className="nexor-chat__capture-row",u.includes("first_name")&&(n.first_name=oe("first_name",c("first_name"),"text",(a=e.lead)==null?void 0:a.first_name),f.appendChild(n.first_name)),u.includes("last_name")&&(n.last_name=oe("last_name",c("last_name"),"text",(x=e.lead)==null?void 0:x.last_name),f.appendChild(n.last_name)),f.childElementCount>0&&t.appendChild(f);}if(u.includes("email")&&(n.email=oe("email",c("email"),"email",(p=e.lead)==null?void 0:p.email),t.appendChild(n.email)),u.includes("phone")){let f=bt(e,c("phone"));n.phone=f.input,s=f.select,t.appendChild(f.wrap);}let o=document.createElement("p");o.className="nexor-chat__capture-error",o.setAttribute("role","alert"),o.hidden=true,t.appendChild(o);let m=document.createElement("button");return m.type="submit",m.className="nexor-chat__capture-submit",m.textContent=e.capture.submitLabel,t.appendChild(m),{form:t,error:o,phoneCountry:s}}function un(e){if(!e.length)return me;let n=e.map(t=>J(t)).filter(t=>!!t);return n.length?n:me}function bt(e,n){var o;let t=document.createElement("div");t.className="nexor-chat__phone";let s=un(e.capture.phoneCountries),l=fe(e.capture.phoneCountryCode),u=document.createElement("select");u.className="nexor-chat__phone-country",u.name="phone_country",u.setAttribute("aria-label","Country code");for(let m of s){let a=document.createElement("option");a.value=m.iso,a.textContent=`${m.flag} ${m.dial}`,m.iso===l.iso&&(a.selected=true),u.appendChild(a);}let c=document.createElement("input");if(c.name="phone",c.type="tel",c.inputMode="numeric",c.autocomplete="tel-national",c.placeholder=n,c.className="nexor-chat__input nexor-chat__phone-number",c.maxLength=W(l),(o=e.lead)!=null&&o.phone){let m=String(e.lead.phone).replace(/\D/g,""),a=l.dial.replace(/\D/g,""),x=m.startsWith(a)?m.slice(a.length):m;c.value=x.slice(0,c.maxLength);}return t.appendChild(u),t.appendChild(c),{wrap:t,select:u,input:c}}function hn(e){var A,M,N,S;let n=e.requestContact,t=document.createElement("div");t.className="nexor-chat__contact-view",t.setAttribute("data-state","form");let s=document.createElement("form");s.className="nexor-chat__capture nexor-chat__contact-form",s.noValidate=true;let l={},u=b=>{var H;return (H=e.capture.placeholders[b])!=null?H:xt[b]},c=document.createElement("div");c.className="nexor-chat__capture-row",l.first_name=oe("first_name",u("first_name"),"text",(A=e.lead)==null?void 0:A.first_name),l.last_name=oe("last_name",u("last_name"),"text",(M=e.lead)==null?void 0:M.last_name),c.appendChild(l.first_name),c.appendChild(l.last_name),s.appendChild(c),l.email=oe("email",u("email"),"email",(N=e.lead)==null?void 0:N.email),s.appendChild(l.email);let o=bt(e,u("phone"));l.phone=o.input;let m=o.select;s.appendChild(o.wrap);let a=document.createElement("p");a.className="nexor-chat__capture-error",a.setAttribute("role","alert"),a.hidden=true,s.appendChild(a);let x=document.createElement("button");x.type="submit",x.className="nexor-chat__capture-submit",s.appendChild(x),t.appendChild(s);let p=document.createElement("div");p.className="nexor-chat__contact-success";let f=document.createElement("div");f.className="nexor-chat__contact-success-icon",f.innerHTML=`
871
871
  <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
872
872
  <path d="M5 13l4 4L19 7" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
873
- </svg>`;let I=document.createElement("p");I.className="nexor-chat__contact-success-text";let L=document.createElement("button");return L.type="button",L.className="nexor-chat__capture-submit",L.textContent=(S=n==null?void 0:n.doneLabel)!=null?S:"Done",p.appendChild(f),p.appendChild(I),p.appendChild(L),t.appendChild(p),{view:t,form:i,inputs:l,error:a,phoneCountry:m,submitBtn:x,success:p,successText:I,successBtn:L}}function hn(e){let n=document.createElement("form");n.className="nexor-chat__composer";let t=document.createElement("textarea");t.className="nexor-chat__input",t.placeholder=e.inputPlaceholder,t.rows=1,t.setAttribute("autocomplete","off");let i=document.createElement("button");return i.type="submit",i.className="nexor-chat__send",i.setAttribute("aria-label","Send message"),i.innerHTML=`
873
+ </svg>`;let I=document.createElement("p");I.className="nexor-chat__contact-success-text";let L=document.createElement("button");return L.type="button",L.className="nexor-chat__capture-submit",L.textContent=(S=n==null?void 0:n.doneLabel)!=null?S:"Done",p.appendChild(f),p.appendChild(I),p.appendChild(L),t.appendChild(p),{view:t,form:s,inputs:l,error:a,phoneCountry:m,submitBtn:x,success:p,successText:I,successBtn:L}}function mn(e){let n=document.createElement("form");n.className="nexor-chat__composer";let t=document.createElement("textarea");t.className="nexor-chat__input",t.placeholder=e.inputPlaceholder,t.rows=1,t.setAttribute("autocomplete","off");let s=document.createElement("button");return s.type="submit",s.className="nexor-chat__send",s.setAttribute("aria-label","Send message"),s.innerHTML=`
874
874
  <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
875
875
  <path d="M3.4 11.2 20.5 4.3c.7-.3 1.4.4 1.1 1.1l-6.9 17.1c-.3.8-1.4.8-1.8 0L10 14l-7.5-3c-.8-.3-.8-1.5 0-1.8Z"
876
876
  stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" fill="currentColor"/>
877
877
  </svg>
878
- `,n.appendChild(t),n.appendChild(i),{form:n,input:t,send:i}}var mn=`
878
+ `,n.appendChild(t),n.appendChild(s),{form:n,input:t,send:s}}var fn=`
879
879
  <svg viewBox="0 0 1722 505" fill="none" xmlns="http://www.w3.org/2000/svg" class="nexor-chat__brand-logo" role="img" aria-label="Nexor">
880
880
  <defs>
881
881
  <linearGradient id="nexorChatBrandGrad" x1="1195.44" y1="21.3423" x2="1195.44" y2="504.454" gradientUnits="userSpaceOnUse">
@@ -887,6 +887,6 @@ textarea.nexor-chat__input {
887
887
  <path d="M1195.22 21.3423C1199.01 21.3424 1202.55 23.2768 1205.81 26.6265C1209.06 29.9743 1212.14 34.8402 1215.03 40.9858C1220.81 53.2843 1225.98 70.9957 1230.31 92.7749C1236.49 123.842 1240.99 163.329 1243.06 207.497C1245.04 168.74 1249.06 134.088 1254.51 106.604C1258.48 86.5946 1263.23 70.315 1268.53 59.0063C1271.18 53.3557 1274 48.8741 1277 45.7866C1279.99 42.6974 1283.27 40.8979 1286.78 40.8979C1290.29 40.8981 1293.56 42.6975 1296.56 45.7866C1299.55 48.8741 1302.37 53.3556 1305.03 59.0063C1310.33 70.315 1315.07 86.5945 1319.04 106.604C1324.73 135.304 1328.87 171.821 1330.75 212.666C1332.39 186.451 1335.28 162.981 1339.08 144C1342.12 128.775 1345.76 116.368 1349.84 107.735C1351.88 103.422 1354.07 99.9788 1356.4 97.5962C1358.73 95.2117 1361.31 93.7866 1364.11 93.7866C1366.91 93.7866 1369.5 95.2116 1371.83 97.5962C1374.16 99.9788 1376.34 103.422 1378.38 107.735C1382.46 116.368 1386.1 128.775 1389.15 144C1393.72 166.881 1396.98 196.283 1398.32 229.154C1399.23 221.906 1400.42 215.317 1401.84 209.621C1403.54 202.788 1405.59 197.165 1407.92 193.217C1410.19 189.36 1412.99 186.675 1416.33 186.675C1419.68 186.676 1422.47 189.36 1424.75 193.217C1427.07 197.165 1429.12 202.788 1430.83 209.621C1434.24 223.306 1436.33 242.142 1436.33 262.898C1436.33 283.654 1434.24 302.489 1430.83 316.174C1429.12 323.007 1427.07 328.631 1424.75 332.579C1422.47 336.436 1419.68 339.119 1416.33 339.12C1412.99 339.12 1410.19 336.436 1407.92 332.579C1405.59 328.631 1403.54 323.007 1401.84 316.174C1400.42 310.478 1399.23 303.889 1398.32 296.641C1396.98 329.512 1393.72 358.915 1389.15 381.796C1386.1 397.021 1382.46 409.428 1378.38 418.061C1376.34 422.374 1374.16 425.816 1371.83 428.199C1369.5 430.583 1366.91 432.009 1364.11 432.009C1361.31 432.009 1358.73 430.584 1356.4 428.199C1354.07 425.816 1351.88 422.374 1349.84 418.061C1345.76 409.428 1342.12 397.021 1339.08 381.796C1335.28 362.814 1332.39 339.344 1330.75 313.129C1328.87 353.974 1324.73 390.492 1319.04 419.192C1315.07 439.201 1310.33 455.481 1305.03 466.79C1302.37 472.44 1299.55 476.922 1296.56 480.009C1293.56 483.098 1290.29 484.898 1286.78 484.898C1283.27 484.898 1279.99 483.098 1277 480.009C1274 476.922 1271.18 472.44 1268.53 466.79C1263.23 455.481 1258.48 439.201 1254.51 419.192C1249.06 391.708 1245.04 357.055 1243.06 318.298C1240.99 362.466 1236.49 401.953 1230.31 433.021C1225.98 454.8 1220.81 472.512 1215.03 484.81C1212.14 490.956 1209.06 495.822 1205.81 499.169C1202.55 502.519 1199.01 504.454 1195.22 504.454C1191.44 504.454 1187.89 502.519 1184.64 499.169C1181.38 495.822 1178.31 490.956 1175.42 484.81C1169.64 472.512 1164.46 454.8 1160.13 433.021C1153.95 401.956 1149.46 362.472 1147.39 318.308C1145.4 357.061 1141.38 391.71 1135.93 419.192C1131.96 439.202 1127.22 455.481 1121.91 466.79C1119.26 472.44 1116.44 476.922 1113.45 480.009C1110.45 483.098 1107.18 484.898 1103.67 484.898C1100.16 484.898 1096.88 483.098 1093.89 480.009C1090.89 476.922 1088.07 472.44 1085.42 466.79C1080.12 455.481 1075.37 439.202 1071.4 419.192C1065.71 390.491 1061.58 353.973 1059.69 313.128C1058.05 339.344 1055.16 362.814 1051.37 381.796C1048.32 397.021 1044.68 409.428 1040.6 418.061C1038.56 422.374 1036.38 425.816 1034.05 428.199C1031.72 430.583 1029.14 432.009 1026.33 432.009C1023.53 432.009 1020.95 430.584 1018.62 428.199C1016.29 425.816 1014.11 422.374 1012.07 418.061C1007.99 409.428 1004.34 397.021 1001.3 381.796C996.723 358.916 993.462 329.514 992.122 296.645C991.214 303.891 990.024 310.479 988.604 316.174C986.901 323.007 984.852 328.631 982.525 332.579C980.252 336.436 977.453 339.12 974.111 339.12C970.77 339.12 967.97 336.436 965.697 332.579C963.371 328.631 961.321 323.007 959.618 316.174C956.207 302.489 954.111 283.654 954.111 262.898C954.111 242.142 956.207 223.306 959.618 209.621C961.321 202.788 963.371 197.165 965.697 193.217C967.97 189.36 970.77 186.675 974.111 186.675C977.453 186.675 980.252 189.36 982.525 193.217C984.852 197.165 986.901 202.788 988.604 209.621C990.024 215.316 991.214 221.904 992.122 229.15C993.462 196.281 996.723 166.88 1001.3 144C1004.34 128.775 1007.99 116.368 1012.07 107.735C1014.11 103.422 1016.29 99.9787 1018.62 97.5962C1020.95 95.2115 1023.53 93.7866 1026.33 93.7866C1029.14 93.7868 1031.72 95.2116 1034.05 97.5962C1036.38 99.9787 1038.56 103.422 1040.6 107.735C1044.68 116.368 1048.32 128.775 1051.37 144C1055.16 162.981 1058.05 186.451 1059.69 212.666C1061.58 171.821 1065.71 135.304 1071.4 106.604C1075.37 86.5944 1080.12 70.315 1085.42 59.0063C1088.07 53.3558 1090.89 48.8741 1093.89 45.7866C1096.88 42.6974 1100.16 40.8979 1103.67 40.8979C1107.18 40.898 1110.45 42.6975 1113.45 45.7866C1116.44 48.8741 1119.26 53.3558 1121.91 59.0063C1127.22 70.315 1131.96 86.5945 1135.93 106.604C1141.38 134.086 1145.4 168.735 1147.39 207.487C1149.46 163.323 1153.95 123.84 1160.13 92.7749C1164.46 70.9957 1169.64 53.2843 1175.42 40.9858C1178.31 34.8403 1181.38 29.9743 1184.64 26.6265C1187.89 23.2769 1191.44 21.3423 1195.22 21.3423Z" fill="url(#nexorChatBrandGrad)"/>
888
888
  <path d="M1490.82 416.676V103.332H1525.71L1541.01 146.784C1559.98 106.392 1596.7 95.3758 1652.39 99.0477V155.964C1588.13 146.784 1556.31 177.996 1556.31 251.436V416.676H1490.82Z" fill="#232522"/>
889
889
  <path d="M1681.68 78.9118C1650.58 78.9118 1642.32 61.0558 1642.32 39.3598C1642.32 17.9518 1650.86 -0.000219345 1681.68 -0.000219345C1712.88 -0.000219345 1721.04 17.9518 1721.04 39.4558C1721.04 61.0558 1712.88 78.9118 1681.68 78.9118ZM1651.82 39.4558C1651.82 57.3118 1658.26 70.7518 1681.68 70.7518C1705.2 70.7518 1711.54 57.3118 1711.54 39.4558C1711.54 21.5998 1705.2 8.15978 1681.68 8.15978C1658.35 8.15978 1651.82 21.6958 1651.82 39.4558ZM1662.1 39.8398C1662.1 28.2238 1666.9 18.3358 1681.87 18.3358C1693.87 18.3358 1700.11 25.0558 1700.11 36.1918H1691.28C1690.7 29.2798 1687.82 26.3998 1681.78 26.3998C1674.1 26.3998 1671.02 31.2958 1671.02 39.5518C1671.02 47.9038 1674.1 52.8958 1681.78 52.8958C1687.82 52.8958 1690.8 50.0158 1691.28 43.3918H1700.11C1700.11 54.6238 1694.16 61.0558 1682.16 61.0558C1666.9 61.0558 1662.1 51.2638 1662.1 39.8398Z" fill="#232522"/>
890
- </svg>`;function fn(){let e=document.createElement("div");return e.className="nexor-chat__footer",e.innerHTML=`<span>Powered by</span><span class="nexor-chat__brand" aria-label="Nexor"><span class="nexor-chat__brand-tip" role="tooltip">getnexor.ai</span>${mn}</span>`,e}function Ct(e,n,t,i){let l=document.createElement("div");l.className=`nexor-chat__msg nexor-chat__msg--${e}`;let u=document.createElement("span");if(u.className="nexor-chat__msg-text",u.textContent=n,l.appendChild(u),e!=="system"&&t){let c=document.createElement("time");c.className="nexor-chat__msg-time",c.dataset.ts=String(t),c.textContent=qe(t,i),l.appendChild(c);}return l}function qe(e,n,t=Date.now()){try{let i=Math.max(0,t-e),l=Math.round(i/6e4),u=Math.round(i/36e5),c=Math.round(i/864e5),o=new Intl.RelativeTimeFormat(n,{numeric:"auto"});return i<45e3?o.format(0,"second"):l<60?o.format(-l,"minute"):u<24?o.format(-u,"hour"):c<7?o.format(-c,"day"):new Date(e).toLocaleDateString(n,{day:"numeric",month:"short"})}catch(i){try{return new Date(e).toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"})}catch(l){return ""}}}function _t(e,n){let t=document.createElement("div");t.className="nexor-chat__resume";let i=document.createElement("span");i.className="nexor-chat__resume-text",i.textContent=e;let l=document.createElement("button");return l.type="button",l.className="nexor-chat__resume-reset",l.textContent=n,t.appendChild(i),t.appendChild(l),{el:t,resetBtn:l}}function yt(){let e=document.createElement("div");return e.className="nexor-chat__typing",e.innerHTML="<span></span><span></span><span></span>",e}function oe(e,n,t,i){let l=document.createElement("input");return l.name=e,l.type=t,l.placeholder=n,i&&(l.value=i),l}function wt(e,n){var Ke,ze,We,je;if(xn(),!n||!n.workflowId)throw new Error("Nexor SDK: initChat() requires `workflowId`.");let t=at(n);ht(t.accentColor,t.accentTextColor);let i=st(),l=`nexor.chat.history.${i}`,u=bn(t),c=ft(t),o=gt(t);u.appendChild(c.wrap),u.appendChild(o.el),((Ke=t.container)!=null?Ke:document.body).appendChild(u);let m=c.channelButtons.length>0,a={isOpen:false,expanded:false,unread:0,leadId:void 0,captured:!ke(t),pendingLead:{...(ze=t.lead)!=null?ze:{}},history:[],webchatEnabled:true,serverInitialMessage:null,configResolved:false,disabledShown:false,shownOpening:null,resetEpisode:false,freshLocalSession:false,episodeChoiceOffered:false,contactChannel:null,leadCreating:null},x,p={pending:[],timer:0,inFlight:false,typing:null,splitTimer:0},f={pending:false,timer:0},I=2e3;c.el.addEventListener("click",m?N:O),o.closeBtn.addEventListener("click",q),(We=o.restartBtn)==null||We.addEventListener("click",de),o.form.addEventListener("submit",ue),o.input.addEventListener("input",pe),o.input.addEventListener("keydown",r=>{r.key==="Enter"&&!r.shiftKey&&!r.isComposing&&(r.preventDefault(),ue(r));}),(je=o.captureForm)==null||je.addEventListener("submit",j);for(let r of Object.values(o.captureInputs))r==null||r.addEventListener("input",K);if(o.phoneCountry&&o.captureInputs.phone&&ie(o.phoneCountry,o.captureInputs.phone,K),o.contact){let r=o.contact;r.form.addEventListener("submit",be);for(let s of Object.values(r.inputs))s==null||s.addEventListener("input",G);r.phoneCountry&&r.inputs.phone&&ie(r.phoneCountry,r.inputs.phone,G),r.successBtn.addEventListener("click",q);}let L=null;if(m){for(let r of c.channelButtons)r.el.addEventListener("click",()=>{r.key==="chat"?(b(),P()):r.action==="contact"?(b(),ge(r.key)):b();});L=r=>{a.expanded&&!c.wrap.contains(r.target)&&b();},document.addEventListener("pointerdown",L);}let H=null,M=It();if(a.freshLocalSession=M.history.length===0,M.history.length){a.history=M.history,M.lead&&(a.pendingLead={...a.pendingLead,...M.lead}),a.captured=true,D("chat"),ce();for(let r of M.history)Ee(r.role==="user"?"user":"bot",r.text,r.ts);Pe();}Re(),x=vt(),t.openOnLoad&&P();function N(){a.expanded?b():S();}function S(){a.expanded=true,c.wrap.setAttribute("data-expanded","true"),c.el.setAttribute("aria-expanded","true");}function b(){a.expanded&&(a.expanded=false,c.wrap.setAttribute("data-expanded","false"),c.el.setAttribute("aria-expanded","false"));}function P(){var r,s;if(b(),!a.isOpen){if(a.isOpen=true,u.setAttribute("data-open","true"),Fe(),!a.webchatEnabled){De(),(r=t.onOpen)==null||r.call(t);return}if(a.history.length===0&&a.captured&&ee()&&Ie(),a.captured)o.input.focus();else {let d=t.capture.fields[0];(d&&o.captureInputs[d]||o.input).focus();}(s=t.onOpen)==null||s.call(t);}}function q(){var r;a.isOpen&&(a.isOpen=false,u.setAttribute("data-open","false"),o.el.getAttribute("data-view")==="contact"&&(a.contactChannel=null,D(_e()),w()),(r=t.onClose)==null||r.call(t));}function w(){var r;o.headerTitle.textContent=t.title,o.headerSubtitleText.textContent=(r=t.subtitle)!=null?r:"",o.headerSubtitle.hidden=!t.subtitle;}function O(){a.isOpen?q():P();}function j(r){var g,C,_;r.preventDefault(),K();let s=Cn(o),d=t.capture.fields,h=t.capture.errorMessages;for(let y of d)if(!s[y])return $(y,h.required);if(d.includes("email")&&!Oe((g=s.email)!=null?g:""))return $("email",h.email);if(d.includes("phone")){let y=J((C=o.phoneCountry)==null?void 0:C.value),v=((_=s.phone)!=null?_:"").replace(/\D/g,"");if(!y||v.length<y.nsn[0]||v.length>y.nsn[1])return $("phone",h.phone);s.phone=`${y.dial}${v}`;}a.pendingLead={...a.pendingLead,...s},a.captured=true,Q(),D("chat"),Re(),o.input.focus(),a.history.length===0&&ee()&&Ie();}function Q(){if(!t.capture.createLeadOnSubmit||a.leadId)return;let r=a.pendingLead;if(!r.first_name&&!r.email&&!r.phone)return;let s=typeof t.metadata=="function"?t.metadata():t.metadata;a.leadCreating=e.createLead({first_name:r.first_name||"Web visitor",last_name:r.last_name,email:r.email,phone:r.phone,source:"web-chat",metadata:{...s,web_chat_session_id:i}}).then(d=>{var h,g;(h=d==null?void 0:d.lead)!=null&&h.id&&!a.leadId&&(a.leadId=d.lead.id,(g=t.onLeadCaptured)==null||g.call(t,d.lead.id)),d&&!d.existed&&(a.episodeChoiceOffered=true);}).catch(d=>{var h;(h=t.onError)==null||h.call(t,d);}).finally(()=>{a.leadCreating=null;});}function $(r,s){F(s);let d=o.captureInputs[r],h=(d==null?void 0:d.closest(".nexor-chat__phone"))||d;h==null||h.classList.add("nexor-chat__input--error"),d==null||d.focus();}function F(r){o.captureError&&(o.captureError.textContent=r,o.captureError.hidden=false);}function K(){var r;o.captureError&&(o.captureError.textContent="",o.captureError.hidden=true),(r=o.captureForm)==null||r.querySelectorAll(".nexor-chat__input--error").forEach(s=>s.classList.remove("nexor-chat__input--error"));}function ie(r,s,d){let h=()=>{let g=J(r.value),C=g?W(g):15;s.maxLength=C;let _=s.value.replace(/\D/g,"").slice(0,C);s.value!==_&&(s.value=_);};s.addEventListener("input",h),r.addEventListener("change",()=>{h(),d==null||d();});}function ge(r){var g,C,_,y,v,B,z;let s=o.contact,d=t.requestContact;if(!s||!d)return;a.contactChannel=r,o.headerTitle.textContent=(g=d.title[r])!=null?g:t.title,o.headerSubtitleText.textContent=(C=d.subtitle[r])!=null?C:"",o.headerSubtitle.hidden=!d.subtitle[r],s.submitBtn.textContent=(_=d.submitLabel[r])!=null?_:"",s.successText.textContent=(y=d.successText[r])!=null?y:"",s.view.setAttribute("data-state","form"),s.submitBtn.disabled=false,G(),xe(),Le(),a.isOpen=true,u.setAttribute("data-open","true"),Fe(),D("contact");let h=[s.inputs.first_name,s.inputs.email,s.inputs.phone].find(A=>A&&!A.value);(B=(v=h!=null?h:s.inputs.first_name)!=null?v:null)==null||B.focus(),(z=t.onOpen)==null||z.call(t);}function xe(){var h,g,C;let r=o.contact;if(!r)return;let s=a.pendingLead;r.inputs.first_name&&(r.inputs.first_name.value=(h=s.first_name)!=null?h:""),r.inputs.last_name&&(r.inputs.last_name.value=(g=s.last_name)!=null?g:""),r.inputs.email&&(r.inputs.email.value=(C=s.email)!=null?C:"");let d=fe(t.capture.phoneCountryCode);if(r.phoneCountry&&(r.phoneCountry.value=d.iso),r.inputs.phone){let _="";if(s.phone){let y=String(s.phone).replace(/\D/g,""),v=d.dial.replace(/\D/g,"");_=(y.startsWith(v)?y.slice(v.length):y).slice(0,W(d));}r.inputs.phone.maxLength=W(d),r.inputs.phone.value=_;}}function be(r){var A,Ve,Ge,Ye,Xe,Ze,Je,Qe,et;r.preventDefault();let s=o.contact,d=a.contactChannel;if(!s||!d)return;G();let h=t.capture.errorMessages,g=(Ve=(A=s.inputs.first_name)==null?void 0:A.value.trim())!=null?Ve:"",C=(Ye=(Ge=s.inputs.last_name)==null?void 0:Ge.value.trim())!=null?Ye:"",_=(Ze=(Xe=s.inputs.email)==null?void 0:Xe.value.trim())!=null?Ze:"",y=((Qe=(Je=s.inputs.phone)==null?void 0:Je.value)!=null?Qe:"").replace(/\D/g,"");if(!g)return V("first_name",h.required);if(d==="email"&&!_)return V("email",h.required);if(_&&!Oe(_))return V("email",h.email);let B=d==="call"||d==="whatsapp",z;if(B||y){let Me=J((et=s.phoneCountry)==null?void 0:et.value);if(!Me||y.length<Me.nsn[0]||y.length>Me.nsn[1])return V("phone",h.phone);z=`${Me.dial}${y}`;}Ce(d,{first:g,last:C,email:_,phone:z});}async function Ce(r,s){var y,v,B,z;let d=o.contact,h=t.requestContact;if(!d||!h)return;d.submitBtn.disabled=true;let g=typeof t.metadata=="function"?t.metadata():t.metadata,C=g!=null?g:void 0,_=C&&C.page_url||(typeof window!="undefined"?window.location.href:void 0);try{let A=await e.requestContact({workflow_id:t.workflowId,first_name:s.first,last_name:s.last||void 0,email:s.email||void 0,phone:s.phone,force_first_channel:r,source:"web-chat",metadata:{...C!=null?C:{},contact_request:!0,requested_channel:r,requested_at:new Date().toISOString(),context_note:`Website visitor asked to be contacted via ${r}${_?` from ${_}`:""}.`}},{timeoutMs:t.requestTimeoutMs,maxRetries:0});(y=A==null?void 0:A.lead)!=null&&y.id&&!a.leadId&&(a.leadId=A.lead.id,(v=t.onLeadCaptured)==null||v.call(t,A.lead.id)),d.successText.textContent=(B=h.successText[r])!=null?B:"",o.headerSubtitle.hidden=!0,d.view.setAttribute("data-state","sent");}catch(A){d.submitBtn.disabled=false,le(h.errorText),(z=t.onError)==null||z.call(t,A);}}function V(r,s){let d=o.contact;if(!d)return;le(s);let h=d.inputs[r],g=(h==null?void 0:h.closest(".nexor-chat__phone"))||h;g==null||g.classList.add("nexor-chat__input--error"),h==null||h.focus();}function le(r){let s=o.contact;s&&(s.error.textContent=r,s.error.hidden=false);}function G(){let r=o.contact;r&&(r.error.textContent="",r.error.hidden=true,r.form.querySelectorAll(".nexor-chat__input--error").forEach(s=>s.classList.remove("nexor-chat__input--error")));}function D(r){o.el.setAttribute("data-view",r);}function _e(){return a.captured?"chat":"capture"}function ye(){let r=a.pendingLead,s=(r.first_name||r.email||r.phone||"").trim();return s?t.resumeWithNameText.replace("{name}",s):t.resumeText}function ce(r=false){if(H)return;let s=_t(ye(),t.startOverText);s.resetBtn.addEventListener("click",de),r&&o.body.firstChild?o.body.insertBefore(s.el,o.body.firstChild):o.body.appendChild(s.el),H=s.el;}function de(){var r;Le(),p.timer&&(window.clearTimeout(p.timer),p.timer=0),p.splitTimer&&(window.clearTimeout(p.splitTimer),p.splitTimer=0),p.pending=[],Y();try{window.localStorage.removeItem(l);}catch(s){}if(a.history=[],a.shownOpening=null,H=null,o.body.replaceChildren(),o.captureView){a.pendingLead={...(r=t.lead)!=null?r:{}},a.captured=false,a.leadId=void 0,a.episodeChoiceOffered=false,a.resetEpisode=true,we(),D("capture"),Re();let s=t.capture.fields[0];(s&&o.captureInputs[s]||o.input).focus();return}a.resetEpisode=true,D("chat"),Re(),a.captured&&ee()&&Ie(),o.input.focus();}function we(){var d,h,g;let r=a.pendingLead;o.captureInputs.first_name&&(o.captureInputs.first_name.value=(d=r.first_name)!=null?d:""),o.captureInputs.last_name&&(o.captureInputs.last_name.value=(h=r.last_name)!=null?h:""),o.captureInputs.email&&(o.captureInputs.email.value=(g=r.email)!=null?g:"");let s=fe(t.capture.phoneCountryCode);if(o.phoneCountry&&(o.phoneCountry.value=s.iso),o.captureInputs.phone){let C="";if(r.phone){let _=String(r.phone).replace(/\D/g,""),y=s.dial.replace(/\D/g,"");C=(_.startsWith(y)?_.slice(y.length):_).slice(0,W(s));}o.captureInputs.phone.maxLength=W(s),o.captureInputs.phone.value=C;}K();}function ue(r){r.preventDefault();let s=o.input.value.trim();s&&(o.input.value="",pe(),he(s));}function pe(){let r=o.input;r.style.height="auto",r.style.height=`${r.scrollHeight+2}px`;}function he(r){if(!a.captured){let s=t.capture.fields[0];(s&&o.captureInputs[s]||o.input).focus();return}Le(),Et(r),p.pending.push(r),Be();}function ve(){var s;let r=t.openingMessage||a.serverInitialMessage;return r?ct(r,a.pendingLead):(s=t.greeting)!=null?s:""}function ee(){return a.webchatEnabled?t.openingMessage||!a.configResolved?true:!!a.serverInitialMessage||!!t.greeting:false}function Ie(){f.pending||(f.pending=true,Se(),f.timer=window.setTimeout(async()=>{if(t.openingMessage||await x,!f.pending)return;f.pending=false,f.timer=0,Y();let r=ve();r&&(a.shownOpening=r,Te(r));},I));}function Le(){f.pending&&(f.timer&&window.clearTimeout(f.timer),f.timer=0,f.pending=false,Y());}async function vt(){var r;try{let s=await e.getChatConfig(t.workflowId,{timeoutMs:1e4,maxRetries:1});Ne(s.enabled!==!1,(r=s.initial_message)!=null?r:null);}catch(s){Ne(true,null);}}function Ne(r,s){a.configResolved=true,a.serverInitialMessage=s,a.webchatEnabled=r,r||(Lt(),Le(),a.isOpen&&De());}function De(){D("chat"),a.disabledShown||(He(t.disabledText),a.disabledShown=true),o.input.disabled=true,o.send.disabled=true,o.input.placeholder=t.disabledText;}function Lt(){for(let r of c.channelButtons){if(r.key!=="chat")continue;let s=r.el.closest(".nexor-chat__channel-item");s instanceof HTMLElement&&(s.style.display="none");}}function Se(){if(p.typing){o.body.appendChild(p.typing),Pe();return}p.typing=$e(yt());}function Y(){var r;(r=p.typing)==null||r.remove(),p.typing=null;}function Be(){Se(),p.timer&&window.clearTimeout(p.timer),p.timer=window.setTimeout(()=>{Tt();},t.debounceMs);}async function Tt(){var h,g,C,_,y;if(p.inFlight||p.pending.length===0)return;let s=p.pending.splice(0,p.pending.length).join(`
891
- `);if(p.inFlight=true,a.leadCreating)try{await a.leadCreating;}catch(v){}let d=a.resetEpisode;try{let v=await e.chat({workflow_id:t.workflowId,session_id:i,message:s,system_prompt:t.systemPrompt,client_prompt:t.clientPrompt,opening_shown:(h=a.shownOpening)!=null?h:void 0,reset_episode:d||void 0,lead:Object.keys(a.pendingLead).length?a.pendingLead:void 0,metadata:typeof t.metadata=="function"?t.metadata():t.metadata},{timeoutMs:t.requestTimeoutMs,maxRetries:0});d&&(a.resetEpisode=!1),v.lead_id&&!a.leadId&&(a.leadId=v.lead_id,(g=t.onLeadCaptured)==null||g.call(t,a.leadId)),v.matched_existing&&a.freshLocalSession&&!a.episodeChoiceOffered&&!d&&(a.episodeChoiceOffered=!0,ce(!0));let B=((C=v.reply)!=null?C:"").trim();Y(),B?Rt(B):(He(t.errorText),(_=t.onError)==null||_.call(t,new Error("Nexor SDK: empty reply from server")));}catch(v){Y(),/web chat is not enabled/i.test((v==null?void 0:v.message)||"")?Ne(false,a.serverInitialMessage):He(t.errorText),(y=t.onError)==null||y.call(t,v);}finally{p.splitTimer||Y(),p.inFlight=false,o.input.focus(),p.pending.length&&Be();}}function Et(r){var d;let s=Date.now();Ee("user",r,s),a.history.push({role:"user",text:r,ts:s}),Ue(),(d=t.onMessage)==null||d.call(t,{role:"user",text:r});}function Te(r,s=true){var h;let d=s?Date.now():void 0;Ee("bot",r,d),a.history.push({role:"bot",text:r,ts:d}),Ue(),a.isOpen||St(),(h=t.onMessage)==null||h.call(t,{role:"bot",text:r});}function Rt(r){let s=t.splitReplies?Mt(r):[r];if(s.length<=1){Te(r);return}let[d,...h]=s;Te(d!=null?d:r,false);let g=0,C=()=>{let _=h[g];if(_===void 0)return;let y=g===h.length-1;g++,Se();let v=t.splitDelayMs>0?t.splitDelayMs:kt(_);p.splitTimer=window.setTimeout(()=>{p.splitTimer=0,Y(),Te(_,y),C();},v);};C();}function Mt(r){let s=r.split(/\n[ \t]*\n+/).map(d=>d.trim()).filter(Boolean);return s.length?s:[r]}function kt(r){let g=3e3+Math.min(r.length,180)*11.11111111111111,C=Math.random()*300-150;return Math.round(Math.max(3e3,Math.min(5e3,g+C)))}function Ue(){try{window.localStorage.setItem(l,JSON.stringify({ts:Date.now(),history:a.history,lead:a.pendingLead})),it();}catch(r){}}function It(){let r={history:[],lead:void 0};try{let s=window.localStorage.getItem(l);if(!s)return r;let d=JSON.parse(s);return !d||!Array.isArray(d.history)?r:Date.now()-(d.ts||0)>2592e6?(window.localStorage.removeItem(l),r):{history:d.history,lead:d.lead&&typeof d.lead=="object"?d.lead:void 0}}catch(s){return r}}function He(r){Ee("system",r);}function Ee(r,s,d){return $e(Ct(r,s,d,t.locale))}let Nt=window.setInterval(()=>{o.body.querySelectorAll(".nexor-chat__msg-time[data-ts]").forEach(r=>{let s=Number(r.dataset.ts);s&&(r.textContent=qe(s,t.locale));});},6e4);function $e(r){return o.body.appendChild(r),p.typing&&p.typing!==r&&o.body.appendChild(p.typing),Pe(),r}function Pe(){o.body.scrollTop=o.body.scrollHeight;}function St(){a.unread++,c.badge.textContent=String(a.unread),c.badge.style.display="flex";}function Fe(){a.unread=0,c.badge.style.display="none";}function Re(){let r=!a.captured;o.input.disabled=r,o.send.disabled=r,o.input.placeholder=r?"Complete the form above to start\u2026":t.inputPlaceholder;}return {open:P,close:q,toggle:O,send:r=>(he(r),Promise.resolve()),destroy:()=>{p.timer&&window.clearTimeout(p.timer),p.splitTimer&&window.clearTimeout(p.splitTimer),f.timer&&window.clearTimeout(f.timer),window.clearInterval(Nt),L&&document.removeEventListener("pointerdown",L),u.remove();},getSessionId:()=>i}}function xn(){if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Nexor SDK: initChat() requires a browser environment.")}function bn(e){let n=document.createElement("div");return n.className="nexor-chat",n.setAttribute("data-position",e.position),n.setAttribute("data-open","false"),n}function Cn(e){let n={},t=e.captureInputs;return t.first_name&&(n.first_name=t.first_name.value.trim()),t.last_name&&(n.last_name=t.last_name.value.trim()),t.email&&(n.email=t.email.value.trim()),t.phone&&(n.phone=t.phone.value.replace(/\D/g,"")),n}function _n(e){return new Z(e)}var se=null;function k(){if(!se)throw new Error("Nexor SDK: call `nexor.init({ apiKey })` before using the API.");return se}function yn(e){return se=new Z(e),se}function wn(){return se!==null}function vn(){se=null;}var T={init:yn,isInitialized:wn,reset:vn,createLead:((...e)=>k().createLead(...e)),createLeadsBulk:((...e)=>k().createLeadsBulk(...e)),updateLead:((...e)=>k().updateLead(...e)),getLead:((...e)=>k().getLead(...e)),getLeadHistory:((...e)=>k().getLeadHistory(...e)),isLeadPaused:((...e)=>k().isLeadPaused(...e)),stopAutomation:((...e)=>k().stopAutomation(...e)),resumeAutomation:((...e)=>k().resumeAutomation(...e)),syncLeadTags:((...e)=>k().syncLeadTags(...e)),listLeadMeetings:((...e)=>k().listLeadMeetings(...e)),listWorkflows:((...e)=>k().listWorkflows(...e)),listCampaigns:((...e)=>k().listCampaigns(...e)),listTemplates:((...e)=>k().listTemplates(...e)),sendMessage:((...e)=>k().sendMessage(...e)),createMeeting:((...e)=>k().createMeeting(...e)),createMeetingNotes:((...e)=>k().createMeetingNotes(...e)),initChat:e=>wt(k(),e)};var Qn=T.init,er=T.isInitialized,tr=T.reset,nr=T.initChat,rr=T.createLead,ar=T.createLeadsBulk,or=T.updateLead,sr=T.getLead,ir=T.getLeadHistory,lr=T.isLeadPaused,cr=T.stopAutomation,dr=T.resumeAutomation,ur=T.syncLeadTags,pr=T.listLeadMeetings,hr=T.listWorkflows,mr=T.listCampaigns,fr=T.listTemplates,gr=T.sendMessage,xr=T.createMeeting,br=T.createMeetingNotes;exports.NexorAPIError=U;exports.NexorAuthError=ne;exports.NexorClient=Z;exports.NexorError=te;exports.NexorNetworkError=X;exports.NexorValidationError=re;exports.createClient=_n;exports.createLead=rr;exports.createLeadsBulk=ar;exports.createMeeting=xr;exports.createMeetingNotes=br;exports.getLead=sr;exports.getLeadHistory=ir;exports.init=Qn;exports.initChat=nr;exports.isInitialized=er;exports.isLeadPaused=lr;exports.listCampaigns=mr;exports.listLeadMeetings=pr;exports.listTemplates=fr;exports.listWorkflows=hr;exports.reset=tr;exports.resumeAutomation=dr;exports.sendMessage=gr;exports.stopAutomation=cr;exports.syncLeadTags=ur;exports.updateLead=or;return exports;})({});//# sourceMappingURL=nexor.iife.js.map
890
+ </svg>`;function gn(){let e=document.createElement("div");return e.className="nexor-chat__footer",e.innerHTML=`<span>Powered by</span><span class="nexor-chat__brand" aria-label="Nexor"><span class="nexor-chat__brand-tip" role="tooltip">getnexor.ai</span>${fn}</span>`,e}function Ct(e,n,t,s){let l=document.createElement("div");l.className=`nexor-chat__msg nexor-chat__msg--${e}`;let u=document.createElement("span");if(u.className="nexor-chat__msg-text",u.textContent=n,l.appendChild(u),e!=="system"&&t){let c=document.createElement("time");c.className="nexor-chat__msg-time",c.dataset.ts=String(t),c.textContent=qe(t,s),l.appendChild(c);}return l}function qe(e,n,t=Date.now()){try{let s=Math.max(0,t-e),l=Math.round(s/6e4),u=Math.round(s/36e5),c=Math.round(s/864e5),o=new Intl.RelativeTimeFormat(n,{numeric:"auto"});return s<45e3?o.format(0,"second"):l<60?o.format(-l,"minute"):u<24?o.format(-u,"hour"):c<7?o.format(-c,"day"):new Date(e).toLocaleDateString(n,{day:"numeric",month:"short"})}catch(s){try{return new Date(e).toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"})}catch(l){return ""}}}function _t(e,n){let t=document.createElement("div");t.className="nexor-chat__resume";let s=document.createElement("span");s.className="nexor-chat__resume-text",s.textContent=e;let l=document.createElement("button");return l.type="button",l.className="nexor-chat__resume-reset",l.textContent=n,t.appendChild(s),t.appendChild(l),{el:t,resetBtn:l}}function yt(){let e=document.createElement("div");return e.className="nexor-chat__typing",e.innerHTML="<span></span><span></span><span></span>",e}function oe(e,n,t,s){let l=document.createElement("input");return l.name=e,l.type=t,l.placeholder=n,s&&(l.value=s),l}function wt(e,n){var ze,Ke,We,je;if(bn(),!n||!n.workflowId)throw new Error("Nexor SDK: initChat() requires `workflowId`.");let t=at(n);ht(t.accentColor,t.accentTextColor);let s=st(),l=`nexor.chat.history.${s}`,u=Cn(t),c=ft(t),o=gt(t);u.appendChild(c.wrap),u.appendChild(o.el),((ze=t.container)!=null?ze:document.body).appendChild(u);let m=c.channelButtons.length>0,a={isOpen:false,expanded:false,unread:0,leadId:void 0,captured:!ke(t),pendingLead:{...(Ke=t.lead)!=null?Ke:{}},history:[],webchatEnabled:true,serverInitialMessage:null,configResolved:false,disabledShown:false,shownOpening:null,resetEpisode:false,freshLocalSession:false,episodeChoiceOffered:false,contactChannel:null,leadCreating:null},x,p={pending:[],timer:0,inFlight:false,typing:null,splitTimer:0},f={pending:false,timer:0},I=2e3;c.el.addEventListener("click",m?N:O),o.closeBtn.addEventListener("click",q),(We=o.restartBtn)==null||We.addEventListener("click",de),o.form.addEventListener("submit",ue),o.input.addEventListener("input",pe),o.input.addEventListener("keydown",r=>{r.key==="Enter"&&!r.shiftKey&&!r.isComposing&&(r.preventDefault(),ue(r));}),(je=o.captureForm)==null||je.addEventListener("submit",j);for(let r of Object.values(o.captureInputs))r==null||r.addEventListener("input",z);if(o.phoneCountry&&o.captureInputs.phone&&ie(o.phoneCountry,o.captureInputs.phone,z),o.contact){let r=o.contact;r.form.addEventListener("submit",be);for(let i of Object.values(r.inputs))i==null||i.addEventListener("input",G);r.phoneCountry&&r.inputs.phone&&ie(r.phoneCountry,r.inputs.phone,G),r.successBtn.addEventListener("click",q);}let L=null;if(m){for(let r of c.channelButtons)r.el.addEventListener("click",()=>{r.key==="chat"?(b(),H()):r.action==="contact"?(b(),ge(r.key)):b();});L=r=>{a.expanded&&!c.wrap.contains(r.target)&&b();},document.addEventListener("pointerdown",L);}let A=null,M=It();if(a.freshLocalSession=M.history.length===0,M.history.length){a.history=M.history,M.lead&&(a.pendingLead={...a.pendingLead,...M.lead}),a.captured=true,D("chat"),ce();for(let r of M.history)Ee(r.role==="user"?"user":"bot",r.text,r.ts);He();}Re(),x=vt(),t.openOnLoad&&H();function N(){a.expanded?b():S();}function S(){a.expanded=true,c.wrap.setAttribute("data-expanded","true"),c.el.setAttribute("aria-expanded","true");}function b(){a.expanded&&(a.expanded=false,c.wrap.setAttribute("data-expanded","false"),c.el.setAttribute("aria-expanded","false"));}function H(){var r,i;if(b(),!a.isOpen){if(a.isOpen=true,u.setAttribute("data-open","true"),Fe(),!a.webchatEnabled){De(),(r=t.onOpen)==null||r.call(t);return}if(a.history.length===0&&a.captured&&ee()&&Ie(),a.captured)o.input.focus();else {let d=t.capture.fields[0];(d&&o.captureInputs[d]||o.input).focus();}(i=t.onOpen)==null||i.call(t);}}function q(){var r;a.isOpen&&(a.isOpen=false,u.setAttribute("data-open","false"),o.el.getAttribute("data-view")==="contact"&&(a.contactChannel=null,D(_e()),w()),(r=t.onClose)==null||r.call(t));}function w(){var r;o.headerTitle.textContent=t.title,o.headerSubtitleText.textContent=(r=t.subtitle)!=null?r:"",o.headerSubtitle.hidden=!t.subtitle;}function O(){a.isOpen?q():H();}function j(r){var g,C,_;r.preventDefault(),z();let i=_n(o),d=t.capture.fields,h=t.capture.errorMessages;for(let y of d)if(!i[y])return $(y,h.required);if(d.includes("email")&&!Oe((g=i.email)!=null?g:""))return $("email",h.email);if(d.includes("phone")){let y=J((C=o.phoneCountry)==null?void 0:C.value),v=((_=i.phone)!=null?_:"").replace(/\D/g,"");if(!y||v.length<y.nsn[0]||v.length>y.nsn[1])return $("phone",h.phone);i.phone=`${y.dial}${v}`;}a.pendingLead={...a.pendingLead,...i},a.captured=true,Q(),D("chat"),Re(),o.input.focus(),a.history.length===0&&ee()&&Ie();}function Q(){if(!t.capture.createLeadOnSubmit||a.leadId)return;let r=a.pendingLead;if(!r.first_name&&!r.email&&!r.phone)return;let i=typeof t.metadata=="function"?t.metadata():t.metadata;a.leadCreating=e.createLead({first_name:r.first_name||"Web visitor",last_name:r.last_name,email:r.email,phone:r.phone,source:"web-chat",metadata:{...i,web_chat_session_id:s}}).then(d=>{var h,g;(h=d==null?void 0:d.lead)!=null&&h.id&&!a.leadId&&(a.leadId=d.lead.id,(g=t.onLeadCaptured)==null||g.call(t,d.lead.id)),d&&!d.existed&&(a.episodeChoiceOffered=true);}).catch(d=>{var h;(h=t.onError)==null||h.call(t,d);}).finally(()=>{a.leadCreating=null;});}function $(r,i){F(i);let d=o.captureInputs[r],h=(d==null?void 0:d.closest(".nexor-chat__phone"))||d;h==null||h.classList.add("nexor-chat__input--error"),d==null||d.focus();}function F(r){o.captureError&&(o.captureError.textContent=r,o.captureError.hidden=false);}function z(){var r;o.captureError&&(o.captureError.textContent="",o.captureError.hidden=true),(r=o.captureForm)==null||r.querySelectorAll(".nexor-chat__input--error").forEach(i=>i.classList.remove("nexor-chat__input--error"));}function ie(r,i,d){let h=()=>{let g=J(r.value),C=g?W(g):15;i.maxLength=C;let _=i.value.replace(/\D/g,"").slice(0,C);i.value!==_&&(i.value=_);};i.addEventListener("input",h),r.addEventListener("change",()=>{h(),d==null||d();});}function ge(r){var g,C,_,y,v,B,K;let i=o.contact,d=t.requestContact;if(!i||!d)return;a.contactChannel=r,o.headerTitle.textContent=(g=d.title[r])!=null?g:t.title,o.headerSubtitleText.textContent=(C=d.subtitle[r])!=null?C:"",o.headerSubtitle.hidden=!d.subtitle[r],i.submitBtn.textContent=(_=d.submitLabel[r])!=null?_:"",i.successText.textContent=(y=d.successText[r])!=null?y:"",i.view.setAttribute("data-state","form"),i.submitBtn.disabled=false,G(),xe(),Le(),a.isOpen=true,u.setAttribute("data-open","true"),Fe(),D("contact");let h=[i.inputs.first_name,i.inputs.email,i.inputs.phone].find(P=>P&&!P.value);(B=(v=h!=null?h:i.inputs.first_name)!=null?v:null)==null||B.focus(),(K=t.onOpen)==null||K.call(t);}function xe(){var h,g,C;let r=o.contact;if(!r)return;let i=a.pendingLead;r.inputs.first_name&&(r.inputs.first_name.value=(h=i.first_name)!=null?h:""),r.inputs.last_name&&(r.inputs.last_name.value=(g=i.last_name)!=null?g:""),r.inputs.email&&(r.inputs.email.value=(C=i.email)!=null?C:"");let d=fe(t.capture.phoneCountryCode);if(r.phoneCountry&&(r.phoneCountry.value=d.iso),r.inputs.phone){let _="";if(i.phone){let y=String(i.phone).replace(/\D/g,""),v=d.dial.replace(/\D/g,"");_=(y.startsWith(v)?y.slice(v.length):y).slice(0,W(d));}r.inputs.phone.maxLength=W(d),r.inputs.phone.value=_;}}function be(r){var P,Ve,Ge,Ye,Ze,Xe,Je,Qe,et;r.preventDefault();let i=o.contact,d=a.contactChannel;if(!i||!d)return;G();let h=t.capture.errorMessages,g=(Ve=(P=i.inputs.first_name)==null?void 0:P.value.trim())!=null?Ve:"",C=(Ye=(Ge=i.inputs.last_name)==null?void 0:Ge.value.trim())!=null?Ye:"",_=(Xe=(Ze=i.inputs.email)==null?void 0:Ze.value.trim())!=null?Xe:"",y=((Qe=(Je=i.inputs.phone)==null?void 0:Je.value)!=null?Qe:"").replace(/\D/g,"");if(!g)return V("first_name",h.required);if(d==="email"&&!_)return V("email",h.required);if(_&&!Oe(_))return V("email",h.email);let B=d==="call"||d==="whatsapp",K;if(B||y){let Me=J((et=i.phoneCountry)==null?void 0:et.value);if(!Me||y.length<Me.nsn[0]||y.length>Me.nsn[1])return V("phone",h.phone);K=`${Me.dial}${y}`;}Ce(d,{first:g,last:C,email:_,phone:K});}async function Ce(r,i){var y,v,B,K;let d=o.contact,h=t.requestContact;if(!d||!h)return;d.submitBtn.disabled=true;let g=typeof t.metadata=="function"?t.metadata():t.metadata,C=g!=null?g:void 0,_=C&&C.page_url||(typeof window!="undefined"?window.location.href:void 0);try{let P=await e.requestContact({workflow_id:t.workflowId,first_name:i.first,last_name:i.last||void 0,email:i.email||void 0,phone:i.phone,force_first_channel:r,source:"web-chat",metadata:{...C!=null?C:{},contact_request:!0,requested_channel:r,requested_at:new Date().toISOString(),context_note:`Website visitor asked to be contacted via ${r}${_?` from ${_}`:""}.`}},{timeoutMs:t.requestTimeoutMs,maxRetries:0});(y=P==null?void 0:P.lead)!=null&&y.id&&!a.leadId&&(a.leadId=P.lead.id,(v=t.onLeadCaptured)==null||v.call(t,P.lead.id)),d.successText.textContent=(B=h.successText[r])!=null?B:"",o.headerSubtitle.hidden=!0,d.view.setAttribute("data-state","sent");}catch(P){d.submitBtn.disabled=false,le(h.errorText),(K=t.onError)==null||K.call(t,P);}}function V(r,i){let d=o.contact;if(!d)return;le(i);let h=d.inputs[r],g=(h==null?void 0:h.closest(".nexor-chat__phone"))||h;g==null||g.classList.add("nexor-chat__input--error"),h==null||h.focus();}function le(r){let i=o.contact;i&&(i.error.textContent=r,i.error.hidden=false);}function G(){let r=o.contact;r&&(r.error.textContent="",r.error.hidden=true,r.form.querySelectorAll(".nexor-chat__input--error").forEach(i=>i.classList.remove("nexor-chat__input--error")));}function D(r){o.el.setAttribute("data-view",r);}function _e(){return a.captured?"chat":"capture"}function ye(){let r=a.pendingLead,i=(r.first_name||r.email||r.phone||"").trim();return i?t.resumeWithNameText.replace("{name}",i):t.resumeText}function ce(r=false){if(A)return;let i=_t(ye(),t.startOverText);i.resetBtn.addEventListener("click",de),r&&o.body.firstChild?o.body.insertBefore(i.el,o.body.firstChild):o.body.appendChild(i.el),A=i.el;}function de(){var r;Le(),p.timer&&(window.clearTimeout(p.timer),p.timer=0),p.splitTimer&&(window.clearTimeout(p.splitTimer),p.splitTimer=0),p.pending=[],Y();try{window.localStorage.removeItem(l);}catch(i){}if(a.history=[],a.shownOpening=null,A=null,o.body.replaceChildren(),o.captureView){a.pendingLead={...(r=t.lead)!=null?r:{}},a.captured=false,a.leadId=void 0,a.episodeChoiceOffered=false,a.resetEpisode=true,we(),D("capture"),Re();let i=t.capture.fields[0];(i&&o.captureInputs[i]||o.input).focus();return}a.resetEpisode=true,D("chat"),Re(),a.captured&&ee()&&Ie(),o.input.focus();}function we(){var d,h,g;let r=a.pendingLead;o.captureInputs.first_name&&(o.captureInputs.first_name.value=(d=r.first_name)!=null?d:""),o.captureInputs.last_name&&(o.captureInputs.last_name.value=(h=r.last_name)!=null?h:""),o.captureInputs.email&&(o.captureInputs.email.value=(g=r.email)!=null?g:"");let i=fe(t.capture.phoneCountryCode);if(o.phoneCountry&&(o.phoneCountry.value=i.iso),o.captureInputs.phone){let C="";if(r.phone){let _=String(r.phone).replace(/\D/g,""),y=i.dial.replace(/\D/g,"");C=(_.startsWith(y)?_.slice(y.length):_).slice(0,W(i));}o.captureInputs.phone.maxLength=W(i),o.captureInputs.phone.value=C;}z();}function ue(r){r.preventDefault();let i=o.input.value.trim();i&&(o.input.value="",pe(),he(i));}function pe(){let r=o.input;r.style.height="auto",r.style.height=`${r.scrollHeight+2}px`;}function he(r){if(!a.captured){let i=t.capture.fields[0];(i&&o.captureInputs[i]||o.input).focus();return}Le(),Et(r),p.pending.push(r),Be();}function ve(){var i;let r=t.openingMessage||a.serverInitialMessage;return r?ct(r,a.pendingLead):(i=t.greeting)!=null?i:""}function ee(){return a.webchatEnabled?t.openingMessage||!a.configResolved?true:!!a.serverInitialMessage||!!t.greeting:false}function Ie(){f.pending||(f.pending=true,Se(),f.timer=window.setTimeout(async()=>{if(t.openingMessage||await x,!f.pending)return;f.pending=false,f.timer=0,Y();let r=ve();r&&(a.shownOpening=r,Te(r));},I));}function Le(){f.pending&&(f.timer&&window.clearTimeout(f.timer),f.timer=0,f.pending=false,Y());}async function vt(){var r;try{let i=await e.getChatConfig(t.workflowId,{timeoutMs:1e4,maxRetries:1});Ne(i.enabled!==!1,(r=i.initial_message)!=null?r:null);}catch(i){Ne(true,null);}}function Ne(r,i){a.configResolved=true,a.serverInitialMessage=i,a.webchatEnabled=r,r||(Lt(),Le(),a.isOpen&&De());}function De(){D("chat"),a.disabledShown||(Ae(t.disabledText),a.disabledShown=true),o.input.disabled=true,o.send.disabled=true,o.input.placeholder=t.disabledText;}function Lt(){for(let r of c.channelButtons){if(r.key!=="chat")continue;let i=r.el.closest(".nexor-chat__channel-item");i instanceof HTMLElement&&(i.style.display="none");}}function Se(){if(p.typing){o.body.appendChild(p.typing),He();return}p.typing=$e(yt());}function Y(){var r;(r=p.typing)==null||r.remove(),p.typing=null;}function Be(){Se(),p.timer&&window.clearTimeout(p.timer),p.timer=window.setTimeout(()=>{Tt();},t.debounceMs);}async function Tt(){var h,g,C,_,y;if(p.inFlight||p.pending.length===0)return;let i=p.pending.splice(0,p.pending.length).join(`
891
+ `);if(p.inFlight=true,a.leadCreating)try{await a.leadCreating;}catch(v){}let d=a.resetEpisode;try{let v=await e.chat({workflow_id:t.workflowId,session_id:s,message:i,system_prompt:t.systemPrompt,client_prompt:t.clientPrompt,opening_shown:(h=a.shownOpening)!=null?h:void 0,reset_episode:d||void 0,lead:Object.keys(a.pendingLead).length?a.pendingLead:void 0,metadata:typeof t.metadata=="function"?t.metadata():t.metadata},{timeoutMs:t.requestTimeoutMs,maxRetries:0});d&&(a.resetEpisode=!1),v.lead_id&&!a.leadId&&(a.leadId=v.lead_id,(g=t.onLeadCaptured)==null||g.call(t,a.leadId)),v.matched_existing&&a.freshLocalSession&&!a.episodeChoiceOffered&&!d&&(a.episodeChoiceOffered=!0,ce(!0));let B=((C=v.reply)!=null?C:"").trim();Y(),B?Rt(B):(Ae(t.errorText),(_=t.onError)==null||_.call(t,new Error("Nexor SDK: empty reply from server")));}catch(v){Y(),/web chat is not enabled/i.test((v==null?void 0:v.message)||"")?Ne(false,a.serverInitialMessage):Ae(t.errorText),(y=t.onError)==null||y.call(t,v);}finally{p.splitTimer||Y(),p.inFlight=false,o.input.focus(),p.pending.length&&Be();}}function Et(r){var d;let i=Date.now();Ee("user",r,i),a.history.push({role:"user",text:r,ts:i}),Ue(),(d=t.onMessage)==null||d.call(t,{role:"user",text:r});}function Te(r,i=true){var h;let d=i?Date.now():void 0;Ee("bot",r,d),a.history.push({role:"bot",text:r,ts:d}),Ue(),a.isOpen||St(),(h=t.onMessage)==null||h.call(t,{role:"bot",text:r});}function Rt(r){let i=t.splitReplies?Mt(r):[r];if(i.length<=1){Te(r);return}let[d,...h]=i;Te(d!=null?d:r,false);let g=0,C=()=>{let _=h[g];if(_===void 0)return;let y=g===h.length-1;g++,Se();let v=t.splitDelayMs>0?t.splitDelayMs:kt(_);p.splitTimer=window.setTimeout(()=>{p.splitTimer=0,Y(),Te(_,y),C();},v);};C();}function Mt(r){let i=r.split(/\n[ \t]*\n+/).map(d=>d.trim()).filter(Boolean);return i.length?i:[r]}function kt(r){let g=3e3+Math.min(r.length,180)*11.11111111111111,C=Math.random()*300-150;return Math.round(Math.max(3e3,Math.min(5e3,g+C)))}function Ue(){try{window.localStorage.setItem(l,JSON.stringify({ts:Date.now(),history:a.history,lead:a.pendingLead})),it();}catch(r){}}function It(){let r={history:[],lead:void 0};try{let i=window.localStorage.getItem(l);if(!i)return r;let d=JSON.parse(i);return !d||!Array.isArray(d.history)?r:Date.now()-(d.ts||0)>2592e6?(window.localStorage.removeItem(l),r):{history:d.history,lead:d.lead&&typeof d.lead=="object"?d.lead:void 0}}catch(i){return r}}function Ae(r){Ee("system",r);}function Ee(r,i,d){return $e(Ct(r,i,d,t.locale))}let Nt=window.setInterval(()=>{o.body.querySelectorAll(".nexor-chat__msg-time[data-ts]").forEach(r=>{let i=Number(r.dataset.ts);i&&(r.textContent=qe(i,t.locale));});},6e4);function $e(r){return o.body.appendChild(r),p.typing&&p.typing!==r&&o.body.appendChild(p.typing),He(),r}function He(){o.body.scrollTop=o.body.scrollHeight;}function St(){a.unread++,c.badge.textContent=String(a.unread),c.badge.style.display="flex";}function Fe(){a.unread=0,c.badge.style.display="none";}function Re(){let r=!a.captured;o.input.disabled=r,o.send.disabled=r,o.input.placeholder=r?"Complete the form above to start\u2026":t.inputPlaceholder;}return {open:H,close:q,toggle:O,send:r=>(he(r),Promise.resolve()),destroy:()=>{p.timer&&window.clearTimeout(p.timer),p.splitTimer&&window.clearTimeout(p.splitTimer),f.timer&&window.clearTimeout(f.timer),window.clearInterval(Nt),L&&document.removeEventListener("pointerdown",L),u.remove();},getSessionId:()=>s}}function bn(){if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Nexor SDK: initChat() requires a browser environment.")}function Cn(e){let n=document.createElement("div");return n.className="nexor-chat",n.setAttribute("data-position",e.position),n.setAttribute("data-open","false"),n}function _n(e){let n={},t=e.captureInputs;return t.first_name&&(n.first_name=t.first_name.value.trim()),t.last_name&&(n.last_name=t.last_name.value.trim()),t.email&&(n.email=t.email.value.trim()),t.phone&&(n.phone=t.phone.value.replace(/\D/g,"")),n}function yn(e){return new X(e)}var se=null;function k(){if(!se)throw new Error("Nexor SDK: call `nexor.init({ apiKey })` before using the API.");return se}function wn(e){return se=new X(e),se}function vn(){return se!==null}function Ln(){se=null;}var T={init:wn,isInitialized:vn,reset:Ln,createLead:((...e)=>k().createLead(...e)),createLeadsBulk:((...e)=>k().createLeadsBulk(...e)),updateLead:((...e)=>k().updateLead(...e)),getLead:((...e)=>k().getLead(...e)),getLeadHistory:((...e)=>k().getLeadHistory(...e)),isLeadPaused:((...e)=>k().isLeadPaused(...e)),stopAutomation:((...e)=>k().stopAutomation(...e)),resumeAutomation:((...e)=>k().resumeAutomation(...e)),syncLeadTags:((...e)=>k().syncLeadTags(...e)),listLeadMeetings:((...e)=>k().listLeadMeetings(...e)),listWorkflows:((...e)=>k().listWorkflows(...e)),listCampaigns:((...e)=>k().listCampaigns(...e)),listTemplates:((...e)=>k().listTemplates(...e)),sendMessage:((...e)=>k().sendMessage(...e)),createMeeting:((...e)=>k().createMeeting(...e)),createMeetingNotes:((...e)=>k().createMeetingNotes(...e)),initChat:e=>wt(k(),e)};var er=T.init,tr=T.isInitialized,nr=T.reset,rr=T.initChat,ar=T.createLead,or=T.createLeadsBulk,sr=T.updateLead,ir=T.getLead,lr=T.getLeadHistory,cr=T.isLeadPaused,dr=T.stopAutomation,ur=T.resumeAutomation,pr=T.syncLeadTags,hr=T.listLeadMeetings,mr=T.listWorkflows,fr=T.listCampaigns,gr=T.listTemplates,xr=T.sendMessage,br=T.createMeeting,Cr=T.createMeetingNotes;exports.NexorAPIError=U;exports.NexorAuthError=ne;exports.NexorClient=X;exports.NexorError=te;exports.NexorNetworkError=Z;exports.NexorValidationError=re;exports.createClient=yn;exports.createLead=ar;exports.createLeadsBulk=or;exports.createMeeting=br;exports.createMeetingNotes=Cr;exports.getLead=ir;exports.getLeadHistory=lr;exports.init=er;exports.initChat=rr;exports.isInitialized=tr;exports.isLeadPaused=cr;exports.listCampaigns=fr;exports.listLeadMeetings=hr;exports.listTemplates=gr;exports.listWorkflows=mr;exports.reset=nr;exports.resumeAutomation=ur;exports.sendMessage=xr;exports.stopAutomation=dr;exports.syncLeadTags=pr;exports.updateLead=sr;return exports;})({});//# sourceMappingURL=nexor.iife.js.map
892
892
  //# sourceMappingURL=nexor.iife.js.map