DollyMSAMIAWAPIWrapper",["$InternalEnum","CarePlatformSalesforceMIAWAPIUtils","CometRelay","CometRouteParams","DollyChatMIAWContext.react","DollyChatMessagesContext.react","DollyMSAMIAWAPIWrapperAddHistoryRootMutation.graphql","DollyMSAMIAWAPIWrapperCloseConversationMutation.graphql","DollyMSAMIAWAPIWrapperCreateConversationMutation.graphql","DollyMSAMIAWAPIWrapperForceCreateConversationMutation.graphql","DollyMSAMIAWAPIWrapperPageDataQuery.graphql","DollyMSAMIAWAPIWrapperSaveConversationIDRootMutation.graphql","DollyMSAMIAWAPIWrapperSendAgentMessageMutation.graphql","DollyMSAMIAWEvent","DollySalesforceConfig","MDCXWwwMetaSupportAssistantControllerParamsRefineValidator","MiawConverstationStatus","SensitiveString","isEmpty","react","toTitleCase","useDollyMSAGenAIUserQuery","useMDCUrlAndReferrer","uuidv4"],(function(a,b,c,d,e,f,g){"use strict";var h,i,j,k,l,m,n,o,p,q=p||(p=d("react"));e=p;var r=e.useCallback,aa=e.useEffect,s=e.useMemo,ba=e.useRef,t=e.useState,ca=b("$InternalEnum")({CHAT_BOT:"Chatbot",AGENT:"Agent",END_USER:"EndUser",SYSTEM:"System"}),da=b("$InternalEnum").Mirrored(["Message","ParticipantChanged","RoutingResult","CloseConversation"]),ea=c("DollySalesforceConfig").UAT_MIAW_API_URL+"/eventrouter/v1/sse";function a(a){var e=a.children,f=a.initialContextID,g=a.initialQuery,p=a.initialRequestID;a=a.initialSessionID;a=d("CometRelay").useLazyLoadQuery(h!==void 0?h:h=b("DollyMSAMIAWAPIWrapperPageDataQuery.graphql"),{query:g!=null?g:"",session_id:a,skip_initial_query:(o||(o=c("isEmpty")))(g),initial_context_id:f,request_id:p});f=d("CometRouteParams").useCometRefinedRouteParams(d("MDCXWwwMetaSupportAssistantControllerParamsRefineValidator").refineMDCXWwwMetaSupportAssistantControllerParams)||{};p=f.sid;var u=c("useMDCUrlAndReferrer")();f=t(p!=null?p:"");var v=f[0],fa=f[1];p=t(!1);var w=p[0],x=p[1];f=t(null);var y=f[0],z=f[1];p=t(null);var A=p[0],B=p[1];f=t(null);var C=f[0],D=f[1];p=t(null);var E=p[0],F=p[1];f=t(!1);var G=f[0],H=f[1];p=t(!1);var I=p[0],J=p[1];f=t(d("MiawConverstationStatus").SSEStatus.NOT_STARTED);var K=f[0],L=f[1];p=t(!1);var M=p[0],N=p[1];f=t(new AbortController());var O=f[0],P=f[1],ga=r(function(){O==null||O.abort(),L(d("MiawConverstationStatus").SSEStatus.NOT_STARTED)},[O]);p=d("CometRelay").useMutation(i!==void 0?i:i=b("DollyMSAMIAWAPIWrapperSendAgentMessageMutation.graphql"));var Q=p[0];f=d("CometRelay").useMutation(j!==void 0?j:j=b("DollyMSAMIAWAPIWrapperAddHistoryRootMutation.graphql"));var R=f[0];p=t(typeof g==="string"&&!(o||(o=c("isEmpty")))(g)?[{id:c("uuidv4")().toString(),type:"user",content:g},{id:c("uuidv4")().toString(),type:"genai",fragment:a==null?void 0:a.xfb_care_sc_agent,userFragment:a,userQuery:g}]:[]);var ha=p[0],S=p[1],T=r(function(a){S(function(b){return[].concat(b,a)})},[]),ia=function(){S([])};f=t({});var ja=f[0],ka=f[1],U=r(function(a){ka(function(b){return babelHelpers["extends"]({},b,(b={},b[a]=!0,b))})},[ka]);a=t({});var la=a[0],ma=a[1],V=r(function(a){ma(function(b){return babelHelpers["extends"]({},b,(b={},b[a]=!0,b))})},[ma]);g=t("");var W=g[0],na=g[1],oa=ba(!1),X=r(function(a){T(a.map(function(a){return a}));a=a.map(function(a){if(a.content==null||(o||(o=c("isEmpty")))(a.unixtime))return null;var b=a.type,d;b==="agent"?d="AGENT":b==="genai"?d="GENAI":b==="admin"?d="ADMIN":d="USER";return{source:d,message:a.content,message_timestamp:a.unixtime,sender_display_name:a.displayName,is_live_agent_message:w}});R({variables:{input:{session_id:v,messages:a.filter(Boolean)}}})},[T,w,R,v]),pa=c("useDollyMSAGenAIUserQuery")(),qa=r(function(a,b){var d=b!=null?b:c("uuidv4")().toString();T([{id:d+"-query",type:"user",content:a}]);pa({userQuery:a,session_id:v,request_id:d}).then(function(b){T([{id:d,type:"genai",fragment:b==null?void 0:b.xfb_care_sc_agent,userQuery:a,userFragment:b,unixtime:Date.now()}])})["catch"](function(a){})},[T,pa,v]);p=t(!1);var ra=p[0],sa=p[1];f=d("CometRelay").useMutation(k!==void 0?k:k=b("DollyMSAMIAWAPIWrapperCreateConversationMutation.graphql"));var ta=f[0];a=d("CometRelay").useMutation(l!==void 0?l:l=b("DollyMSAMIAWAPIWrapperCloseConversationMutation.graphql"));var ua=a[0];g=d("CometRelay").useMutation(m!==void 0?m:m=b("DollyMSAMIAWAPIWrapperForceCreateConversationMutation.graphql"));var va=g[0];p=d("CometRelay").useMutation(n!==void 0?n:n=b("DollyMSAMIAWAPIWrapperSaveConversationIDRootMutation.graphql"));var Y=p[0],wa=r(function(a,b){var c;a=JSON.parse(b.entryPayload);B(a==null||(c=a.estimatedWaitTime)==null?void 0:c.estimatedWaitTimeInSeconds)},[]),xa=r(function(a,b){var e=JSON.parse(b.entryPayload);if(e==null||a==null)return;var f=e==null?void 0:e.id;if(e.entryType===da.ParticipantChanged){var g;e==null||(g=e.entries)==null||g.forEach(function(e){var g;if((e==null||(g=e.participant)==null?void 0:g.role)===ca.AGENT){var h=c("toTitleCase")(e==null?void 0:e.displayName);e.operation==="add"?(d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"agent_join",conversation_id:a,placement:"help_center.msa.chat"})),x(!0),z(h),N(!1),X([{type:"admin",id:f,content:"# Chat started with "+h+"
---
The chat will stay open 8 hours after your last message.
If you step away for any reason, you can always come back to this chat.",unixtime:Math.ceil((b==null?void 0:b.transcriptedTimestamp)/1e3)}])):e.operation==="remove"&&(d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"agent_leave",conversation_id:a,placement:"help_center.msa.chat"})),x(!1),J(!0),X([{type:"admin",id:f,content:h+" left the chat
You are now chatting with Meta AI support assistant",unixtime:Math.ceil((b==null?void 0:b.transcriptedTimestamp)/1e3)},{type:"genai",id:c("uuidv4")().toString(),content:"Hi, this is Meta AI support assistant again!
Is there anything else I can help you with?",unixtime:Math.ceil((b==null?void 0:b.transcriptedTimestamp)/1e3)+1}]))}})}},[X,u]),ya=r(function(a,b,c,e){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"received_receipt",conversation_id:a,placement:"help_center.msa.chat"})),V(e)},[V,u]),za=r(function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"read_receipt",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),U(a)},[C,U,u]),Aa=r(function(a,b,c,e){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"agent_message",conversation_id:a,placement:"help_center.msa.chat"})),X([{type:"agent",id:e,unixtime:Math.ceil(b.clientTimestamp/1e3),content:c,displayName:b.senderDisplayName}])},[X,u]),Z=r(function(a){L(d("MiawConverstationStatus").SSEStatus.CONNECTING);d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"sse_subscribe_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"}));var b=d("CarePlatformSalesforceMIAWAPIUtils").subscribeToAgentEvents(ea,{accept:"text/event-stream",authorization:"Bearer "+a.getContainedString(),"content-type":"application/json","X-Org-Id":c("DollySalesforceConfig").UAT_MIAW_API_ORG_ID},a.getContainedString(),ya,Aa,xa,wa,function(){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"typing_indicator_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),H(!0)},function(){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"typing_indicator_end",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),H(!1)},null,null,null,null,za)["catch"](function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"sse_subscribe_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:a.message})),L(d("MiawConverstationStatus").SSEStatus.ERROR)}).then(function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"sse_subscribe_success",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),L(d("MiawConverstationStatus").SSEStatus.CONNECTED),P(a)});return function(){b.then(function(a){a==null||a.abort()})["catch"](function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"sse_unsubscribe_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:a.message}))})}},[u,C,ya,Aa,xa,wa,za]),Ba=r(function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"close_conversation_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),void ua({onCompleted:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"close_conversation_success",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:((a=a.xfb_care_platform_chat_close_conversation)==null?void 0:a.success)!==!0?"Failed to close conversation":void 0}))},onError:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"close_conversation_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:(a=a.message)!=null?a:"Failed to close conversation with error"}))},variables:{input:{conversation_id:a,env:"UAT",vertical:"RL"}}})},[ua,C,u]),$=r(function(a){x(!0),N(!0),na(a),d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"resume_conversation_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),void ta({onCompleted:function(a){var b,e;d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"resume_conversation_success",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"}));b=(b=(b=a.xfb_care_platform_chat_initiate_conversation)==null?void 0:b.access_token)!=null?b:"";e=(e=a.xfb_care_platform_chat_initiate_conversation)==null?void 0:e.conversation_id;a=(a=a.xfb_care_platform_chat_initiate_conversation)==null?void 0:a.conversation_status;e!=null&&(void Y({variables:{input:{session_id:v,conversation_id:e}}}),D(e));a===d("MiawConverstationStatus").MiawConverstationStatus.ROUTED.valueOf()&&N(!1);e=new(c("SensitiveString"))(b);F(e);Z(e)},onError:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"resume_conversation_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:(a=a.message)!=null?a:"Failed to resume conversation with error"}))},variables:{input:{env:"UAT",vertical:"RL",case_routing_attributes:{}}}})},[u,C,ta,Z,Y,v]),Ca=r(function(a,b){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"create_conversation_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),x(!0),N(!0),na(b),void va({onCompleted:function(a){var b;d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"create_conversation_success",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"}));b=(b=(b=a.xfb_care_platform_chat_create_conversation)==null?void 0:b.access_token)!=null?b:"";a=(a=a.xfb_care_platform_chat_create_conversation)==null?void 0:a.conversation_id;a!=null&&(void Y({variables:{input:{session_id:v,conversation_id:a}}}),D(a));a=new(c("SensitiveString"))(b);F(a);Z(a)},onError:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"create_conversation_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:(a=a.message)!=null?a:"Failed to create conversation with error"}))},variables:{input:{env:"UAT",vertical:"RL",case_routing_attributes:a}}})},[u,C,va,Z,Y,v]);f=s(function(){return{isChatWithAgent:w,setIsChatWithAgent:x,conversationID:C,setConversationID:D,accessToken:E,setAccessToken:F,isAgentTyping:G,setIsAgentTyping:H,isStartingChatConnection:M,setIsStartingChatConnection:N,onAbortStream:ga,setAbortController:P,createConversation:Ca,resumeConversation:$,closeConsersation:Ba,agentName:y,setAgentName:z,estimatedWaitTime:A,setEstimatedWaitTime:B,setReadReceiptConfirmation:U,readReceiptStatus:ja,setReceivedReceiptConfirmation:V,receivedReceiptStatus:la,isReconnectable:I,setIsReconnectable:J,sseStatus:K}},[w,C,E,G,M,ga,Ca,$,y,A,U,ja,V,la,Ba,I,J,K]);a=s(function(){var a=function(a,b){if(w||I){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"user_live_agent_message_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"}));var e=b!=null?b:c("uuidv4")().toString();T([{id:e,type:"user",content:a,unixtime:Math.ceil(Date.now()/1e3),isLiveAgentMessage:!0,initialSendStatus:d("DollyChatMessagesContext.react").TDollyChatMessageStatus.SENT}]);Q({onCompleted:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"user_live_agent_message_success",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),S(function(b){return b.map(function(b){if(b.id===e&&b.type==="user"){var c,d;return babelHelpers["extends"]({},b,{SFID:(c=a==null||(d=a.xfb_care_platform_chat_send_message)==null?void 0:d.message_id)!=null?c:""})}return b})})},onError:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"user_live_agent_message_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:(a=a.message)!=null?a:"Failed to send user live agent message with error"}));S(function(a){return a.map(function(a){return a.id===e&&a.type==="user"?babelHelpers["extends"]({},a,{initialSendStatus:d("DollyChatMessagesContext.react").TDollyChatMessageStatus.ERROR}):a})})},variables:{input:{conversation_id:C!=null?C:"",env:"UAT",vertical:"RL",message:a}}});R({variables:{input:{session_id:v,messages:[{source:"USER",message:a,message_timestamp:Date.now(),is_live_agent_message:!0}]}}});I&&(K===d("MiawConverstationStatus").SSEStatus.NOT_STARTED&&$(""),K===d("MiawConverstationStatus").SSEStatus.CONNECTED&&N(!0),x(!0),J(!1))}else qa(a,b)},b=function(){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"user_message_stop",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),S(function(a){var b=a[a.length-1];return(b==null?void 0:b.type)==="genai"?a.slice(0,-1):a}),sa(!1)};return{messages:ha,onIncomingMessages:X,onOutgoingMessage:a,messageInFlight:ra,setMessageInFlight:sa,stopMessageResponse:b,sessionID:v,setSessionID:fa,invalidateSessionData:ia}},[ha,X,ra,v,w,I,u,C,T,Q,R,K,$,qa]);aa(function(){w&&!M&&!(o||(o=c("isEmpty")))(W.trim())&&oa.current===!1&&(oa.current=!0,d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"live_agent_handover_send_summary_start",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"})),Q({onCompleted:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"live_agent_handover_send_summary_success",conversation_id:C!=null?C:"",placement:"help_center.msa.chat"}))},onError:function(a){d("DollyMSAMIAWEvent").logDollyMSAMIAWEvent(babelHelpers["extends"]({},u,{event:"live_agent_handover_send_summary_error",conversation_id:C!=null?C:"",placement:"help_center.msa.chat",error:(a=a.message)!=null?a:"Failed to send handover summary message with error"}))},variables:{input:{conversation_id:C!=null?C:"",env:"UAT",vertical:"RL",message:"[[AI GENERATED SUMMARY]]
"+W}}}))},[M,W,Q,C,w,u]);return q.jsx(d("DollyChatMIAWContext.react").DollyChatMIAWProviderContext.Provider,{value:f,children:q.jsx(d("DollyChatMessagesContext.react").DollyChatMessagesProviderContext.Provider,{value:a,children:e})})}a.displayName=a.name+" [from "+f.id+"]";g["default"]=a}),98);
-----
DollyMSAMIAWAPIWrapperPageDataQuery_facebookRelayOperation",[],(function(a,b,c,d,e,f){e.exports="25059353550362436"}),null);
-----
-----
DollyMSAMIAWAPIWrapperPageDataQuery_facebookRelayOperation",[],(function(a,b,c,d,e,f){e.exports="25059353550362436"}),null);
-----