autofaq chat
This commit is contained in:
parent
a299a93b0b
commit
a17080f4fd
@ -1,6 +1,8 @@
|
||||
import { reduxWrapper } from '../store'
|
||||
import numeral from 'numeral';
|
||||
import Script from 'next/script';
|
||||
import jwt from 'jsonwebtoken';
|
||||
//import 'https://chat.autofaq.ai/widget/static/css/main.css';
|
||||
|
||||
import '../css/style.css';
|
||||
|
||||
@ -28,7 +30,8 @@ const WrappedApp = (props) =>
|
||||
|
||||
return (
|
||||
<>
|
||||
{ props.observer && (
|
||||
<link href="//chat.autofaq.ai/widget/static/css/main.css" rel="stylesheet" />
|
||||
{ !props.observer && (
|
||||
<>
|
||||
<Script id="yandex-metrica" strategy={'afterInteractive'}>
|
||||
{`
|
||||
@ -42,6 +45,32 @@ const WrappedApp = (props) =>
|
||||
console.log(ym, ${ process.env.NEXT_PUBLIC_YANDEX_METRIKA_ID });
|
||||
`}
|
||||
</Script>
|
||||
<Script id="auto-faq" strategy={'afterInteractive'}>
|
||||
{`
|
||||
window.widgetHost = "https://chat.autofaq.ai";
|
||||
window.widgetServiceId = "${ process.env.NEXT_PUBLIC_AUTOFAQ_AI_SERVICE_ID }";
|
||||
window.widgetChannelId = "${ process.env.NEXT_PUBLIC_AUTOFAQ_AI_CHANNEL_ID }";
|
||||
|
||||
window.widgetUserLogin = ${ props.acc !== null ? `"${ props.acc }"` : "undefined" };
|
||||
window.widgetUserEmail = ${ props.email !== null ? `"${ props.email }"` : "undefined" };
|
||||
window.widgetUserPayload = ${ props.acc !== null ? `{ "acc_number": "${ props.acc }" }` : "undefined" };
|
||||
|
||||
console.log("widget", {
|
||||
widgetHost: window.widgetHost,
|
||||
widgetServiceId: window.widgetServiceId,
|
||||
widgetChannelId: window.widgetChannelId,
|
||||
widgetUserLogin: window.widgetUserLogin,
|
||||
widgetUserEmail: window.widgetUserEmail,
|
||||
widgetUserPayload: window.widgetUserPayload,
|
||||
});
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.id = "autofaqWidget";
|
||||
script.type = "text/javascript";
|
||||
script.src = "https://chat.autofaq.ai/widget/static/js/main.js";
|
||||
document.head.appendChild(script);
|
||||
`}
|
||||
</Script>
|
||||
<noscript>
|
||||
<div>
|
||||
<img src={`https://mc.yandex.ru/watch/${ process.env.NEXT_PUBLIC_YANDEX_METRIKA_ID }`} style={{ position:'absolute', left:'-9999px' }} alt=""/>
|
||||
@ -57,20 +86,41 @@ const WrappedApp = (props) =>
|
||||
WrappedApp.getInitialProps = async (props) =>
|
||||
{
|
||||
const { req } = props.ctx;
|
||||
|
||||
let observer = true;
|
||||
|
||||
let observer = false;
|
||||
let acc = null;
|
||||
let email = null;
|
||||
|
||||
if(req !== undefined)
|
||||
{
|
||||
const { cookies } = req;
|
||||
|
||||
if(cookies !== undefined && cookies !== null)
|
||||
{
|
||||
if(cookies.jwt !== undefined && cookies.jwt !== null)
|
||||
{
|
||||
let client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT);
|
||||
console.log({ client_jwt_decoded });
|
||||
acc = client_jwt_decoded.acc_number;
|
||||
email = client_jwt_decoded.login;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(req !== undefined && req.url !== null && req.url.indexOf("offstage") > -1)
|
||||
{
|
||||
observer = false;
|
||||
observer = true;
|
||||
}
|
||||
|
||||
if(req !== undefined && req.cookies !== undefined && req.cookies.observer !== undefined && req.cookies.observer === "true")
|
||||
{
|
||||
observer = false;
|
||||
observer = true;
|
||||
}
|
||||
|
||||
return {
|
||||
observer,
|
||||
acc,
|
||||
email,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user