-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path753.vg_bundle.js
1 lines (1 loc) · 5.74 KB
/
753.vg_bundle.js
1
"use strict";(self.webpackChunkcustom_vf_nextjs=self.webpackChunkcustom_vf_nextjs||[]).push([[753],{1753:(n,t,e)=>{e.r(t),e.d(t,{default:()=>E});var o=e(2167),i=e(5861),r=e(885),a=e(4687),u=e.n(a),l=e(1194),c=e(7294),s=e(1721),g=e.n(s),v=e(3068),f=e(7619),d=e(7828),p=e(2280),b=e(9352),h=e(7479),m=e(155),y=e(8676),k=e(381),w=e.n(k),O=e(8650),x=e(3711),N=e(231),D=c.createElement;function j(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(n);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),e.push.apply(e,o)}return e}function _(n){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?j(Object(e),!0).forEach((function(t){(0,o.Z)(n,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):j(Object(e)).forEach((function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(e,t))}))}return n}const E=function(n){var t,e,o,a,s,k,j=(0,y.useRuntime)(),E=j.runtime,I=j.confirmedBucket,P=j.setRuntime,C=j.pushChatNotice,S=((0,h.F)().getColor,c.useState({})),Z=(0,r.Z)(S,2),M=Z[0],T=Z[1],J=c.useState(null),R=(0,r.Z)(J,2),q=R[0],A=R[1],B=c.useState("init"),L=(0,r.Z)(B,2),Y=L[0],F=L[1],G=(null==E||null===(t=E.variables)||void 0===t||null===(t=t.vapiConfig)||void 0===t?void 0:t.PUBLIC_API_KEY)||(null==M||null===(e=M.vapiConfig)||void 0===e?void 0:e.PUBLIC_API_KEY);function K(){return(K=(0,i.Z)(u().mark((function t(){var e,o,i;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch("".concat((0,l.MC)({region:"voiceglow-eu"===I?"eu":"na"}),"/public/users/").concat(null===(e=n.agentData)||void 0===e?void 0:e.ownerID)).then((function(n){return n.json()}));case 2:o=t.sent,T(o.data),i=new(g())(G),A(i);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}return c.useEffect((function(){if(G){var n=new(g())(G);A(n)}}),[G]),c.useEffect((function(){if(q)return q.on("call-start",(function(){F("ongoing"),P((function(n){return _(_({},n),{},{callOngoing:!0})}))})),q.on("speech-end",(function(){})),q.on("speech-start",(function(){})),q.on("call-end",(function(){F("init"),P((function(n){return _(_({},n),{},{callOngoing:!1})}))})),q.on("volume-level",(function(n){})),q.on("message",function(){var n=(0,i.Z)(u().mark((function n(t){var e,o,i;return u().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("conversation-update"!==t.type){n.next=6;break}if(null==(e=t.conversation.flatMap((function(n){try{JSON.parse(n.content);return[]}catch(t){return n.content?{from:"assistant"===n.role?"bot":"human",messages:[{from:"assistant"===n.role?"bot":"human",type:"text",item:{payload:{message:n.content}},ts:w()().unix()}],ts:w()().unix()}:[]}})))||!e.length){n.next=6;break}return i=(0,O.getFirestore)(x.l2,I),n.next=6,(0,O.setDoc)((0,O.doc)(i,"voiceglow/".concat(null==E||null===(o=E.variables)||void 0===o?void 0:o.ID,"/convos/").concat(E.userID,"/convo/JSON_STRING")),{convoTurns_JSON_STRING:JSON.stringify(e)});case 6:case"end":return n.stop()}}),n)})));return function(t){return n.apply(this,arguments)}}()),q.on("error",(function(n){try{var t=n.error.message;P((function(n){return _(_({},n),{},{callOngoing:!1})})),F("init"),C(t,"fail",5e3)}catch(n){C("Error occured please check console","fail",3e3)}})),function(){q.stop(),P((function(n){return _(_({},n),{},{callOngoing:!1})}))}}),[q]),c.useEffect((function(){!function(){K.apply(this,arguments)}()}),[]),G?D(f.E.div,{key:"vg-voice--container",initial:{opacity:1,bottom:"init"===Y?"-30%":"0%",height:"35%"},animate:{opacity:1,bottom:0,height:"init"===Y?"40%":"35%"},exit:{opacity:1,bottom:"init"===Y?"-35%":"0%",height:"35%"},transition:{type:"spring",damping:20,stiffness:100,mass:.5},className:" vg-py-unit-5 vg-h-full vg-flex vg-flex-col vg-gap-0 vg-justify-center vg-items-center vg-absolute vg-left-0 vg-w-full vg-bg-background/50 vg-backdrop-blur vg-z-[100] vg-px-unit-20 vg-mx-auto vg-text-center vg-border-t vg-border-foreground-100 vg-voice--container"},D(d.M,null,"init"===Y?D(f.E.div,{className:" vg-mb-unit-4 ",layout:!0,key:"vg-voice--question_".concat(null===(o=n.agentData)||void 0===o?void 0:o.ID)},D(p.Z,{className:" vg-text-large vg-font-bold vg-leading-6 vg-voice--question"},(null===(a=n.agentData)||void 0===a||null===(a=a.ui)||void 0===a||null===(a=a.voice)||void 0===a?void 0:a.question)||"Would you like to talk in realtime with an AI agent?")):null,D(f.E.button,{key:"vg-voice--yes-please_".concat(null===(s=n.agentData)||void 0===s?void 0:s.ID),layout:!0,animate:{scale:"init"===Y?1:"starting"===Y?1.05:"ongoing"===Y?1.1:1},whileHover:{scale:1.1},className:" vg-border vg-border-foreground-300 ".concat("init"===Y?" vg-bg-background-500 ":"starting"===Y?" vg-bg-background-600 ":"ongoing"===Y?" vg-bg-danger-500 vg-text-danger-50 ":" vg-bg-background-500 "," vg-mb-unit-5 vg-rounded-full vg-w-unit-20 vg-h-unit-20 vg-p-unit-5 vg-font-bold vg-transition-colors vg-voice--yes-button"),onClick:function(){var t;"init"!==Y?q.isMuted()?(q.setMuted(!1),F("ongoing")):(q.setMuted(!0),F("muted")):(F("starting"),q.start(null===(t=n.agentData)||void 0===t||null===(t=t.vapi)||void 0===t?void 0:t.id))}},"starting"===Y?D(v.Z,{className:" vg-w-full vg-h-full "}):null,"init"===Y?D(N.uYL,{className:" vg-w-full vg-h-full vg-flex-shrink-0 "}):null,"ongoing"===Y?D(b.xEs,{className:" vg-w-full vg-h-full vg-flex-shrink-0 "}):null,"muted"===Y?D(b._v3,{className:" vg-w-full vg-h-full vg-flex-shrink-0 "}):null),D(f.E.button,{key:"vg-voice--no-thanks_".concat(null===(k=n.agentData)||void 0===k?void 0:k.ID),layout:!0,className:" vg-border vg-border-foreground-100 vg-w-unit-8 vg-h-unit-8 vg-font-normal vg-opacity-80 vg-rounded-full vg-p-unit-1 vg-voice--no-button",onClick:function(){q&&q.stop(),n.onNoThanks&&n.onNoThanks()}},D(m.bjh,{className:" vg-w-full vg-h-full vg-flex-shrink-0 "})))):null}}}]);