Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions javascript/userCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,23 @@ function renderHtmlResponse(elem, url, method, onSucceeded=null, onFailed=null,
});
}

function setupIntercom(userId, userName, userEmail, userCreatedAt) {
try {
const date = new Date(userCreatedAt);
window.Intercom("boot", {
api_base: "https://api-iam.intercom.io",
app_id: "idmms6yo",
user_id: userId,
name: userName,
email: userEmail,
created_at: Math.floor(date.getTime() / 1000),
});
window.Intercom("update");
} catch (error) {
console.error("Intercom setup error:", error);
}
}


let _isUserCenterInited = false;
function initUserCenter(realtimeData) {
Expand Down Expand Up @@ -445,6 +462,7 @@ function initUserCenter(realtimeData) {
);
}
_isUserCenterInited = true;
setupIntercom(orderInfo.user_id, orderInfo.nickname, orderInfo.email, orderInfo.registered_time);
}
// initialize user center
realtimeDataCallbacks.push(initUserCenter);
Expand Down
14 changes: 14 additions & 0 deletions modules/ui_gradio_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,28 @@ def stylesheet(fn):
return head


def body_end_scripts():
body = ""
body += """
<script>
// We pre-filled your app ID in the widget URL: 'https://widget.intercom.io/widget/idmms6yo'
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/idmms6yo';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
</script>
"""

return body


def reload_javascript():
css = css_html()

def template_response(*args, **kwargs):
js = javascript_html(args[1]['request'])
body_end_scripts = body_end_scripts()
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
res.body = res.body.replace(b'</body>', f'{body_end_scripts}</body>'.encode("utf8"))
res.init_headers()
return res

Expand Down