@@ -160,9 +160,7 @@ <h3 class="text-lg font-medium leading-6 text-gray-900">Conversation List Displa
160
160
});
161
161
</ textarea >
162
162
</ div >
163
- < button id ="renderConversationListBtn " class ="mt-3 inline-flex items-center rounded-md bg-[#742ddd] px-3 py-2 text-sm text-white shadow-sm hover:bg-[#6211c8] ">
164
- Open Conversation List
165
- </ button >
163
+ < div id ="conversation-list-container "> </ div >
166
164
</ div >
167
165
</ div >
168
166
</ div >
@@ -195,7 +193,8 @@ <h3 class="text-lg font-medium leading-6 text-gray-900">Conversation List Displa
195
193
196
194
<!-- Live Demo -->
197
195
< script type ="module ">
198
- import { loadMessenger } from 'https://aiagent.stg.sendbirdtest.com/orgs/default/index.js' ;
196
+ // import { loadMessenger } from 'https://aiagent.stg.sendbirdtest.com/orgs/default/index.js';
197
+ import { loadMessenger } from 'http://localhost:8080/default/index.js' ;
199
198
200
199
const messenger = await loadMessenger ( ) ;
201
200
await messenger . initialize ( {
@@ -239,22 +238,47 @@ <h3 class="text-lg font-medium leading-6 text-gray-900">Conversation List Displa
239
238
messenger . close ( ) ;
240
239
} ) ;
241
240
242
- document . getElementById ( 'renderConversationListBtn' ) . addEventListener ( 'click' , async ( ) => {
243
- messenger . destroy ( ) ;
244
- const conversationListMessenger = await loadMessenger ( {
245
- customMainComponent : ( { messenger, react } ) => ( props ) => {
246
- return react . createElement ( messenger . AgentProviderContainer , props , [
247
- react . createElement ( messenger . ConversationList ) ,
248
- ] ) ;
249
- }
250
- } ) ;
251
- await conversationListMessenger . initialize ( {
252
- appId : import . meta. env . VITE_APP_ID ,
253
- aiAgentId : import . meta. env . VITE_AI_AGENT_ID ,
254
- customApiHost : import . meta. env . VITE_CUSTOM_API_HOST ,
255
- customWebSocketHost : import . meta. env . VITE_CUSTOM_WS_HOST ,
256
- rootElement : document . getElementById ( 'messenger-container' ) ,
257
- } ) ;
241
+ const conversationListMessenger = await loadMessenger ( {
242
+ customMainComponent : ( { messenger, react } ) => ( props ) => {
243
+ react . useEffect ( ( ) => {
244
+ const observer = new MutationObserver ( ( mutations ) => {
245
+ const agentEntry = document . getElementById ( 'sb-agent-entry' ) ;
246
+ if ( agentEntry ) {
247
+ agentEntry . style . setProperty ( 'width' , '100%' , 'important' ) ;
248
+ agentEntry . style . setProperty ( 'height' , '100%' , 'important' ) ;
249
+ observer . disconnect ( ) ;
250
+ }
251
+ } ) ;
252
+
253
+ observer . observe ( document . body , {
254
+ childList : true ,
255
+ subtree : true
256
+ } ) ;
257
+
258
+ return ( ) => observer . disconnect ( ) ;
259
+ } , [ ] ) ;
260
+
261
+ return react . createElement ( 'div' ,
262
+ {
263
+ style : {
264
+ width : '300px' ,
265
+ height : '500px' ,
266
+ border : '1px solid #ccc' ,
267
+ marginTop : '20px' ,
268
+ }
269
+ } , react . createElement ( messenger . AgentProviderContainer , props , [
270
+ react . createElement ( messenger . ConversationList ) ,
271
+ ] ) ) ;
272
+ } ,
273
+ containerId : 'conversation-list-container' ,
274
+ useShadowDOM : false ,
275
+ } ) ;
276
+
277
+ await conversationListMessenger . initialize ( {
278
+ appId : import . meta. env . VITE_APP_ID ,
279
+ aiAgentId : import . meta. env . VITE_AI_AGENT_ID ,
280
+ customApiHost : import . meta. env . VITE_CUSTOM_API_HOST ,
281
+ customWebSocketHost : import . meta. env . VITE_CUSTOM_WS_HOST ,
258
282
} ) ;
259
283
</ script >
260
284
</ body >
0 commit comments