obi-sdk 0.1.9 → 0.2.0

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 CHANGED
@@ -9,17 +9,18 @@ A JavaScript SDK with dynamic content capabilities for integrating Obi into your
9
9
  - Framework-agnostic UI components using Web Components
10
10
  - Event-based API
11
11
  - TypeScript support
12
+ - Session persistence across page reloads
12
13
 
13
14
  ## Configuration Options
14
15
 
15
16
  The loader accepts the following configuration options:
16
17
 
17
- | Option | Type | Default | Description |
18
- | ---------- | ------- | ---------------- | ----------------------------------------------------------------------------------------------------------- |
19
- | `position` | string | `'bottom-right'` | Position of the widget on the page. Options: `'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'` |
20
- | `apiKey` | string | - | Your Obi API key (required for production) |
21
- | `autoInit` | boolean | `true` | Whether to initialize the widget automatically when loaded |
22
- | `user` | object | - | User information with `id` (required), `email` (optional) and `metadata` (optional) |
18
+ | Option | Type | Default | Description |
19
+ | ---------- | ------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20
+ | `position` | string | `'bottom-right'` | Position of the widget on the page. Options: `'bottom-right'`, `'bottom-left'`, `'bottom-center'`, `'top-right'`, `'top-left'`, `'top-center'`, `'middle-left'`, `'middle-right'` |
21
+ | `apiKey` | string | - | Your Obi API key (required for production) |
22
+ | `user` | object | - | User information with `id` (required), `email` (optional) and `metadata` (optional) |
23
+ | `isActive` | boolean | `true` | Whether to show the widget. Set to `false` to disable the widget for specific users |
23
24
 
24
25
  ## Installation Options
25
26
 
@@ -33,29 +34,30 @@ The simplest way to add Obi to your website is by using the inline loader script
33
34
 
34
35
  **Example HTML structure:**
35
36
 
