@@ -110,42 +110,9 @@ function App() {
110
110
111
111
## Embedding Methods
112
112
113
- ### 1. Data Attributes
113
+ ### 1. Custom Element (Recommended)
114
114
115
- The simplest way to embed the widget using HTML data attributes:
116
-
117
- ``` html
118
- <div
119
- data-client-widget =" VapiWidget"
120
- data-public-key =" pk_123"
121
- data-assistant-id =" asst_456"
122
- data-mode =" voice"
123
- data-theme =" dark"
124
- data-size =" compact"
125
- ></div >
126
- ```
127
-
128
- ### 2. JSON Props
129
-
130
- Pass complex configuration using JSON in the ` data-props ` attribute:
131
-
132
- ``` html
133
- <div
134
- data-client-widget =" VapiWidget"
135
- data-props =' {
136
- "publicKey": "pk_123",
137
- "assistantId": "asst_456",
138
- "mode": "hybrid",
139
- "theme": "light",
140
- "accentColor": "#3B82F6",
141
- "requireConsent": true
142
- }'
143
- ></div >
144
- ```
145
-
146
- ### 3. Custom Element
147
-
148
- Use the widget as a custom HTML element with kebab-case attributes:
115
+ Use the widget as a custom HTML element with kebab-case attributes - the cleanest and most modern approach:
149
116
150
117
``` html
151
118
<vapi-widget
@@ -158,23 +125,19 @@ Use the widget as a custom HTML element with kebab-case attributes:
158
125
></vapi-widget >
159
126
```
160
127
161
- ### 4. Programmatic
128
+ ### 2. Data Attributes
162
129
163
- Create widgets dynamically with JavaScript :
130
+ Use this approach if your environment doesn't support custom elements or for better compatibility with older systems :
164
131
165
132
``` html
166
- <div id =" my-widget" ></div >
167
- <script >
168
- new WidgetLoader ({
169
- container: ' #my-widget' ,
170
- component: ' VapiWidget' ,
171
- props: {
172
- publicKey: ' pk_123' ,
173
- vapiConfig: ' asst_456' ,
174
- mode: ' hybrid' ,
175
- },
176
- });
177
- </script >
133
+ <div
134
+ data-client-widget =" VapiWidget"
135
+ data-public-key =" pk_123"
136
+ data-assistant-id =" asst_456"
137
+ data-mode =" voice"
138
+ data-theme =" dark"
139
+ data-size =" compact"
140
+ ></div >
178
141
```
179
142
180
143
## Usage Examples
@@ -269,31 +232,6 @@ npm run dev
269
232
270
233
Visit < http://localhost:5173 > to see the example app.
271
234
272
- ## Project Structure
273
-
274
- ```
275
- @vapi-ai/client-sdk-react/
276
- ├── src/
277
- │ ├── components/ # React components
278
- │ │ ├── VapiWidget.tsx # Main widget component
279
- │ │ ├── AnimatedStatusIcon.tsx
280
- │ │ └── ConsentForm.tsx
281
- │ ├── hooks/ # Custom React hooks
282
- │ │ ├── useVapiWidget.ts
283
- │ │ ├── useVapiCall.ts
284
- │ │ └── useVapiChat.ts
285
- │ ├── widget/ # Widget loader for embedding
286
- │ │ └── index.ts # WidgetLoader class
287
- │ ├── styles/ # Global styles
288
- │ └── utils/ # Utility functions
289
- ├── example/ # Example application
290
- ├── dist/ # Built files
291
- │ ├── index.js # React library (ES)
292
- │ ├── index.cjs # React library (CommonJS)
293
- │ └── widget.umd.js # Embeddable widget
294
- └── docs/ # Documentation
295
- ```
296
-
297
235
## Browser Support
298
236
299
237
- Chrome/Edge 79+
@@ -307,10 +245,6 @@ Visit <http://localhost:5173> to see the example app.
307
245
- HTTPS required in production
308
246
- VAPI account and API key
309
247
310
- ## License
311
-
312
- ISC
313
-
314
248
## Contributing
315
249
316
250
1 . Fork the repository
0 commit comments