@getnexorai/sdk 0.1.5 → 0.1.7
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/chat.cjs +112 -19
- package/dist/chat.cjs.map +1 -1
- package/dist/chat.d.cts +2 -2
- package/dist/chat.d.ts +2 -2
- package/dist/chat.js +1 -1
- package/dist/{chunk-EGZR7CCR.js → chunk-DSKP6MXM.js} +114 -21
- package/dist/chunk-DSKP6MXM.js.map +1 -0
- package/dist/{config-C39P5Aax.d.cts → config-DBEY3q4Q.d.cts} +13 -1
- package/dist/{config-C39P5Aax.d.ts → config-DBEY3q4Q.d.ts} +13 -1
- package/dist/index.cjs +112 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nexor.iife.js +71 -20
- package/dist/nexor.iife.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-EGZR7CCR.js.map +0 -1
package/dist/nexor.iife.js
CHANGED
|
@@ -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: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)=>`
|
|
1
|
+
var Nexor=(function(exports){'use strict';var te=class extends Error{constructor(n){super(n),this.name="NexorError";}},$=class extends te{constructor(n){var t;super(n.message),this.name="NexorAPIError",this.status=n.status,this.code=(t=n.code)!=null?t:Pt(n.status),this.body=n.body,this.requestId=n.requestId;}},ne=class extends ${constructor(n){super({status:401,code:"unauthorized",...n}),this.name="NexorAuthError";}},re=class extends ${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 Pt(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 Ot="https://api.getnexor.ai",Dt=3e4,qt=2,Bt="0.1.0";function it(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/${Bt}${e.userAgentSuffix?` ${e.userAgentSuffix}`:""}`;return {apiKey:e.apiKey.trim(),baseUrl:Kt((l=e.baseUrl)!=null?l:Ot),timeoutMs:(u=e.timeoutMs)!=null?u:Dt,maxRetries:(c=e.maxRetries)!=null?c:qt,fetchImpl:n,userAgent:t}}async function E(e,n){var m,a,b,p,f,I,L,A,M;let t=Wt(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=(b=(a=n.options)==null?void 0:a.timeoutMs)!=null?b: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,_=(I=n.options)==null?void 0:I.signal,H=()=>S.abort();_&&(_.aborted?S.abort():_.addEventListener("abort",H));let B=setTimeout(()=>S.abort(),u);try{let v=await e.fetchImpl(t,{method:n.method,headers:s,body:l,signal:S.signal});clearTimeout(B),_==null||_.removeEventListener("abort",H);let D=(L=v.headers.get("x-request-id"))!=null?L:void 0;if(v.ok){if(v.status===204)return;let z=await v.text();if(!z)return;try{return JSON.parse(z)}catch(K){throw new $({status:v.status,message:"Failed to parse JSON response",body:z,requestId:D})}}let j=await Ft(v),Q=(A=$t(j))!=null?A:`HTTP ${v.status}`,F=Ut(v.status,Q,j,D);if(zt(v.status)&&N<c){await ot(at(N,v)),o=F;continue}throw F}catch(v){if(clearTimeout(B),_==null||_.removeEventListener("abort",H),v instanceof $)throw v;let D=v instanceof Error&&(v.name==="AbortError"||/abort/i.test(v.message));if(D&&(_!=null&&_.aborted))throw v;if(o=v,N<c){await ot(at(N));continue}throw new Z(D?`Request timed out after ${u}ms`:`Network error: ${(M=v==null?void 0:v.message)!=null?M:String(v)}`,v)}}throw o!=null?o:new Z("Request failed")}function Ut(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 $({status:e,message:n,body:t,requestId:s})}function $t(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 Ft(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 zt(e){return e===429||e>=500&&e<=599}function at(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 ot(e){return new Promise(n=>setTimeout(n,e))}function Kt(e){return e.endsWith("/")?e.slice(0,-1):e}function Wt(e,n,t){let s=n.startsWith("/")?n:`/${n}`,l=jt(t);return `${e}${s}${l?`?${l}`:""}`}function jt(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=it(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 st(e){var n,t,s,l,u,c,o,m,a,b,p,f,I,L,A,M,N,S,_,H,B,v,D,j,Q,F,z,K,se,ge,xe,be,Ce,V,le,G,U,_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:(b=e.inputPlaceholder)!=null?b:"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:Yt(e.channels),requestContact:en((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:(_=e.requestTimeoutMs)!=null?_:6e4,container:e.container,systemPrompt:e.systemPrompt,clientPrompt:e.clientPrompt,lead:e.lead,capture:{fields:(B=(H=e.capture)==null?void 0:H.fields)!=null?B:["first_name","email"],mode:(D=(v=e.capture)==null?void 0:v.mode)!=null?D:"before",createLeadOnSubmit:(Q=(j=e.capture)==null?void 0:j.createLeadOnSubmit)!=null?Q:false,label:(z=(F=e.capture)==null?void 0:F.label)!=null?z:"Tell us a bit about you to get started:",submitLabel:(se=(K=e.capture)==null?void 0:K.submitLabel)!=null?se:"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=(U=(G=e.capture)==null?void 0:G.errorMessages)==null?void 0:U.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 Vt=["whatsapp","call","email","instagram","chat"],Gt={whatsapp:"WhatsApp",call:"Call",email:"Email",instagram:"Instagram",chat:"Chat"};function Yt(e){var o,m;if(!e)return [];let n=(o=e.order)!=null?o:Vt,t=a=>{var b,p;return (p=(b=e.labels)==null?void 0:b[a])!=null?p:Gt[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 b=e.whatsapp.replace(/[^\d]/g,"");if(!b)break;let p=e.whatsappText?`?text=${encodeURIComponent(e.whatsappText)}`:"";c.push({key:a,href:`https://wa.me/${b}${p}`,external:true,label:t(a)});break}case "call":{if(s.has("call")){c.push(l(a));break}if(!e.call)break;let b=e.call.replace(/[^\d+]/g,"");if(!b)break;c.push({key:a,href:`tel:${b}`,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 b=/^https?:\/\//i.test(e.instagram)?e.instagram:`https://instagram.com/${e.instagram.replace(/^@/,"")}`;c.push({key:a,href:b,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 Zt={call:"Request a call",email:"Request an email",whatsapp:"Request a message"},Xt={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."},Jt={call:"Request call",email:"Request email",whatsapp:"Request message"},Qt={call:"Thanks! We'll call you shortly.",email:"Thanks! We'll email you shortly.",whatsapp:"Thanks! We'll message you shortly."};function en(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,Zt),subtitle:t(e.subtitle,Xt),submitLabel:t(e.submitLabel,Jt),successText:t(e.successText,Qt),doneLabel:(s=e.doneLabel)!=null?s:"Done",errorText:(l=e.errorText)!=null?l:"Something went wrong. Please try again."}}function Ie(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 lt="nexor.chat.session_id";function ct(){let e=Date.now();try{let t=ut();if(t&&e-t.ts<2592e6)return De(t.id,e),t.id}catch(t){}let n=`sess_${tn(16)}`;try{De(n,e);}catch(t){}return n}function dt(){try{let e=ut();e&&De(e.id,Date.now());}catch(e){}}function ut(){let e=window.localStorage.getItem(lt);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 De(e,n){window.localStorage.setItem(lt,JSON.stringify({id:e,ts:n}));}function tn(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 nn=/^[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 qe(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:nn.test(n)}var rn={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 an(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 pt(e,n){return typeof e!="string"||!e?"":e.replace(/\{\{\s*([a-zA-Z_]+)\s*\}\}/g,(s,l)=>{let u=rn[l.toLowerCase()];return u?an(n,u):s}).replace(/[ \t]+([,.!?;:])/g,"$1").replace(/[ \t]{2,}/g," ").replace(/^[ \t]*[,;:][ \t]*/gm,"").replace(/[ \t]+$/gm,"").trim()}var ht={iso:"CL",name:"Chile",dial:"+56",flag:"\u{1F1E8}\u{1F1F1}",nsn:[9,9]},me=[ht,{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 on(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 on(n)||J(n)||ht}var mt=(e,n)=>`
|
|
2
2
|
.nexor-chat,
|
|
3
3
|
.nexor-chat * {
|
|
4
4
|
box-sizing: border-box;
|
|
@@ -373,6 +373,40 @@ var Nexor=(function(exports){'use strict';var te=class extends Error{constructor
|
|
|
373
373
|
}
|
|
374
374
|
.nexor-chat__msg--bot .nexor-chat__msg-time { text-align: left; }
|
|
375
375
|
|
|
376
|
+
/* File Library attachment: the image itself is the bubble (no padding/bg). */
|
|
377
|
+
.nexor-chat__msg--media {
|
|
378
|
+
padding: 0;
|
|
379
|
+
background: transparent;
|
|
380
|
+
border: none;
|
|
381
|
+
box-shadow: none;
|
|
382
|
+
overflow: hidden;
|
|
383
|
+
}
|
|
384
|
+
.nexor-chat__media-img {
|
|
385
|
+
display: block;
|
|
386
|
+
max-width: 100%;
|
|
387
|
+
max-height: 260px;
|
|
388
|
+
width: auto;
|
|
389
|
+
height: auto;
|
|
390
|
+
border-radius: 14px;
|
|
391
|
+
border-bottom-left-radius: 4px;
|
|
392
|
+
object-fit: cover;
|
|
393
|
+
}
|
|
394
|
+
.nexor-chat__media-doc {
|
|
395
|
+
display: inline-flex;
|
|
396
|
+
align-items: center;
|
|
397
|
+
gap: 6px;
|
|
398
|
+
padding: 8px 12px;
|
|
399
|
+
border-radius: 14px;
|
|
400
|
+
border-bottom-left-radius: 4px;
|
|
401
|
+
background: #fff;
|
|
402
|
+
border: 1px solid rgba(0,0,0,0.06);
|
|
403
|
+
color: ${e};
|
|
404
|
+
text-decoration: none;
|
|
405
|
+
font-size: 13px;
|
|
406
|
+
font-weight: 500;
|
|
407
|
+
}
|
|
408
|
+
.nexor-chat__media-doc::before { content: "\\1F4CE"; }
|
|
409
|
+
|
|
376
410
|
@keyframes nexor-msg-in {
|
|
377
411
|
from { transform: translateY(8px) scale(0.96); opacity: 0; }
|
|
378
412
|
to { transform: translateY(0) scale(1); opacity: 1; }
|
|
@@ -512,7 +546,8 @@ var Nexor=(function(exports){'use strict';var te=class extends Error{constructor
|
|
|
512
546
|
transition: border-color 140ms ease, box-shadow 140ms ease;
|
|
513
547
|
}
|
|
514
548
|
/* Composer textarea: auto-grows (height managed in JS) up to ~4 lines, then
|
|
515
|
-
scrolls. resize:none disables the manual drag handle.
|
|
549
|
+
scrolls. resize:none disables the manual drag handle. Filled style: neutral
|
|
550
|
+
pill at rest that "lights up" white on focus \u2014 calmer than a glowing ring. */
|
|
516
551
|
textarea.nexor-chat__input {
|
|
517
552
|
display: block;
|
|
518
553
|
resize: none;
|
|
@@ -521,11 +556,22 @@ textarea.nexor-chat__input {
|
|
|
521
556
|
max-height: 98px; /* 4 lines (20\xD74) + 16 padding + 2 border */
|
|
522
557
|
white-space: pre-wrap;
|
|
523
558
|
word-break: break-word;
|
|
559
|
+
background: #f3f4f6;
|
|
560
|
+
border-color: transparent;
|
|
561
|
+
border-radius: 19px;
|
|
562
|
+
padding: 8px 14px;
|
|
563
|
+
transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
|
|
524
564
|
}
|
|
565
|
+
textarea.nexor-chat__input::placeholder { color: #9ca3af; }
|
|
525
566
|
.nexor-chat__input:focus,
|
|
526
567
|
.nexor-chat__capture input:focus {
|
|
527
568
|
border-color: ${e};
|
|
528
|
-
box-shadow: 0 0 0
|
|
569
|
+
box-shadow: 0 0 0 2px ${e}1f;
|
|
570
|
+
}
|
|
571
|
+
textarea.nexor-chat__input:focus {
|
|
572
|
+
background: #fff;
|
|
573
|
+
border-color: ${e}99;
|
|
574
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.06);
|
|
529
575
|
}
|
|
530
576
|
.nexor-chat__input--error,
|
|
531
577
|
.nexor-chat__capture input.nexor-chat__input--error {
|
|
@@ -666,21 +712,26 @@ textarea.nexor-chat__input {
|
|
|
666
712
|
background: ${e};
|
|
667
713
|
color: ${n};
|
|
668
714
|
border: none;
|
|
669
|
-
border-radius:
|
|
670
|
-
padding: 0
|
|
715
|
+
border-radius: 9999px; /* circle, matches the pill composer */
|
|
716
|
+
padding: 0;
|
|
671
717
|
font: inherit;
|
|
672
718
|
font-weight: 600;
|
|
673
719
|
cursor: pointer;
|
|
674
|
-
|
|
720
|
+
width: 38px;
|
|
675
721
|
height: 38px; /* matches the one-line textarea height */
|
|
676
722
|
flex: none;
|
|
677
723
|
display: flex;
|
|
678
724
|
align-items: center;
|
|
679
725
|
justify-content: center;
|
|
680
|
-
|
|
726
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.12);
|
|
727
|
+
transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
|
|
728
|
+
}
|
|
729
|
+
.nexor-chat__send:hover {
|
|
730
|
+
filter: brightness(1.08);
|
|
731
|
+
box-shadow: 0 2px 6px rgba(0,0,0,0.18);
|
|
732
|
+
transform: translateY(-1px);
|
|
681
733
|
}
|
|
682
|
-
.nexor-chat__send:
|
|
683
|
-
.nexor-chat__send:active { transform: scale(0.95); }
|
|
734
|
+
.nexor-chat__send:active { transform: scale(0.93); }
|
|
684
735
|
.nexor-chat__send[disabled] {
|
|
685
736
|
opacity: 0.6;
|
|
686
737
|
cursor: not-allowed;
|
|
@@ -691,7 +742,7 @@ textarea.nexor-chat__input {
|
|
|
691
742
|
height: 18px;
|
|
692
743
|
transition: transform 200ms ease;
|
|
693
744
|
}
|
|
694
|
-
.nexor-chat__send:not([disabled]):hover svg { transform:
|
|
745
|
+
.nexor-chat__send:not([disabled]):hover svg { transform: translateY(-1.5px); }
|
|
695
746
|
|
|
696
747
|
/* Small spinner inside the send button while a turn is in flight */
|
|
697
748
|
.nexor-chat__send--loading svg { display: none; }
|
|
@@ -839,11 +890,11 @@ textarea.nexor-chat__input {
|
|
|
839
890
|
}
|
|
840
891
|
.nexor-chat__status-dot { animation: none; }
|
|
841
892
|
}
|
|
842
|
-
`;var
|
|
893
|
+
`;var ft="data-nexor-chat-styles";function gt(e,n){let t=document.querySelector(`style[${ft}]`);t||(t=document.createElement("style"),t.setAttribute(ft,"1"),document.head.appendChild(t)),t.textContent=mt(e,n);}var xt=`
|
|
843
894
|
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
844
895
|
<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
896
|
stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
|
|
846
|
-
</svg>`,
|
|
897
|
+
</svg>`,sn={whatsapp:`
|
|
847
898
|
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
848
899
|
<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
900
|
</svg>`,call:`
|
|
@@ -858,7 +909,7 @@ textarea.nexor-chat__input {
|
|
|
858
909
|
<rect x="3.5" y="3.5" width="17" height="17" rx="5" stroke="currentColor" stroke-width="1.8"/>
|
|
859
910
|
<circle cx="12" cy="12" r="4" stroke="currentColor" stroke-width="1.8"/>
|
|
860
911
|
<circle cx="17.2" cy="6.8" r="1.2" fill="currentColor"/>
|
|
861
|
-
</svg>`,chat:
|
|
912
|
+
</svg>`,chat:xt};function bt(e){let n=document.createElement("div");n.className="nexor-chat__launcher-wrap";let t=e.channels.length>0,{fan:s,channelButtons:l}=t?ln(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=xt;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 ln(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=sn[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 Ct(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}=cn(e),m=dn(),{form:a,input:b,send:p}=gn(e),f=e.showBranding?bn():null,I={},L=null,A=null,M=null,N=null;if(Ie(e)){let _=un(e,I);L=_.view,A=_.form,M=_.error,N=_.phoneCountry;}let S=e.requestContact?fn(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:b,send:p,captureView:L,captureForm:A,captureError:M,phoneCountry:N,captureInputs:I,contact:S}}function cn(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
913
|
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
863
914
|
<path d="M4 5v5h5M20 19v-5h-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
864
915
|
<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 +918,15 @@ textarea.nexor-chat__input {
|
|
|
867
918
|
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
868
919
|
<path d="M6 6l12 12M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
869
920
|
</svg>
|
|
870
|
-
`,n.appendChild(m),{header:n,closeBtn:m,restartBtn:o,titleEl:s,subtitleEl:l,subtitleTextEl:c}}function
|
|
921
|
+
`,n.appendChild(m),{header:n,closeBtn:m,restartBtn:o,titleEl:s,subtitleEl:l,subtitleTextEl:c}}function dn(){let e=document.createElement("div");return e.className="nexor-chat__body",e}function un(e,n){let t=document.createElement("div");t.className="nexor-chat__capture-view";let{form:s,error:l,phoneCountry:u}=pn(e,n);return t.appendChild(s),{view:t,form:s,error:l,phoneCountry:u}}var _t={first_name:"First name",last_name:"Last name",email:"Email",phone:"Phone"};function pn(e,n){var a,b,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:_t[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",(b=e.lead)==null?void 0:b.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=yt(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 hn(e){if(!e.length)return me;let n=e.map(t=>J(t)).filter(t=>!!t);return n.length?n:me}function yt(e,n){var o;let t=document.createElement("div");t.className="nexor-chat__phone";let s=hn(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,""),b=m.startsWith(a)?m.slice(a.length):m;c.value=b.slice(0,c.maxLength);}return t.appendChild(u),t.appendChild(c),{wrap:t,select:u,input:c}}function fn(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=_=>{var H;return (H=e.capture.placeholders[_])!=null?H:_t[_]},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=yt(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 b=document.createElement("button");b.type="submit",b.className="nexor-chat__capture-submit",s.appendChild(b),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
922
|
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
872
923
|
<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:s,inputs:l,error:a,phoneCountry:m,submitBtn:
|
|
924
|
+
</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:b,success:p,successText:I,successBtn:L}}function gn(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
925
|
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
875
|
-
<path d="
|
|
876
|
-
stroke="currentColor" stroke-width="
|
|
926
|
+
<path d="M12 19V5.8M5.8 12 12 5.8 18.2 12"
|
|
927
|
+
stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
877
928
|
</svg>
|
|
878
|
-
`,n.appendChild(t),n.appendChild(s),{form:n,input:t,send:s}}var
|
|
929
|
+
`,n.appendChild(t),n.appendChild(s),{form:n,input:t,send:s}}var xn=`
|
|
879
930
|
<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
931
|
<defs>
|
|
881
932
|
<linearGradient id="nexorChatBrandGrad" x1="1195.44" y1="21.3423" x2="1195.44" y2="504.454" gradientUnits="userSpaceOnUse">
|
|
@@ -887,6 +938,6 @@ textarea.nexor-chat__input {
|
|
|
887
938
|
<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
939
|
<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
940
|
<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 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(
|
|
941
|
+
</svg>`;function bn(){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>${xn}</span>`,e}function wt(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=Ue(t,s),l.appendChild(c);}return l}function Be(e){let n=document.createElement("div");if(n.className="nexor-chat__msg nexor-chat__msg--bot nexor-chat__msg--media",e.type==="image"){let t=document.createElement("img");t.className="nexor-chat__media-img",t.src=e.url,t.alt=e.filename||"",t.loading="lazy",t.addEventListener("error",()=>n.remove()),n.appendChild(t);}else {let t=document.createElement("a");t.className="nexor-chat__media-doc",t.href=e.url,t.target="_blank",t.rel="noopener noreferrer",t.textContent=e.filename||"Descargar archivo",n.appendChild(t);}return n}function Ue(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 vt(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 Lt(){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 Tt(e,n){var je,Ve,Ge,Ye;if(_n(),!n||!n.workflowId)throw new Error("Nexor SDK: initChat() requires `workflowId`.");let t=st(n);gt(t.accentColor,t.accentTextColor);let s=ct(),l=`nexor.chat.history.${s}`,u=yn(t),c=bt(t),o=Ct(t);u.appendChild(c.wrap),u.appendChild(o.el),((je=t.container)!=null?je:document.body).appendChild(u);let m=c.channelButtons.length>0,a={isOpen:false,expanded:false,unread:0,leadId:void 0,captured:!Ie(t),pendingLead:{...(Ve=t.lead)!=null?Ve:{}},history:[],webchatEnabled:true,serverInitialMessage:null,configResolved:false,disabledShown:false,shownOpening:null,resetEpisode:false,freshLocalSession:false,episodeChoiceOffered:false,contactChannel:null,leadCreating:null},b,p={pending:[],timer:0,inFlight:false,typing:null,splitTimer:0},f={pending:false,timer:0},I=2e3;c.el.addEventListener("click",m?N:D),o.closeBtn.addEventListener("click",B),(Ge=o.restartBtn)==null||Ge.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));}),(Ye=o.captureForm)==null||Ye.addEventListener("submit",j);for(let r of Object.values(o.captureInputs))r==null||r.addEventListener("input",K);if(o.phoneCountry&&o.captureInputs.phone&&se(o.phoneCountry,o.captureInputs.phone,K),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&&se(r.phoneCountry,r.inputs.phone,G),r.successBtn.addEventListener("click",B);}let L=null;if(m){for(let r of c.channelButtons)r.el.addEventListener("click",()=>{r.key==="chat"?(_(),H()):r.action==="contact"?(_(),ge(r.key)):_();});L=r=>{a.expanded&&!c.wrap.contains(r.target)&&_();},document.addEventListener("pointerdown",L);}let A=null,M=At();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,U("chat"),ce();for(let r of M.history)r.media?Re(Be(r.media)):Ee(r.role==="user"?"user":"bot",r.text,r.ts);Oe();}Me(),b=Et(),t.openOnLoad&&H();function N(){a.expanded?_():S();}function S(){a.expanded=true,c.wrap.setAttribute("data-expanded","true"),c.el.setAttribute("aria-expanded","true");}function _(){a.expanded&&(a.expanded=false,c.wrap.setAttribute("data-expanded","false"),c.el.setAttribute("aria-expanded","false"));}function H(){var r,i;if(_(),!a.isOpen){if(a.isOpen=true,u.setAttribute("data-open","true"),We(),!a.webchatEnabled){$e(),(r=t.onOpen)==null||r.call(t);return}if(a.history.length===0&&a.captured&&ee()&&Ne(),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 B(){var r;a.isOpen&&(a.isOpen=false,u.setAttribute("data-open","false"),o.el.getAttribute("data-view")==="contact"&&(a.contactChannel=null,U(_e()),v()),(r=t.onClose)==null||r.call(t));}function v(){var r;o.headerTitle.textContent=t.title,o.headerSubtitleText.textContent=(r=t.subtitle)!=null?r:"",o.headerSubtitle.hidden=!t.subtitle;}function D(){a.isOpen?B():H();}function j(r){var g,C,w;r.preventDefault(),K();let i=wn(o),d=t.capture.fields,h=t.capture.errorMessages;for(let x of d)if(!i[x])return F(x,h.required);if(d.includes("email")&&!qe((g=i.email)!=null?g:""))return F("email",h.email);if(d.includes("phone")){let x=J((C=o.phoneCountry)==null?void 0:C.value),y=((w=i.phone)!=null?w:"").replace(/\D/g,"");if(!x||y.length<x.nsn[0]||y.length>x.nsn[1])return F("phone",h.phone);i.phone=`${x.dial}${y}`;}a.pendingLead={...a.pendingLead,...i},a.captured=true,Q(),U("chat"),Me(),o.input.focus(),a.history.length===0&&ee()&&Ne();}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 F(r,i){z(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 z(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(i=>i.classList.remove("nexor-chat__input--error"));}function se(r,i,d){let h=()=>{let g=J(r.value),C=g?W(g):15;i.maxLength=C;let w=i.value.replace(/\D/g,"").slice(0,C);i.value!==w&&(i.value=w);};i.addEventListener("input",h),r.addEventListener("change",()=>{h(),d==null||d();});}function ge(r){var g,C,w,x,y,O,q;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=(w=d.submitLabel[r])!=null?w:"",i.successText.textContent=(x=d.successText[r])!=null?x:"",i.view.setAttribute("data-state","form"),i.submitBtn.disabled=false,G(),xe(),Le(),a.isOpen=true,u.setAttribute("data-open","true"),We(),U("contact");let h=[i.inputs.first_name,i.inputs.email,i.inputs.phone].find(P=>P&&!P.value);(O=(y=h!=null?h:i.inputs.first_name)!=null?y:null)==null||O.focus(),(q=t.onOpen)==null||q.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 w="";if(i.phone){let x=String(i.phone).replace(/\D/g,""),y=d.dial.replace(/\D/g,"");w=(x.startsWith(y)?x.slice(y.length):x).slice(0,W(d));}r.inputs.phone.maxLength=W(d),r.inputs.phone.value=w;}}function be(r){var P,Ze,Xe,Je,Qe,et,tt,nt,rt;r.preventDefault();let i=o.contact,d=a.contactChannel;if(!i||!d)return;G();let h=t.capture.errorMessages,g=(Ze=(P=i.inputs.first_name)==null?void 0:P.value.trim())!=null?Ze:"",C=(Je=(Xe=i.inputs.last_name)==null?void 0:Xe.value.trim())!=null?Je:"",w=(et=(Qe=i.inputs.email)==null?void 0:Qe.value.trim())!=null?et:"",x=((nt=(tt=i.inputs.phone)==null?void 0:tt.value)!=null?nt:"").replace(/\D/g,"");if(!g)return V("first_name",h.required);if(d==="email"&&!w)return V("email",h.required);if(w&&!qe(w))return V("email",h.email);let O=d==="call"||d==="whatsapp",q;if(O||x){let ke=J((rt=i.phoneCountry)==null?void 0:rt.value);if(!ke||x.length<ke.nsn[0]||x.length>ke.nsn[1])return V("phone",h.phone);q=`${ke.dial}${x}`;}Ce(d,{first:g,last:C,email:w,phone:q});}async function Ce(r,i){var x,y,O,q;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,w=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}${w?` from ${w}`:""}.`}},{timeoutMs:t.requestTimeoutMs,maxRetries:0});(x=P==null?void 0:P.lead)!=null&&x.id&&!a.leadId&&(a.leadId=P.lead.id,(y=t.onLeadCaptured)==null||y.call(t,P.lead.id)),d.successText.textContent=(O=h.successText[r])!=null?O:"",o.headerSubtitle.hidden=!0,d.view.setAttribute("data-state","sent");}catch(P){d.submitBtn.disabled=false,le(h.errorText),(q=t.onError)==null||q.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 U(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=vt(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(),U("capture"),Me();let i=t.capture.fields[0];(i&&o.captureInputs[i]||o.input).focus();return}a.resetEpisode=true,U("chat"),Me(),a.captured&&ee()&&Ne(),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 w=String(r.phone).replace(/\D/g,""),x=i.dial.replace(/\D/g,"");C=(w.startsWith(x)?w.slice(x.length):w).slice(0,W(i));}o.captureInputs.phone.maxLength=W(i),o.captureInputs.phone.value=C;}K();}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(),kt(r),p.pending.push(r),Fe();}function ve(){var i;let r=t.openingMessage||a.serverInitialMessage;return r?pt(r,a.pendingLead):(i=t.greeting)!=null?i:""}function ee(){return a.webchatEnabled?t.openingMessage||!a.configResolved?true:!!a.serverInitialMessage||!!t.greeting:false}function Ne(){f.pending||(f.pending=true,Ae(),f.timer=window.setTimeout(async()=>{if(t.openingMessage||await b,!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 Et(){var r;try{let i=await e.getChatConfig(t.workflowId,{timeoutMs:1e4,maxRetries:1});Se(i.enabled!==!1,(r=i.initial_message)!=null?r:null);}catch(i){Se(true,null);}}function Se(r,i){a.configResolved=true,a.serverInitialMessage=i,a.webchatEnabled=r,r||(Rt(),Le(),a.isOpen&&$e());}function $e(){U("chat"),a.disabledShown||(Pe(t.disabledText),a.disabledShown=true),o.input.disabled=true,o.send.disabled=true,o.input.placeholder=t.disabledText;}function Rt(){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 Ae(){if(p.typing){o.body.appendChild(p.typing),Oe();return}p.typing=Re(Lt());}function Y(){var r;(r=p.typing)==null||r.remove(),p.typing=null;}function Fe(){Ae(),p.timer&&window.clearTimeout(p.timer),p.timer=window.setTimeout(()=>{Mt();},t.debounceMs);}async function Mt(){var h,g,C,w,x;if(p.inFlight||p.pending.length===0)return;let i=p.pending.splice(0,p.pending.length).join(`
|
|
942
|
+
`);if(p.inFlight=true,a.leadCreating)try{await a.leadCreating;}catch(y){}let d=a.resetEpisode;try{let y=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),y.lead_id&&!a.leadId&&(a.leadId=y.lead_id,(g=t.onLeadCaptured)==null||g.call(t,a.leadId)),y.matched_existing&&a.freshLocalSession&&!a.episodeChoiceOffered&&!d&&(a.episodeChoiceOffered=!0,ce(!0));let O=((C=y.reply)!=null?C:"").trim(),q=Array.isArray(y.media)&&y.media.length>0;Y(),O?It(O,q?()=>ze(y.media):void 0):q?ze(y.media):(Pe(t.errorText),(w=t.onError)==null||w.call(t,new Error("Nexor SDK: empty reply from server")));}catch(y){Y(),/web chat is not enabled/i.test((y==null?void 0:y.message)||"")?Se(false,a.serverInitialMessage):Pe(t.errorText),(x=t.onError)==null||x.call(t,y);}finally{p.splitTimer||Y(),p.inFlight=false,o.input.focus(),p.pending.length&&Fe();}}function kt(r){var d;let i=Date.now();Ee("user",r,i),a.history.push({role:"user",text:r,ts:i}),He(),(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}),He(),a.isOpen||Ke(),(h=t.onMessage)==null||h.call(t,{role:"bot",text:r});}function ze(r){if(!(!Array.isArray(r)||r.length===0)){for(let i of r)!i||typeof i.url!="string"||!i.url||(Re(Be(i)),a.history.push({role:"bot",text:"",ts:Date.now(),media:i}));He(),a.isOpen||Ke();}}function It(r,i){let d=t.splitReplies?Nt(r):[r];if(d.length<=1){Te(r),i==null||i();return}let[h,...g]=d;Te(h!=null?h:r,false);let C=0,w=()=>{let x=g[C];if(x===void 0){i==null||i();return}let y=C===g.length-1;C++,Ae();let O=t.splitDelayMs>0?t.splitDelayMs:St(x);p.splitTimer=window.setTimeout(()=>{p.splitTimer=0,Y(),Te(x,y),w();},O);};w();}function Nt(r){let i=r.split(/\n[ \t]*\n+/).map(d=>d.trim()).filter(Boolean);return i.length?i:[r]}function St(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 He(){try{window.localStorage.setItem(l,JSON.stringify({ts:Date.now(),history:a.history,lead:a.pendingLead})),dt();}catch(r){}}function At(){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 Pe(r){Ee("system",r);}function Ee(r,i,d){return Re(wt(r,i,d,t.locale))}let Ht=window.setInterval(()=>{o.body.querySelectorAll(".nexor-chat__msg-time[data-ts]").forEach(r=>{let i=Number(r.dataset.ts);i&&(r.textContent=Ue(i,t.locale));});},6e4);function Re(r){return o.body.appendChild(r),p.typing&&p.typing!==r&&o.body.appendChild(p.typing),Oe(),r}function Oe(){o.body.scrollTop=o.body.scrollHeight;}function Ke(){a.unread++,c.badge.textContent=String(a.unread),c.badge.style.display="flex";}function We(){a.unread=0,c.badge.style.display="none";}function Me(){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:B,toggle:D,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(Ht),L&&document.removeEventListener("pointerdown",L),u.remove();},getSessionId:()=>s}}function _n(){if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Nexor SDK: initChat() requires a browser environment.")}function yn(e){let n=document.createElement("div");return n.className="nexor-chat",n.setAttribute("data-position",e.position),n.setAttribute("data-open","false"),n}function wn(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 vn(e){return new X(e)}var ie=null;function k(){if(!ie)throw new Error("Nexor SDK: call `nexor.init({ apiKey })` before using the API.");return ie}function Ln(e){return ie=new X(e),ie}function Tn(){return ie!==null}function En(){ie=null;}var T={init:Ln,isInitialized:Tn,reset:En,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=>Tt(k(),e)};var nr=T.init,rr=T.isInitialized,ar=T.reset,or=T.initChat,ir=T.createLead,sr=T.createLeadsBulk,lr=T.updateLead,cr=T.getLead,dr=T.getLeadHistory,ur=T.isLeadPaused,pr=T.stopAutomation,hr=T.resumeAutomation,mr=T.syncLeadTags,fr=T.listLeadMeetings,gr=T.listWorkflows,xr=T.listCampaigns,br=T.listTemplates,Cr=T.sendMessage,_r=T.createMeeting,yr=T.createMeetingNotes;exports.NexorAPIError=$;exports.NexorAuthError=ne;exports.NexorClient=X;exports.NexorError=te;exports.NexorNetworkError=Z;exports.NexorValidationError=re;exports.createClient=vn;exports.createLead=ir;exports.createLeadsBulk=sr;exports.createMeeting=_r;exports.createMeetingNotes=yr;exports.getLead=cr;exports.getLeadHistory=dr;exports.init=nr;exports.initChat=or;exports.isInitialized=rr;exports.isLeadPaused=ur;exports.listCampaigns=xr;exports.listLeadMeetings=fr;exports.listTemplates=br;exports.listWorkflows=gr;exports.reset=ar;exports.resumeAutomation=hr;exports.sendMessage=Cr;exports.stopAutomation=pr;exports.syncLeadTags=mr;exports.updateLead=lr;return exports;})({});//# sourceMappingURL=nexor.iife.js.map
|
|
892
943
|
//# sourceMappingURL=nexor.iife.js.map
|