36
- <!DOCTYPE html>
37
- <html>
38
- <head>
39
- <title>My Website with Obi</title>
40
- <script>
41
- // Configure Obi
42
- window.obiWidgetConfig = {
43
- position: "bottom-right",
44
- apiKey: "YOUR_API_KEY",
45
- user: {
46
- id: "user-123",
47
- email: "user@example.com",
48
- },
37
+ <!DOCTYPE html>
38
+ <html>
39
+ <head>
40
+ <title>My Website with Obi</title>
41
+ <script>
42
+ // Configure Obi
43
+ window.obiWidgetConfig = {
44
+ position: "bottom-right",
45
+ apiKey: "YOUR_API_KEY",
46
+ isActive: true,
47
+ user: {
48
+ id: "user-123",
49
+ email: "user@example.com",
49
50
  }
50
- </script>
51
- </head>
52
- <body>
53
- <!-- Your website content -->
54
- <script>
55
- (()=>{var s=window,d=document,r={position:"bottom-right",autoInit:!0};function t(){var t,e,o,a=s.obiWidgetConfig||{};for(t in r)t in a||(a[t]=r[t]);if("function"==typeof s.ObiSDK||"object"==typeof s.ObiSDK)l(a);else if(s.__obiSDKLoading)e=function(){l(a)},o=s.setInterval(function(){"function"!=typeof s.ObiSDK&&"object"!=typeof s.ObiSDK||(s.clearInterval(o),e())},100);else{var i=function(t){var e,o,i,n;t=t,e=function(){s.__obiSDKLoading=!1,l(a)},s.__obiSDKLoading=!0,(o=d.createElement("script")).type="text/javascript",o.async=!0,o.src=(i="https://unpkg.com/obi-sdk")+"@"+(n=t||"latest")+"/dist/obi-sdk.standalone.iife.js",o.onload=e,o.onerror=function(){"latest"!==n?(console.warn("Failed to load specific version, falling back to latest"),o.src=i+"@latest/dist/obi-sdk.standalone.iife.js",o.onload=e):(s.__obiSDKLoading=!1,console.error("Failed to load Obi SDK"))},d.head.appendChild(o)};try{var n=new XMLHttpRequest;n.open("GET","https://registry.npmjs.org/obi-sdk/latest"),n.onload=function(){if(200===n.status)try{var t=JSON.parse(n.responseText);i(t.version)}catch(t){i(null)}else i(null)},n.onerror=function(){i(null)},n.send()}catch(t){i(null)}}}function l(t){var e;d.querySelector("obi-widget")?console.log("Obi Widget already exists on the page"):customElements.get("obi-widget")?(e=d.createElement("obi-widget"),t.apiKey&&e.setAttribute("api-key",t.apiKey),t.position&&e.setAttribute("position",t.position),t.user&&e.setAttribute("user",JSON.stringify(t.user)),d.body.appendChild(e),console.log("Obi Widget added to page")):console.warn("Obi Widget component not registered - SDK may not have loaded properly")}s.__obiSDKLoading=s.__obiSDKLoading||!1,s.obiWidgetConfig&&!1===s.obiWidgetConfig.autoInit?console.log("Obi Widget auto-initialization disabled"):"complete"===d.readyState?t():s.attachEvent?s.attachEvent("onload",t):s.addEventListener("load",t,!1)})();
56
- </script>
57
- </body>
58
- </html>
51
+ }
52
+ </script>
53
+ </head>
54
+ <body>
55
+ <!-- Your website content -->
56
+ <script>
57
+ (()=>{var t,e,n=window,o=document,s=n.ObiSDK;"function"==typeof s||"object"==typeof s?s("update",n.obiWidgetConfig):((t=function(){t.q.push(arguments)}).q=[],n.ObiSDK=t,e=function(t){var e=o.createElement("script"),t=(e.type="text/javascript",e.async=!0,e.src="https://unpkg.com/obi-sdk@"+(t||"latest")+"/dist/obi-sdk.standalone.iife.js",o.getElementsByTagName("script")[0]);t.parentNode.insertBefore(e,t)},s=function(){try{var t=new XMLHttpRequest;t.open("GET","https://registry.npmjs.org/obi-sdk/latest"),t.onload=function(){if(200===t.status)try{e(JSON.parse(t.responseText).version)}catch(t){e()}else e()},t.onerror=function(){e()},t.send()}catch(t){e()}},"complete"===o.readyState?s():n.attachEvent?n.attachEvent("onload",s):n.addEventListener("load",s,!1))})();
58
+ </script>
59
+ </body>
60
+ </html>
59
61
 
60
62
  The widget will automatically appear in the specified position on your page.
61
63
 
@@ -69,6 +71,7 @@ You can also include the loader directly from our CDN:
69
71
  window.obiWidgetConfig = {
70
72
  position: "bottom-right",
71
73
  apiKey: "YOUR_API_KEY",
74
+ isActive: true,
72
75
  }
73
76
  </script>
74
77
 
@@ -78,15 +81,28 @@ You can also include the loader directly from our CDN:
78
81
 
79
82
  ## Widget Positioning
80
83
 
81
- The widget can be positioned in one of four corners of the page:
84
+ The widget can be positioned in one of eight positions on the page:
82
85
 
83
86
  ```js
84
87
  window.obiWidgetConfig = {
85
- position: "bottom-right", // Options: "bottom-right", "bottom-left", "top-right", "top-left"
88
+ position: "bottom-right", // Options: "bottom-right", "bottom-left", "bottom-center", "top-right", "top-left", "top-center", "middle-left", "middle-right"
86
89
  apiKey: "YOUR_API_KEY",
87
90
  }
88
91
  ```
89
92
 
93
+ ## Session Persistence
94
+
95
+ The SDK now supports session persistence across page reloads and navigation. If a user refreshes the page or navigates to another page on your site, the session with Obi will be automatically restored when they return, providing a seamless experience.
96
+
97
+ Key features of session persistence:
98
+
99
+ - Sessions are stored locally in the browser using a namespaced localStorage implementation
100
+ - Session data is automatically cleared after a configurable expiration time (default: 5 minutes)
101
+ - When reconnecting, the previous session state is restored, including the current conversation
102
+ - Users can manually end a session at any time by using the disconnect option
103
+
104
+ No additional configuration is required to enable this feature.
105
+
90
106
  ## License
91
107
 
92
108
  SEE LICENSE IN LICENSE.txt