@robylon/web-react-sdk 1.1.41-staging.2 → 1.1.41-staging.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -19
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/ChatbotFloatingButton.d.ts +3 -0
- package/dist/cjs/types/components/ChatbotIframe.d.ts +4 -0
- package/dist/cjs/types/components/RobylonChatbot.d.ts +16 -3
- package/dist/cjs/types/core/config.d.ts +7 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/types/events.d.ts +8 -1
- package/dist/cjs/types/types.d.ts +50 -0
- package/dist/cjs/types/utils/fetchData.d.ts +7 -1
- package/dist/cjs/types/utils/launcherInfo.d.ts +9 -0
- package/dist/cjs/types/utils/mockProactive.d.ts +2 -0
- package/dist/cjs/types/utils/proactive.d.ts +19 -0
- package/dist/cjs/types/utils/sanitize.d.ts +4 -0
- package/dist/cjs/types/utils/url.d.ts +8 -0
- package/dist/cjs/types/vanilla/components/ChatbotContainer.d.ts +1 -1
- package/dist/cjs/types/vanilla/components/ChatbotFloatingButton.d.ts +10 -0
- package/dist/cjs/types/vanilla/components/ChatbotIframe.d.ts +13 -0
- package/dist/cjs/types/vanilla/index.d.ts +9 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/ChatbotFloatingButton.d.ts +3 -0
- package/dist/esm/types/components/ChatbotIframe.d.ts +4 -0
- package/dist/esm/types/components/RobylonChatbot.d.ts +16 -3
- package/dist/esm/types/core/config.d.ts +7 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/types/events.d.ts +8 -1
- package/dist/esm/types/types.d.ts +50 -0
- package/dist/esm/types/utils/fetchData.d.ts +7 -1
- package/dist/esm/types/utils/launcherInfo.d.ts +9 -0
- package/dist/esm/types/utils/mockProactive.d.ts +2 -0
- package/dist/esm/types/utils/proactive.d.ts +19 -0
- package/dist/esm/types/utils/sanitize.d.ts +4 -0
- package/dist/esm/types/utils/url.d.ts +8 -0
- package/dist/esm/types/vanilla/components/ChatbotContainer.d.ts +1 -1
- package/dist/esm/types/vanilla/components/ChatbotFloatingButton.d.ts +10 -0
- package/dist/esm/types/vanilla/components/ChatbotIframe.d.ts +13 -0
- package/dist/esm/types/vanilla/index.d.ts +9 -0
- package/dist/index.d.ts +82 -3
- package/dist/umd/robylon-chatbot.js +1 -1
- package/dist/umd/robylon-chatbot.js.map +1 -1
- package/dist/umd/types/components/ChatbotFloatingButton.d.ts +3 -0
- package/dist/umd/types/components/ChatbotIframe.d.ts +4 -0
- package/dist/umd/types/components/RobylonChatbot.d.ts +16 -3
- package/dist/umd/types/core/config.d.ts +7 -0
- package/dist/umd/types/index.d.ts +1 -0
- package/dist/umd/types/types/events.d.ts +8 -1
- package/dist/umd/types/types.d.ts +50 -0
- package/dist/umd/types/utils/fetchData.d.ts +7 -1
- package/dist/umd/types/utils/launcherInfo.d.ts +9 -0
- package/dist/umd/types/utils/mockProactive.d.ts +2 -0
- package/dist/umd/types/utils/proactive.d.ts +19 -0
- package/dist/umd/types/utils/sanitize.d.ts +4 -0
- package/dist/umd/types/utils/url.d.ts +8 -0
- package/dist/umd/types/vanilla/components/ChatbotContainer.d.ts +1 -1
- package/dist/umd/types/vanilla/components/ChatbotFloatingButton.d.ts +10 -0
- package/dist/umd/types/vanilla/components/ChatbotIframe.d.ts +13 -0
- package/dist/umd/types/vanilla/index.d.ts +9 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -6,21 +6,17 @@ The Robylon SDK provides an easy way to integrate a customizable chatbot into yo
|
|
|
6
6
|
|
|
7
7
|
- [Installation](#installation)
|
|
8
8
|
- [React SDK Usage](#react-sdk-usage)
|
|
9
|
+
- [Basic Implementation](#react-basic-implementation)
|
|
10
|
+
- [External Triggers](#react-external-triggers)
|
|
11
|
+
- [Event Handling](#react-event-handling)
|
|
9
12
|
- [Plain JavaScript & No-Code Integration](#plain-javascript--no-code-integration)
|
|
10
13
|
- [Quick Embed (Easiest Method)](#quick-embed-easiest-method)
|
|
14
|
+
- [ES5/Google Tag Manager](#es5google-tag-manager)
|
|
11
15
|
- [Option 1: Quick Setup - Load with Page](#option-1-quick-setup---load-with-page)
|
|
12
16
|
- [Option 2: Reliable Loading - After DOM is Ready](#option-2-reliable-loading---after-dom-is-ready)
|
|
13
17
|
- [Option 3: User Context - Initialize After User Data](#option-3-user-context---initialize-after-user-data)
|
|
14
18
|
- [Configuration Options](#configuration-options)
|
|
15
19
|
- [Event Handling](#event-handling)
|
|
16
|
-
- [Customization](#customization)
|
|
17
|
-
- [Troubleshooting](#troubleshooting)
|
|
18
|
-
- [Platform-Specific Integration Guides](#platform-specific-integration-guides)
|
|
19
|
-
- [Webflow](#webflow-integration)
|
|
20
|
-
- [Wix](#wix-integration)
|
|
21
|
-
- [Shopify](#shopify-integration)
|
|
22
|
-
- [WordPress](#wordpress-integration)
|
|
23
|
-
- [Using the SDK from CDN](#using-the-sdk-from-cdn)
|
|
24
20
|
|
|
25
21
|
## Installation
|
|
26
22
|
|
|
@@ -122,6 +118,93 @@ The React component accepts an `onEvent` prop for handling chatbot events:
|
|
|
122
118
|
|
|
123
119
|
The `Chatbot` component renders a floating button that opens a chat interface when clicked. It handles all the communication with the Robylon backend services.
|
|
124
120
|
|
|
121
|
+
### React: External Triggers
|
|
122
|
+
|
|
123
|
+
You can control the chatbot iframe from outside the component using a ref. This allows you to trigger open, close, or toggle actions from anywhere in your application:
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
import React, { useRef, useState, useEffect } from "react";
|
|
127
|
+
import { Chatbot, ChatbotRef } from "@robylon/web-react-sdk";
|
|
128
|
+
|
|
129
|
+
function App() {
|
|
130
|
+
const chatbotRef = useRef < ChatbotRef > null;
|
|
131
|
+
const [isChatbotReady, setIsChatbotReady] = useState(false);
|
|
132
|
+
|
|
133
|
+
// Method 1: Check readiness state before calling methods
|
|
134
|
+
const showChatbot = () => {
|
|
135
|
+
if (chatbotRef.current?.isReady) {
|
|
136
|
+
chatbotRef.current.show();
|
|
137
|
+
} else {
|
|
138
|
+
console.log("Chatbot not ready yet");
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const hideChatbot = () => {
|
|
143
|
+
chatbotRef.current?.hide();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const toggleChatbot = () => {
|
|
147
|
+
chatbotRef.current?.toggle();
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Method 2: Listen for ready event
|
|
151
|
+
const handleChatbotEvent = (event) => {
|
|
152
|
+
if (event.type === "CHATBOT_READY") {
|
|
153
|
+
setIsChatbotReady(true);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div className="App">
|
|
159
|
+
<h1>My Website</h1>
|
|
160
|
+
|
|
161
|
+
{/* External control buttons with readiness state */}
|
|
162
|
+
<button onClick={showChatbot} disabled={!isChatbotReady}>
|
|
163
|
+
Show Chatbot
|
|
164
|
+
</button>
|
|
165
|
+
<button onClick={hideChatbot}>Hide Chatbot</button>
|
|
166
|
+
<button onClick={toggleChatbot}>Toggle Chatbot</button>
|
|
167
|
+
|
|
168
|
+
<Chatbot
|
|
169
|
+
ref={chatbotRef}
|
|
170
|
+
api_key="YOUR_API_KEY"
|
|
171
|
+
user_id="optional-user-id"
|
|
172
|
+
onEvent={handleChatbotEvent}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Available External Methods & Properties
|
|
180
|
+
|
|
181
|
+
| Method/Property | Type | Description |
|
|
182
|
+
| --------------- | -------- | ------------------------------------------------------ |
|
|
183
|
+
| `show()` | function | Opens the chatbot iframe if it's currently closed |
|
|
184
|
+
| `hide()` | function | Closes the chatbot iframe if it's currently open |
|
|
185
|
+
| `toggle()` | function | Toggles the chatbot iframe visibility |
|
|
186
|
+
| `isReady` | boolean | Indicates if the chatbot is ready for external control |
|
|
187
|
+
|
|
188
|
+
#### Event Handling with External Triggers
|
|
189
|
+
|
|
190
|
+
External trigger methods emit the same events as internal triggers:
|
|
191
|
+
|
|
192
|
+
- `CHATBOT_BUTTON_CLICKED` - When `show()` or `toggle()` opens the chatbot
|
|
193
|
+
- `CHATBOT_CLOSED` - When `hide()` or `toggle()` closes the chatbot
|
|
194
|
+
- `CHATBOT_READY` - When the chatbot is ready for external control (emitted once after initialization)
|
|
195
|
+
|
|
196
|
+
This ensures consistent event handling regardless of how the chatbot is triggered.
|
|
197
|
+
|
|
198
|
+
#### Readiness Handling
|
|
199
|
+
|
|
200
|
+
The SDK provides multiple ways to handle chatbot readiness:
|
|
201
|
+
|
|
202
|
+
1. **Check `isReady` property** - Synchronous check before calling methods
|
|
203
|
+
2. **Listen for `CHATBOT_READY` event** - Event-based notification when ready
|
|
204
|
+
3. **Guard clauses** - Methods safely handle early calls with console warnings
|
|
205
|
+
|
|
206
|
+
This prevents race conditions and provides a smooth user experience.
|
|
207
|
+
|
|
125
208
|
## Plain JavaScript & No-Code Integration
|
|
126
209
|
|
|
127
210
|
> **IMPORTANT:** You will need an API key from Robylon for any integration to work.
|
|
@@ -136,6 +219,18 @@ This is the simplest way to add the Robylon chatbot to any website with a single
|
|
|
136
219
|
|
|
137
220
|
Just replace `YOUR_API_KEY_HERE` with your actual Robylon API key, and you're done! No additional code is needed.
|
|
138
221
|
|
|
222
|
+
### ES5/Google Tag Manager
|
|
223
|
+
|
|
224
|
+
#### ES5 Compatible Version
|
|
225
|
+
|
|
226
|
+
For older browsers that don't support ES6 features, use this ES5 compatible version:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
<script>(function(a){window.R=window.R||function(){(window.R.q=window.R.q||[]).push(Array.prototype.slice.call(arguments))};window.R.show=function(){window.R('show')};window.R.hide=function(){window.R('hide')};window.R.toggle=function(){window.R('toggle')};window.R.track=function(){window.R('track',Array.prototype.slice.call(arguments))};var o=function(){var s=document.createElement("script");s.src="https://cdn.robylon.ai/sdk/latest/chatbot.js";s.id="robylon-chatbot-sdk";s.onload=function(){if(a){window.RobylonChatbot.create({api_key:a})}};document.body.appendChild(s)};if(document.readyState==="complete"){o()}else{window.addEventListener("load",o)}})("YOUR_API_KEY_HERE");</script>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
This version is compatible with Internet Explorer 11 and other older browsers that don't support ES6 features like arrow functions, `const`/`let`, and Proxy objects.
|
|
233
|
+
|
|
139
234
|
#### Quick Embed with Custom Position and Spacing
|
|
140
235
|
|
|
141
236
|
If you want to customize the position and spacing of the chatbot button, you can use this alternative version:
|
|
@@ -151,6 +246,16 @@ Just replace:
|
|
|
151
246
|
- `30` with your desired side spacing in pixels
|
|
152
247
|
- `25` with your desired bottom spacing in pixels
|
|
153
248
|
|
|
249
|
+
##### ES5 Compatible Version with Custom Position and Spacing
|
|
250
|
+
|
|
251
|
+
For older browsers, use this ES5 compatible version with custom positioning:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
<script>(function(a,p,s,b){window.R=window.R||function(){(window.R.q=window.R.q||[]).push(Array.prototype.slice.call(arguments))};window.R.show=function(){window.R('show')};window.R.hide=function(){window.R('hide')};window.R.toggle=function(){window.R('toggle')};window.R.track=function(){window.R('track',Array.prototype.slice.call(arguments))};var o=function(){var s=document.createElement("script");s.src="https://cdn.robylon.ai/sdk/latest/chatbot.js";s.id="robylon-chatbot-sdk";s.onload=function(){if(a){window.RobylonChatbot.create({api_key:a,position:p,sideSpacing:s,bottomSpacing:b})}};document.body.appendChild(s)};if(document.readyState==="complete"){o()}else{window.addEventListener("load",o)}})("YOUR_API_KEY_HERE","Left",30,25);</script>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Replace the same parameters as above for the ES5 compatible version.
|
|
258
|
+
|
|
154
259
|
#### Where to place the script:
|
|
155
260
|
|
|
156
261
|
- At the end of your HTML `<body>` section for best performance
|
|
@@ -410,22 +515,25 @@ const chatbot = RobylonChatbot.create({
|
|
|
410
515
|
// chatbot.hide(); // Hide the chatbot
|
|
411
516
|
// chatbot.toggle(); // Toggle visibility
|
|
412
517
|
// chatbot.destroy(); // Remove the chatbot from the page
|
|
518
|
+
|
|
519
|
+
> **Note:** The plain JavaScript SDK provides direct instance methods for external control. The React SDK provides similar functionality through refs (see [React External Triggers](#react-external-triggers) section above).
|
|
413
520
|
```
|
|
414
521
|
|
|
415
522
|
## Configuration Options
|
|
416
523
|
|
|
417
|
-
The SDK supports the following configuration options for both React and plain JavaScript implementations
|
|
524
|
+
The SDK supports the following configuration options for both React and plain JavaScript implementations. **Note:** The React SDK also supports external triggers via refs for programmatic control of the chatbot iframe.
|
|
418
525
|
|
|
419
|
-
| Option | Type | Description
|
|
420
|
-
| ------------- | -------- |
|
|
421
|
-
| api_key | string | Your Robylon API key
|
|
422
|
-
| user_id | string | User identifier for conversation tracking
|
|
423
|
-
| user_token | string | Authentication token
|
|
424
|
-
| user_profile | object | Additional user information
|
|
425
|
-
| onEvent | function | Event handler for chatbot interactions
|
|
426
|
-
| position | string | Position of the chatbot button ("Left"/"Right")
|
|
427
|
-
| sideSpacing | number | Distance from the side of the screen (in px)
|
|
428
|
-
| bottomSpacing | number | Distance from the bottom of the screen (in px)
|
|
526
|
+
| Option | Type | Description | Required/Optional |
|
|
527
|
+
| ------------- | -------- | ------------------------------------------------- | ----------------- |
|
|
528
|
+
| api_key | string | Your Robylon API key | Required |
|
|
529
|
+
| user_id | string | User identifier for conversation tracking | Optional |
|
|
530
|
+
| user_token | string | Authentication token | Optional |
|
|
531
|
+
| user_profile | object | Additional user information | Optional |
|
|
532
|
+
| onEvent | function | Event handler for chatbot interactions | Optional |
|
|
533
|
+
| position | string | Position of the chatbot button ("Left"/"Right") | Optional |
|
|
534
|
+
| sideSpacing | number | Distance from the side of the screen (in px) | Optional |
|
|
535
|
+
| bottomSpacing | number | Distance from the bottom of the screen (in px) | Optional |
|
|
536
|
+
| show_launcher | boolean | Show the floating launcher button (default: true) | Optional |
|
|
429
537
|
|
|
430
538
|
### Position and Spacing Configuration
|
|
431
539
|
|
|
@@ -442,6 +550,14 @@ You can control the position and spacing of the chatbot button either through th
|
|
|
442
550
|
/>
|
|
443
551
|
```
|
|
444
552
|
|
|
553
|
+
#### React: Hide Floating Launcher Button
|
|
554
|
+
|
|
555
|
+
To hide the floating launcher and manage visibility via external triggers or custom UI, set `show_launcher` to `false` (defaults to `true`):
|
|
556
|
+
|
|
557
|
+
```jsx
|
|
558
|
+
<Chatbot api_key="YOUR_API_KEY" show_launcher={false} />
|
|
559
|
+
```
|
|
560
|
+
|
|
445
561
|
#### Plain JavaScript Example:
|
|
446
562
|
|
|
447
563
|
```javascript
|
|
@@ -465,6 +581,7 @@ The SDK emits the following events that you can listen for in both React and pla
|
|
|
465
581
|
| `CHATBOT_LOADED` | The chatbot iframe has been loaded | - |
|
|
466
582
|
| `CHATBOT_OPENED` | The chatbot has been opened | - |
|
|
467
583
|
| `CHATBOT_CLOSED` | The chatbot has been closed | - |
|
|
584
|
+
| `CHATBOT_READY` | The chatbot is ready for external control | - |
|
|
468
585
|
| `CHAT_INITIALIZED` | The chat session has been initialized | - |
|
|
469
586
|
| `CHAT_INITIALIZATION_FAILED` | The chat session failed to initialize | `{ error: string }` |
|
|
470
587
|
| `SESSION_REFRESHED` | The chat session has been refreshed | - |
|