Skip to content

Commit 7600202

Browse files
authored
Merge pull request #32 from sendbird/docs/js-update
docs: update README.md
2 parents 4948f8e + f83870d commit 7600202

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

js/README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Add the AI Agent SDK to your web page by importing it as a module.
3636

3737
```html
3838
<script type="module">
39-
import { loadMessenger } from "https://aiagent.sendbird.com/orgs/<org_name>/index.js";
39+
import { loadMessenger } from "https://aiagent.sendbird.com/orgs/default/index.js";
4040
</script>
4141
```
4242

@@ -62,7 +62,7 @@ For proper user session management, you can update the session information using
6262

6363
```javascript
6464
// Update entire session configuration
65-
await messenger.updateUserSession({
65+
messenger.updateUserSession({
6666
userId: 'new_user_id',
6767
authToken: 'new_auth_token',
6868
// this callback should handle session token refresh:
@@ -85,7 +85,7 @@ To launch and display the messenger, implement the code below:
8585
8686
```javascript
8787
const messenger = await loadMessenger();
88-
await messenger.initialize({
88+
messenger.initialize({
8989
appId: 'YOUR_APP_ID',
9090
aiAgentId: 'YOUR_AI_AGENT_ID',
9191
});
@@ -94,11 +94,11 @@ To launch and display the messenger, implement the code below:
9494
The messenger view can be programmatically controlled using the `open()` and `close()` methods:
9595

9696
```javascript
97-
// Open the messenger view automatically after 1 second after initialized
98-
await messenger.initialize({ appId, aiAgentId });
99-
setTimeout(() => {
97+
// Open the messenger view automatically after initialized
98+
messenger.initialize({ appId, aiAgentId });
99+
messenger.onLoad(() => {
100100
messenger.open();
101-
}, 1000);
101+
});
102102

103103
// Close the messenger view by clicking a button
104104
<button onClick={() => messenger.close()}>Close</button>
@@ -108,7 +108,7 @@ To update the configurations:
108108

109109
```javascript
110110
// Update configuration
111-
await messenger.updateConfig({
111+
messenger.updateConfig({
112112
appId: 'NEW_APP_ID',
113113
aiAgentId: 'NEW_BOT_ID',
114114
// ... other config options
@@ -126,16 +126,19 @@ The following are available advanced features.
126126
![Image](https://github.com/user-attachments/assets/348ccad1-ec9a-4851-9324-084eaf569e34)
127127

128128
```javascript
129-
const messenger = await loadMessenger();
130-
await messenger.initialize({
129+
const messenger = await loadMessenger({
130+
// Use Conversation component to display only the messenger without the launcher
131+
customMainComponent: ({ messenger, react }) => {
132+
return (props) => {
133+
return react.createElement(messenger.AgentProviderContainer, props, [
134+
react.createElement(messenger.Conversation),
135+
]);
136+
};
137+
}
138+
});
139+
messenger.initialize({
131140
appId: 'APP_ID',
132141
aiAgentId: 'AI_AGENT_ID',
133-
// Use Conversation component to display only the messenger without the launcher
134-
customMainComponent: (coreModule) => (props) => (
135-
<coreModule.AgentProviderContainer {...props}>
136-
<coreModule.Conversation />
137-
</coreModule.AgentProviderContainer>
138-
),
139142
});
140143
```
141144

0 commit comments

Comments
 (0)