{ "version": 3, "sources": ["../../misc/intercom.ts"], "sourcesContent": ["/**\n * Note: Intercom integration is disabled for test users.\n */\nimport {report_error} from \"@cling/lib.shared.debug\"\nimport {assert_never} from \"@cling/lib.shared.utils\"\nimport {i18n} from \"@cling/lib.web.i18n\"\nimport {promp_state} from \"../dialogs/prompt\"\n\nexport function open_intercom(view: \"new_message\" | \"home\" | \"messages\") {\n const doit = () => {\n try {\n if (view === \"new_message\") {\n Intercom(\"showNewMessage\")\n } else if (view === \"home\") {\n Intercom(\"show\")\n } else if (view === \"messages\") {\n Intercom(\"showMessages\")\n } else {\n assert_never(view)\n }\n } catch {\n // Intercom is blocked in current browser, open help center instead.\n window.open(\"https://cling.com/detail\", \"_blank\", \"noopener\")\n }\n }\n if (!window.Intercom) {\n promp_state.show_prompt({\n onAccept: () => {\n startup()\n doit()\n },\n button_label_accept: i18n.ok,\n button_label_cancel: i18n.cancel,\n desktop_focus: \"accept\",\n title: i18n.we_need_your_approval,\n content: i18n.cookies_are_required_to_ensure,\n })\n } else {\n doit()\n }\n}\n\nfunction inject_intercom_code() {\n const i: any = function (...args: any[]) {\n i.c(args)\n }\n i.q = []\n i.c = function (args: any) {\n i.q.push(args)\n }\n window.Intercom = i\n // eslint-disable-next-line sonarjs/disabled-resource-integrity\n const s = document.createElement(\"script\")\n s.type = \"text/javascript\"\n s.async = true\n s.src = \"https://widget.intercom.io/widget/hdhrvn9l\"\n const x = document.getElementsByTagName(\"script\")[0]\n x.parentNode!.insertBefore(s, x)\n}\n\nfunction startup() {\n try {\n if (init_args.email?.endsWith(\"@example.com\")) {\n return\n }\n if (!window.Intercom) {\n inject_intercom_code()\n }\n window.Intercom(\"boot\", {\n app_id: \"hdhrvn9l\",\n user_id: init_args.crm_id,\n name: init_args.full_name,\n hide_default_launcher: true,\n vertical_padding: 60,\n })\n } catch (error) {\n report_error(error)\n }\n}\n\nlet init_args: {\n crm_id: string | undefined\n email: string | undefined\n full_name: string | undefined\n}\n\nexport function init(args: typeof init_args) {\n init_args = args\n if (document.cookie.includes(\"intercom-session-\")) {\n startup()\n }\n if (location.search.includes(\"notification_link_uid\")) {\n // The user clicked a link in an e-mail sent by Intercom.\n open_intercom(\"messages\")\n // Clean up the URL.\n window.history.replaceState(history.state, \"\", window.location.pathname)\n }\n}\n"], "mappings": "uKAQO,SAASA,EAAcC,EAA2C,CACrE,IAAMC,EAAOC,EAAA,IAAM,CACf,GAAI,CACIF,IAAS,cACT,SAAS,gBAAgB,EAClBA,IAAS,OAChB,SAAS,MAAM,EACRA,IAAS,WAChB,SAAS,cAAc,EAEvBG,EAAaH,CAAI,CAEzB,MAAQ,CAEJ,OAAO,KAAK,2BAA4B,SAAU,UAAU,CAChE,CACJ,EAfa,QAgBR,OAAO,SAaRC,EAAK,EAZLG,EAAY,YAAY,CACpB,SAAUF,EAAA,IAAM,CACZG,EAAQ,EACRJ,EAAK,CACT,EAHU,YAIV,oBAAqBK,EAAK,GAC1B,oBAAqBA,EAAK,OAC1B,cAAe,SACf,MAAOA,EAAK,sBACZ,QAASA,EAAK,8BAClB,CAAC,CAIT,CAhCgBJ,EAAAH,EAAA,iBAkChB,SAASQ,GAAuB,CAC5B,IAAMC,EAASN,EAAA,YAAaO,EAAa,CACrCD,EAAE,EAAEC,CAAI,CACZ,EAFe,KAGfD,EAAE,EAAI,CAAC,EACPA,EAAE,EAAI,SAAUC,EAAW,CACvBD,EAAE,EAAE,KAAKC,CAAI,CACjB,EACA,OAAO,SAAWD,EAElB,IAAME,EAAI,SAAS,cAAc,QAAQ,EACzCA,EAAE,KAAO,kBACTA,EAAE,MAAQ,GACVA,EAAE,IAAM,6CACR,IAAMC,EAAI,SAAS,qBAAqB,QAAQ,EAAE,CAAC,EACnDA,EAAE,WAAY,aAAaD,EAAGC,CAAC,CACnC,CAhBST,EAAAK,EAAA,wBAkBT,SAASF,GAAU,CACf,GAAI,CACA,GAAIO,EAAU,OAAO,SAAS,cAAc,EACxC,OAEC,OAAO,UACRL,EAAqB,EAEzB,OAAO,SAAS,OAAQ,CACpB,OAAQ,WACR,QAASK,EAAU,OACnB,KAAMA,EAAU,UAChB,sBAAuB,GACvB,iBAAkB,EACtB,CAAC,CACL,OAASC,EAAO,CACZC,EAAaD,CAAK,CACtB,CACJ,CAlBSX,EAAAG,EAAA,WAoBT,IAAIO,EAMG,SAASG,EAAKN,EAAwB,CACzCG,EAAYH,EACR,SAAS,OAAO,SAAS,mBAAmB,GAC5CJ,EAAQ,EAER,SAAS,OAAO,SAAS,uBAAuB,IAEhDN,EAAc,UAAU,EAExB,OAAO,QAAQ,aAAa,QAAQ,MAAO,GAAI,OAAO,SAAS,QAAQ,EAE/E,CAXgBG,EAAAa,EAAA", "names": ["open_intercom", "view", "doit", "__name", "assert_never", "promp_state", "startup", "i18n", "inject_intercom_code", "i", "args", "s", "x", "init_args", "error", "report_error", "init"] }