@sawport/react-sdk 1.2.5-alpha.3 → 1.2.5-alpha.5
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 +212 -163
- package/dist/index.js +571 -331
- package/dist/index.standalone.js +6 -6
- package/dist/index.umd.js +6 -6
- package/dist/react-sdk.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,214 +1,263 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sawport Widget Integration Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Sawport Widget enables secure customer interactions—video calls, chat, document upload, and e-signature—embedded directly into your website or web application.
|
|
6
|
+
|
|
7
|
+
Available integrations:
|
|
8
|
+
- Web (CDN Embedded)
|
|
9
|
+
- React SDK
|
|
10
|
+
- Vue.js ES Module Integration
|
|
11
|
+
|
|
12
|
+
This guide provides configuration steps and usage examples for all supported platforms.
|
|
13
|
+
|
|
14
|
+
## Using Sawport Widget on the Web (CDN)
|
|
15
|
+
|
|
16
|
+
### 2.1 Add Required Scripts and Styles
|
|
17
|
+
Place this inside your HTML `<head>` tag:
|
|
2
18
|
|
|
3
|
-
## Web Usage
|
|
4
|
-
### Pull the Sawport Widget CSS from your HTML head into your web page.
|
|
5
19
|
```html
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
<link
|
|
21
|
+
href="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/react-sdk.css"
|
|
22
|
+
rel="stylesheet"
|
|
23
|
+
/>
|
|
10
24
|
```
|
|
11
25
|
|
|
12
|
-
### Create
|
|
26
|
+
### 2.2 Create Widget Container & Mount the Widget
|
|
27
|
+
Place this immediately after the `<body>` tag:
|
|
28
|
+
|
|
13
29
|
```html
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
<div style="position: fixed; bottom: 20px; right: 20px; z-index: 200" id="sawport-widget"></div>
|
|
31
|
+
|
|
32
|
+
<script src="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/index.standalone.js" type="text/javascript"></script>
|
|
33
|
+
|
|
34
|
+
<script type="text/javascript">
|
|
35
|
+
function docReady(fn) {
|
|
36
|
+
['complete', 'interactive'].includes(document.readyState)
|
|
37
|
+
? setTimeout(fn, 1)
|
|
38
|
+
: document.addEventListener('DOMContentLoaded', fn);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
docReady(() => window.sawportReactSDK.mountWidget(
|
|
42
|
+
{
|
|
43
|
+
baseURL: "https://{{BASE_URL}}",
|
|
44
|
+
apiURL: "https://{{BASE_URL}}/api/v1/",
|
|
45
|
+
projectId: "{{PROJECT_ID}}",
|
|
46
|
+
user: { email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname' }, // optional
|
|
47
|
+
},
|
|
48
|
+
"sawport-widget"
|
|
49
|
+
));
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
17
52
|
```
|
|
18
53
|
|
|
19
|
-
###
|
|
20
|
-
After pulling the sawport SDK
|
|
21
|
-
Global variable `sawportSDK` will be exposed to your webpage which you can access its method and properties.
|
|
54
|
+
### 2.3 Complete HTML Example
|
|
22
55
|
|
|
23
|
-
**Important**: Use the `standalone` bundle for CDN usage to prevent React version conflicts:
|
|
24
56
|
```html
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
<!DOCTYPE html>
|
|
58
|
+
<html>
|
|
59
|
+
<head>
|
|
60
|
+
<link
|
|
61
|
+
href="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/react-sdk.css"
|
|
62
|
+
rel="stylesheet"
|
|
63
|
+
/>
|
|
64
|
+
</head>
|
|
65
|
+
|
|
66
|
+
<body>
|
|
67
|
+
<!-- Your website content -->
|
|
68
|
+
|
|
69
|
+
<div
|
|
70
|
+
style="position: fixed; bottom: 20px; right: 20px; z-index: 200"
|
|
71
|
+
id="sawport-widget"
|
|
72
|
+
></div>
|
|
73
|
+
|
|
74
|
+
<script src="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/index.standalone.js" type="text/javascript"></script>
|
|
75
|
+
|
|
76
|
+
<script type="text/javascript">
|
|
77
|
+
function docReady(fn) {
|
|
78
|
+
['complete', 'interactive'].includes(document.readyState)
|
|
79
|
+
? setTimeout(fn, 1)
|
|
80
|
+
: document.addEventListener('DOMContentLoaded', fn);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
docReady(() => window.sawportReactSDK.mountWidget(
|
|
84
|
+
{
|
|
85
|
+
baseURL: "https://{{BASE_URL}}",
|
|
86
|
+
apiURL: "https://{{BASE_URL}}/api/v1/",
|
|
87
|
+
projectId: "{{PROJECT_ID}}",
|
|
88
|
+
user: { email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname' }, // optional
|
|
89
|
+
},
|
|
90
|
+
"sawport-widget"
|
|
91
|
+
));
|
|
92
|
+
</script>
|
|
93
|
+
</body>
|
|
94
|
+
</html>
|
|
28
95
|
```
|
|
29
96
|
|
|
30
|
-
###
|
|
31
|
-
|
|
97
|
+
### 2.4 Updating Enterprise Credentials Dynamically
|
|
98
|
+
|
|
32
99
|
```html
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
100
|
+
<script type="text/javascript">
|
|
101
|
+
window.sawportReactSDK.setSawportConfig({
|
|
102
|
+
baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
|
|
103
|
+
apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
|
|
104
|
+
projectId: 'XXXXXXXXXXXXXX',
|
|
105
|
+
user: {
|
|
106
|
+
email: 'example@email.com',
|
|
107
|
+
mobile: '080XXXXXXXXX',
|
|
108
|
+
name: 'Firstname Lastname',
|
|
38
109
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
|
|
42
|
-
apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
|
|
43
|
-
projectId: XXXXXXXXXXXXXX,
|
|
44
|
-
user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
|
|
45
|
-
}, 'sawport-widget'))
|
|
46
|
-
</script>
|
|
47
|
-
</body>
|
|
110
|
+
});
|
|
111
|
+
</script>
|
|
48
112
|
```
|
|
49
113
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
docReady(() => sawportSDK.setSawportConfig({
|
|
54
|
-
baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
|
|
55
|
-
apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
|
|
56
|
-
projectId: XXXXXXXXXXXXXX,
|
|
57
|
-
user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
|
|
58
|
-
})
|
|
59
|
-
)
|
|
60
|
-
```
|
|
114
|
+
## Using the Widget in ReactJS
|
|
115
|
+
|
|
116
|
+
### 3.1 Install the SDK
|
|
61
117
|
|
|
62
|
-
# Usage In REACTJS
|
|
63
|
-
## Install the SDK
|
|
64
118
|
```bash
|
|
65
119
|
yarn add @sawport/react-sdk
|
|
66
120
|
```
|
|
67
121
|
|
|
68
|
-
|
|
69
|
-
|
|
122
|
+
### 3.2 Configure the SDK (Global Config)
|
|
123
|
+
|
|
124
|
+
Wrap your app with `SawportContext.Provider`:
|
|
125
|
+
|
|
70
126
|
```jsx
|
|
71
127
|
import { SawportContext } from '@sawport/react-sdk';
|
|
72
128
|
|
|
73
129
|
<SawportContext.Provider
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
130
|
+
value={{
|
|
131
|
+
config: {
|
|
132
|
+
baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
|
|
133
|
+
apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
|
|
134
|
+
projectId: 'XXXXXXXXXXXXXX'
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<YourApp />
|
|
82
139
|
</SawportContext.Provider>
|
|
83
140
|
```
|
|
84
|
-
|
|
141
|
+
|
|
142
|
+
### 3.3 Using the Widget
|
|
143
|
+
|
|
85
144
|
```jsx
|
|
86
145
|
import { Widget } from '@sawport/react-sdk';
|
|
87
146
|
|
|
88
|
-
<Widget
|
|
147
|
+
<Widget
|
|
148
|
+
user={{
|
|
149
|
+
email: 'example@email.com',
|
|
150
|
+
mobile: '080XXXXXXXXX',
|
|
151
|
+
name: 'Firstname Lastname'
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
89
154
|
```
|
|
90
155
|
|
|
91
|
-
|
|
156
|
+
### 3.4 Updating Config at Runtime
|
|
157
|
+
|
|
92
158
|
```js
|
|
93
159
|
import { setSawportConfig } from '@sawport/react-sdk';
|
|
94
160
|
|
|
95
161
|
setSawportConfig({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
162
|
+
user: {
|
|
163
|
+
email: 'example@email.com',
|
|
164
|
+
mobile: '080XXXXXXXXX',
|
|
165
|
+
name: 'Firstname Lastname'
|
|
166
|
+
},
|
|
167
|
+
baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
|
|
168
|
+
apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
|
|
169
|
+
projectId: 'XXXXXXXXXXXXXX'
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Using the Widget in Vue.js
|
|
174
|
+
|
|
175
|
+
### 4.1 Install the SDK
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
yarn add @sawport/react-sdk
|
|
101
179
|
```
|
|
102
180
|
|
|
103
|
-
|
|
104
|
-
|
|
181
|
+
### 4.2 Create Widget Mounting Point
|
|
182
|
+
|
|
105
183
|
```html
|
|
106
|
-
|
|
107
|
-
<html lang="en">
|
|
108
|
-
<head>
|
|
109
|
-
<meta charset="UTF-8">
|
|
110
|
-
<link rel="icon" href="/favicon.ico">
|
|
111
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
112
|
-
<title>Vite App</title>
|
|
113
|
-
<!-- ADD SAWPORT SDK CSS -->
|
|
114
|
-
<link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
|
|
115
|
-
</head>
|
|
116
|
-
<body>
|
|
117
|
-
<div id="app"></div>
|
|
118
|
-
<!-- CREATE A DIV TO HOLD SAWPORT WIDGET -->
|
|
119
|
-
<div id="sawport-widget"></div>
|
|
120
|
-
<!-- ADD SAWPORT SDK JS -->
|
|
121
|
-
<script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
|
|
122
|
-
<script type="module" src="/src/main.js"></script>
|
|
123
|
-
</body>
|
|
124
|
-
</html>
|
|
184
|
+
<div id="sawport-widget"></div>
|
|
125
185
|
```
|
|
126
186
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
By pulling the Sawport SDK, `sawportSDK` variable would be exposed to your vuejs app globally.
|
|
187
|
+
### 4.3 Mount Widget From Vue App
|
|
188
|
+
|
|
130
189
|
```vue
|
|
131
190
|
<script setup>
|
|
191
|
+
import { onMounted } from 'vue'
|
|
192
|
+
import { mountWidget } from '@sawport/react-sdk'
|
|
132
193
|
import HelloWorld from './components/HelloWorld.vue'
|
|
194
|
+
// import the SDK css styling
|
|
195
|
+
import '@sawport/react-sdk/dist/react-sdk.css'
|
|
133
196
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/'
|
|
197
|
+
const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}'
|
|
137
198
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
199
|
+
onMounted(() => {
|
|
200
|
+
mountWidget({
|
|
201
|
+
baseURL: dashboardUrl,
|
|
202
|
+
apiURL: `${dashboardUrl}/api/v1/`,
|
|
203
|
+
projectId: 'XXXXXXXXXXXXXX',
|
|
204
|
+
user: {
|
|
205
|
+
email: 'example@email.com',
|
|
206
|
+
mobile: '2348123456789',
|
|
207
|
+
name: 'Firstname Lastname'
|
|
208
|
+
},
|
|
209
|
+
}, 'sawport-widget')
|
|
210
|
+
})
|
|
146
211
|
</script>
|
|
147
212
|
|
|
148
213
|
<template>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
<HelloWorld msg="You did it!" />
|
|
153
|
-
</div>
|
|
214
|
+
<div class="wrapper">
|
|
215
|
+
<HelloWorld msg="You did it!" />
|
|
216
|
+
</div>
|
|
154
217
|
</template>
|
|
155
218
|
```
|
|
156
219
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
###
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
-
|
|
179
|
-
|
|
180
|
-
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
###
|
|
187
|
-
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
##
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
|
|
198
|
-
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
React hook for Sawport Context for global configuration of the widget
|
|
202
|
-
### Type
|
|
203
|
-
- React Context Hook - Function()
|
|
204
|
-
### Return
|
|
205
|
-
- Sawport Context
|
|
206
|
-
- - [config](#sawportconfig)
|
|
207
|
-
- - [setConfig](#setsawportconfig)
|
|
208
|
-
|
|
209
|
-
## mountWidget
|
|
210
|
-
Method to mount the Sawport SDK widget in HTML element with id of `sawport-widget`
|
|
211
|
-
### Type
|
|
212
|
-
- Function(config)
|
|
213
|
-
### Props
|
|
214
|
-
- [config](#sawportconfig)
|
|
220
|
+
## API Reference: Sawport SDK
|
|
221
|
+
|
|
222
|
+
### 5.1 Widget Component
|
|
223
|
+
- React component for embedding the widget.
|
|
224
|
+
- Props:
|
|
225
|
+
- **user**: Customer information
|
|
226
|
+
- **projectId**: Enterprise ID
|
|
227
|
+
|
|
228
|
+
### 5.2 SawportContext
|
|
229
|
+
- Global configuration provider.
|
|
230
|
+
- Properties:
|
|
231
|
+
- **config**: Sawport configuration object
|
|
232
|
+
- **setConfig**: Update configuration
|
|
233
|
+
|
|
234
|
+
### 5.3 setSawportConfig
|
|
235
|
+
- Function for updating SDK config globally.
|
|
236
|
+
|
|
237
|
+
### 5.4 sawportConfig Object
|
|
238
|
+
- Fields:
|
|
239
|
+
- **user.name**: Customer name
|
|
240
|
+
- **user.mobile**: Customer phone number
|
|
241
|
+
- **user.email**: Customer email address
|
|
242
|
+
- **projectId**: Enterprise project ID
|
|
243
|
+
- **baseURL**: Dashboard domain
|
|
244
|
+
- **apiURL**: Dashboard API base
|
|
245
|
+
|
|
246
|
+
### 5.5 useSawportConfig
|
|
247
|
+
- React hook to access the config object.
|
|
248
|
+
|
|
249
|
+
### 5.6 useSawportContext
|
|
250
|
+
- Hook to retrieve both config and setConfig.
|
|
251
|
+
|
|
252
|
+
### 5.7 mountWidget
|
|
253
|
+
- Mounts SDK widget into a DOM element.
|
|
254
|
+
- Usage: `mountWidget(config, "sawport-widget")`
|
|
255
|
+
|
|
256
|
+
## Summary
|
|
257
|
+
|
|
258
|
+
This page provides a complete guide for integrating the Sawport Widget across:
|
|
259
|
+
- CDN-based web apps
|
|
260
|
+
- React apps
|
|
261
|
+
- Vue.js apps
|
|
262
|
+
|
|
263
|
+
It includes configuration references, usage patterns, and API documentation for all widget-related tools.
|