Skip to content

Commit b5d1a2b

Browse files
committed
plan script
1 parent 5427412 commit b5d1a2b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

reflex_ui/blocks/plain.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Plain chat integration for customer support.
2+
3+
This module provides integration with Plain.com chat widget for live customer support.
4+
"""
5+
6+
import reflex as rx
7+
8+
PLAIN_INIT_SCRIPT = """
9+
(function(d, script) {{
10+
script = d.createElement('script');
11+
script.async = false;
12+
script.onload = function(){{
13+
Plain.init({{
14+
appId: 'liveChatApp_01KGG4JD5JHG8JY8X5CCN7811V',
15+
hideLauncher: {hide_launcher},
16+
hideBranding: true,
17+
theme: 'auto',
18+
}});
19+
}};
20+
script.src = 'https://chat.cdn-plain.com/index.js';
21+
d.getElementsByTagName('head')[0].appendChild(script);
22+
}}(document));
23+
"""
24+
25+
26+
def open_plain_chat() -> rx.event.EventSpec:
27+
"""Open the Plain chat widget.
28+
29+
Returns:
30+
An event spec that opens the Plain chat interface when triggered.
31+
"""
32+
return rx.call_script(
33+
"try { Plain.open(); } catch (e) { console.error('Plain chat not available:', e); }"
34+
)
35+
36+
37+
def get_plain_script(hide_launcher: bool = True) -> rx.Component:
38+
"""Get the Plain chat initialization script component.
39+
40+
Args:
41+
hide_launcher: Whether to hide the default Plain chat launcher button. Defaults to True.
42+
43+
Returns:
44+
A Reflex script component that initializes the Plain chat widget.
45+
"""
46+
return rx.script(PLAIN_INIT_SCRIPT.format(hide_launcher=str(hide_launcher).lower()))

0 commit comments

Comments
 (0)