@@ -34,6 +34,14 @@ class PlainChat(rx.Component):
3434 # Optional tier ID for thread details
3535 tier_id : rx .Var [str ] = rx .Var .create ("" )
3636
37+ # Entry point options
38+ # Type is either 'default' or 'chat'. 'default' opens intro screen, 'chat' opens straight into chat
39+ entry_point_type : rx .Var [str ] = rx .Var .create ("" )
40+ # The external ID of which chat to open. If not provided it defaults to the last conversation
41+ entry_point_external_id : rx .Var [str ] = rx .Var .create ("" )
42+ # Prevents the user from going back to the intro screen to start a new chat
43+ single_chat_mode : rx .Var [bool ] = rx .Var .create (False )
44+
3745 def add_imports (self ) -> dict :
3846 """Add React imports."""
3947 return {"react" : ["useEffect" ]}
@@ -92,6 +100,20 @@ def add_hooks(self) -> list[str | rx.Var]:
92100 initOptions.requireAuthentication = true;
93101 }}
94102
103+ // Add entryPoint if type, externalId, or singleChatMode is provided
104+ if ({ self .entry_point_type !s} || { self .entry_point_external_id !s} || { self .single_chat_mode !s} ) {{
105+ initOptions.entryPoint = {{}};
106+ if ({ self .entry_point_type !s} ) {{
107+ initOptions.entryPoint.type = { self .entry_point_type !s} ;
108+ }}
109+ if ({ self .entry_point_external_id !s} ) {{
110+ initOptions.entryPoint.externalId = { self .entry_point_external_id !s} ;
111+ }}
112+ if ({ self .single_chat_mode !s} ) {{
113+ initOptions.entryPoint.singleChatMode = true;
114+ }}
115+ }}
116+
95117 if (window.Plain) {{
96118 if (Plain.isInitialized()) {{
97119 // Already initialized, update in-place
@@ -109,7 +131,7 @@ def add_hooks(self) -> list[str | rx.Var]:
109131 script.src = 'https://chat.cdn-plain.com/index.js';
110132 script.onload = () => Plain.init(initOptions);
111133 document.head.appendChild(script);
112- }}, [{ self .full_name !s} , { self .short_name !s} , { self .chat_avatar_url !s} , { self .external_id !s} , { self .tier_id !s} , { self .email !s} , { self .email_hash !s} ])"""
134+ }}, [{ self .full_name !s} , { self .short_name !s} , { self .chat_avatar_url !s} , { self .external_id !s} , { self .tier_id !s} , { self .entry_point_type !s } , { self . entry_point_external_id !s } , { self . single_chat_mode !s } , { self . email !s} , { self .email_hash !s} ])"""
113135 )
114136 ]
115137
0 commit comments