natureco-sdk 1.0.4 → 1.0.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.
Files changed (3) hide show
  1. package/README.md +608 -155
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,228 +1,548 @@
1
- # NatureCo JavaScript SDK
1
+ # NatureCo SDK
2
2
 
3
- Official JavaScript SDK for NatureCo API. Build powerful AI bots and integrate them with Discord, Telegram, Slack, and Instagram.
3
+ Official JavaScript SDK for NatureCo API - Build powerful AI chatbots and integrate them across multiple platforms.
4
4
 
5
- ## Installation
5
+ [![npm version](https://img.shields.io/npm/v/natureco-sdk.svg)](https://www.npmjs.com/package/natureco-sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## 📦 Installation
6
9
 
7
10
  ```bash
8
11
  npm install natureco-sdk
9
12
  ```
10
13
 
11
- ## Quick Start
14
+ Or using yarn:
15
+
16
+ ```bash
17
+ yarn add natureco-sdk
18
+ ```
19
+
20
+ For browser usage via CDN:
21
+
22
+ ```html
23
+ <script src="https://unpkg.com/natureco-sdk@latest/index.js"></script>
24
+ ```
25
+
26
+ ## 🚀 Quick Start
12
27
 
13
28
  ```javascript
14
29
  const { NatureCoClient } = require('natureco-sdk');
15
30
 
16
- // Initialize client
17
- const client = new NatureCoClient('nco_your_api_key_here');
31
+ // Initialize the client with your API key
32
+ const client = new NatureCoClient('nc_your_api_key_here');
18
33
 
19
- // Create a bot
34
+ // Create a new bot
20
35
  const bot = await client.bots.create({
21
36
  name: 'My First Bot',
22
- systemPrompt: 'You are a helpful assistant',
37
+ systemPrompt: 'You are a helpful assistant.',
23
38
  model: 'gpt-4'
24
39
  });
25
40
 
26
41
  console.log('Bot created:', bot);
27
42
  ```
28
43
 
29
- ## Modules
44
+ ## 🔑 Authentication
45
+
46
+ ### Getting Your API Key
47
+
48
+ 1. Go to [NatureCo Developers Portal](https://natureco.me/developers)
49
+ 2. Navigate to **API Keys** section
50
+ 3. Click **Generate New Key**
51
+ 4. Copy your API key (starts with `nc_` or `nco_`)
52
+
53
+ ### Initialize Client
54
+
55
+ ```javascript
56
+ const { NatureCoClient } = require('natureco-sdk');
57
+
58
+ const client = new NatureCoClient('nc_your_api_key_here', {
59
+ baseURL: 'https://api.natureco.me/api/v1', // Optional: custom API endpoint
60
+ timeout: 30000 // Optional: request timeout in ms (default: 30000)
61
+ });
62
+ ```
63
+
64
+ ## 🤖 Bot Management
65
+
66
+ ### Create a Bot
67
+
68
+ ```javascript
69
+ const bot = await client.bots.create({
70
+ name: 'Customer Support Bot',
71
+ systemPrompt: 'You are a friendly customer support assistant. Help users with their questions.',
72
+ model: 'gpt-4' // Options: 'gpt-4', 'gpt-3.5-turbo', 'claude-3'
73
+ });
30
74
 
31
- ### Bot Management
75
+ console.log('Bot ID:', bot.botId);
76
+ ```
77
+
78
+ ### List All Bots
32
79
 
33
80
  ```javascript
34
- // List all bots
35
81
  const bots = await client.bots.list();
36
82
 
37
- // Get bot details
38
- const bot = await client.bots.get('bot_id');
83
+ bots.forEach(bot => {
84
+ console.log(`${bot.name} (${bot.botId})`);
85
+ });
86
+ ```
87
+
88
+ ### Get Bot Details
89
+
90
+ ```javascript
91
+ const bot = await client.bots.get('bot_123456');
39
92
 
40
- // Update bot
41
- await client.bots.update('bot_id', {
42
- name: 'Updated Name',
43
- systemPrompt: 'New system prompt'
93
+ console.log('Bot name:', bot.name);
94
+ console.log('System prompt:', bot.systemPrompt);
95
+ console.log('Model:', bot.model);
96
+ ```
97
+
98
+ ### Update a Bot
99
+
100
+ ```javascript
101
+ const updatedBot = await client.bots.update('bot_123456', {
102
+ name: 'Updated Bot Name',
103
+ systemPrompt: 'New system prompt',
104
+ model: 'gpt-4'
44
105
  });
106
+ ```
45
107
 
46
- // Delete bot
47
- await client.bots.delete('bot_id');
108
+ ### Delete a Bot
109
+
110
+ ```javascript
111
+ await client.bots.delete('bot_123456');
112
+ console.log('Bot deleted successfully');
48
113
  ```
49
114
 
50
- ### Channel Integration
115
+ ## 📱 Channel Integration
116
+
117
+ Connect your bot to Discord, Telegram, Slack, Instagram, and more.
118
+
119
+ ### Connect Discord
51
120
 
52
121
  ```javascript
53
- // Connect Discord
54
- await client.channels.connect({
55
- botId: 'bot_id',
122
+ const channel = await client.channels.connect({
123
+ botId: 'bot_123456',
56
124
  platform: 'discord',
57
- token: 'discord_bot_token'
125
+ token: 'your_discord_bot_token',
126
+ config: {
127
+ guildId: 'your_guild_id', // Optional
128
+ commandPrefix: '!' // Optional
129
+ }
58
130
  });
131
+ ```
132
+
133
+ ### Connect Telegram
59
134
 
60
- // Connect Telegram
61
- await client.channels.connect({
62
- botId: 'bot_id',
135
+ ```javascript
136
+ const channel = await client.channels.connect({
137
+ botId: 'bot_123456',
63
138
  platform: 'telegram',
64
- token: 'telegram_bot_token'
139
+ token: 'your_telegram_bot_token'
65
140
  });
141
+ ```
66
142
 
67
- // List channels
68
- const channels = await client.channels.list('bot_id');
143
+ ### Connect Slack
144
+
145
+ ```javascript
146
+ const channel = await client.channels.connect({
147
+ botId: 'bot_123456',
148
+ platform: 'slack',
149
+ token: 'xoxb-your-slack-bot-token',
150
+ config: {
151
+ signingSecret: 'your_signing_secret'
152
+ }
153
+ });
154
+ ```
69
155
 
70
- // Disconnect channel
71
- await client.channels.disconnect('bot_id', 'channel_id');
156
+ ### Connect Instagram
72
157
 
73
- // Test channel connection
74
- await client.channels.test('bot_id', 'channel_id');
158
+ ```javascript
159
+ const channel = await client.channels.connect({
160
+ botId: 'bot_123456',
161
+ platform: 'instagram',
162
+ token: 'your_instagram_access_token',
163
+ config: {
164
+ pageId: 'your_page_id',
165
+ verifyToken: 'your_verify_token'
166
+ }
167
+ });
75
168
  ```
76
169
 
77
- ### Messaging
170
+ ### List Connected Channels
78
171
 
79
172
  ```javascript
80
- // Send message
81
- await client.messages.send({
82
- botId: 'bot_id',
83
- message: 'Hello, world!',
84
- channel: 'discord',
173
+ const channels = await client.channels.list('bot_123456');
174
+
175
+ channels.forEach(channel => {
176
+ console.log(`${channel.platform}: ${channel.isActive ? 'Active' : 'Inactive'}`);
177
+ });
178
+ ```
179
+
180
+ ### Disconnect a Channel
181
+
182
+ ```javascript
183
+ await client.channels.disconnect('bot_123456', 'channel_789');
184
+ console.log('Channel disconnected');
185
+ ```
186
+
187
+ ### Test Channel Connection
188
+
189
+ ```javascript
190
+ const result = await client.channels.test('bot_123456', 'channel_789');
191
+ console.log('Test result:', result.success ? 'Passed' : 'Failed');
192
+ ```
193
+
194
+ ## 💬 Messaging
195
+
196
+ ### Send a Message
197
+
198
+ ```javascript
199
+ const response = await client.messages.send({
200
+ botId: 'bot_123456',
201
+ message: 'Hello! How can I help you today?',
202
+ channel: 'web', // 'web', 'discord', 'telegram', etc.
85
203
  userId: 'user_123'
86
204
  });
87
205
 
88
- // Get message history
206
+ console.log('Bot response:', response.reply);
207
+ ```
208
+
209
+ ### Get Message History
210
+
211
+ ```javascript
89
212
  const messages = await client.messages.history({
90
- botId: 'bot_id',
213
+ botId: 'bot_123456',
91
214
  limit: 50,
92
215
  offset: 0
93
216
  });
94
217
 
95
- // Get specific message
96
- const message = await client.messages.get('bot_id', 'message_id');
218
+ messages.forEach(msg => {
219
+ console.log(`[${msg.timestamp}] ${msg.userId}: ${msg.message}`);
220
+ console.log(`Bot: ${msg.reply}`);
221
+ });
222
+ ```
223
+
224
+ ### Get Specific Message
225
+
226
+ ```javascript
227
+ const message = await client.messages.get('bot_123456', 'msg_789');
228
+ console.log('Message:', message);
97
229
  ```
98
230
 
99
- ### Webhooks
231
+ ## 🔔 Webhooks
232
+
233
+ Receive real-time notifications when events occur.
234
+
235
+ ### Create a Webhook
100
236
 
101
237
  ```javascript
102
- // Create webhook
103
238
  const webhook = await client.webhooks.create({
104
- botId: 'bot_id',
105
- url: 'https://your-server.com/webhook',
106
- events: ['message.received', 'message.sent'],
107
- secret: 'your_webhook_secret'
239
+ botId: 'bot_123456',
240
+ url: 'https://your-domain.com/webhook',
241
+ events: ['message.received', 'message.sent', 'bot.error'],
242
+ secret: 'your_webhook_secret' // Optional: for signature verification
108
243
  });
109
244
 
110
- // List webhooks
111
- const webhooks = await client.webhooks.list('bot_id');
245
+ console.log('Webhook ID:', webhook.id);
246
+ ```
247
+
248
+ ### Available Events
249
+
250
+ - `message.received` - New message received from user
251
+ - `message.sent` - Bot sent a message
252
+ - `bot.error` - Bot encountered an error
253
+ - `channel.connected` - New channel connected
254
+ - `channel.disconnected` - Channel disconnected
255
+ - `user.joined` - New user started conversation
256
+ - `analytics.daily` - Daily analytics summary
257
+
258
+ ### List Webhooks
112
259
 
113
- // Update webhook
114
- await client.webhooks.update('bot_id', 'webhook_id', {
115
- url: 'https://new-url.com/webhook',
260
+ ```javascript
261
+ const webhooks = await client.webhooks.list('bot_123456');
262
+
263
+ webhooks.forEach(webhook => {
264
+ console.log(`${webhook.url}: ${webhook.active ? 'Active' : 'Inactive'}`);
265
+ });
266
+ ```
267
+
268
+ ### Update Webhook
269
+
270
+ ```javascript
271
+ const updated = await client.webhooks.update('bot_123456', 'webhook_789', {
272
+ url: 'https://new-domain.com/webhook',
273
+ events: ['message.received'],
116
274
  active: true
117
275
  });
276
+ ```
277
+
278
+ ### Delete Webhook
118
279
 
119
- // Test webhook
120
- await client.webhooks.test('bot_id', 'webhook_id');
280
+ ```javascript
281
+ await client.webhooks.delete('bot_123456', 'webhook_789');
282
+ ```
121
283
 
122
- // Get webhook logs
123
- const logs = await client.webhooks.logs('bot_id', 'webhook_id', 20);
284
+ ### Test Webhook
124
285
 
125
- // Delete webhook
126
- await client.webhooks.delete('bot_id', 'webhook_id');
286
+ ```javascript
287
+ const result = await client.webhooks.test('bot_123456', 'webhook_789');
288
+ console.log('Test result:', result);
127
289
  ```
128
290
 
129
- ### Analytics
291
+ ### View Webhook Logs
130
292
 
131
293
  ```javascript
132
- // Get analytics overview
294
+ const logs = await client.webhooks.logs('bot_123456', 'webhook_789', 20);
295
+
296
+ logs.forEach(log => {
297
+ console.log(`[${log.timestamp}] ${log.event}: ${log.status}`);
298
+ });
299
+ ```
300
+
301
+ ### Webhook Payload Example
302
+
303
+ ```javascript
304
+ // Your webhook endpoint will receive:
305
+ {
306
+ "event": "message.received",
307
+ "timestamp": "2024-01-15T10:30:00Z",
308
+ "botId": "bot_123456",
309
+ "data": {
310
+ "messageId": "msg_789",
311
+ "userId": "user_123",
312
+ "message": "Hello bot!",
313
+ "channel": "discord",
314
+ "metadata": {
315
+ "username": "john_doe",
316
+ "channelId": "channel_456"
317
+ }
318
+ }
319
+ }
320
+ ```
321
+
322
+ ### Verify Webhook Signature
323
+
324
+ ```javascript
325
+ const crypto = require('crypto');
326
+
327
+ function verifyWebhookSignature(payload, signature, secret) {
328
+ const hmac = crypto.createHmac('sha256', secret);
329
+ const digest = hmac.update(JSON.stringify(payload)).digest('hex');
330
+ return signature === digest;
331
+ }
332
+
333
+ // In your webhook handler:
334
+ app.post('/webhook', (req, res) => {
335
+ const signature = req.headers['x-natureco-signature'];
336
+ const isValid = verifyWebhookSignature(req.body, signature, 'your_webhook_secret');
337
+
338
+ if (!isValid) {
339
+ return res.status(401).send('Invalid signature');
340
+ }
341
+
342
+ // Process webhook...
343
+ res.status(200).send('OK');
344
+ });
345
+ ```
346
+
347
+ ## 🎨 Web Widget
348
+
349
+ Embed a chat widget on your website.
350
+
351
+ ### Basic Embed
352
+
353
+ ```javascript
354
+ const embedCode = client.widget.getEmbedCode('bot_123456');
355
+ console.log(embedCode);
356
+ // Output: <script src="https://api.natureco.me/widget.js" data-bot-id="bot_123456" data-theme="light" data-position="bottom-right"></script>
357
+ ```
358
+
359
+ ### Custom Theme and Position
360
+
361
+ ```javascript
362
+ const embedCode = client.widget.getEmbedCode({
363
+ botId: 'bot_123456',
364
+ theme: 'dark', // 'light' or 'dark'
365
+ position: 'bottom-left' // 'bottom-right', 'bottom-left', 'top-right', 'top-left'
366
+ });
367
+ ```
368
+
369
+ ### HTML Integration
370
+
371
+ ```html
372
+ <!DOCTYPE html>
373
+ <html>
374
+ <head>
375
+ <title>My Website</title>
376
+ </head>
377
+ <body>
378
+ <h1>Welcome to my website</h1>
379
+
380
+ <!-- Add this before closing </body> tag -->
381
+ <script
382
+ src="https://api.natureco.me/widget.js"
383
+ data-bot-id="bot_123456"
384
+ data-theme="dark"
385
+ data-position="bottom-right"
386
+ data-welcome-message="Hi! How can I help you today?"
387
+ data-primary-color="#22c55e">
388
+ </script>
389
+ </body>
390
+ </html>
391
+ ```
392
+
393
+ ### Update Widget Settings
394
+
395
+ ```javascript
396
+ await client.widget.updateSettings({
397
+ botId: 'bot_123456',
398
+ theme: 'dark',
399
+ position: 'bottom-right',
400
+ welcomeMessage: 'Hello! How can I assist you?',
401
+ primaryColor: '#22c55e'
402
+ });
403
+ ```
404
+
405
+ ### Get Widget Settings
406
+
407
+ ```javascript
408
+ const settings = await client.widget.getSettings('bot_123456');
409
+ console.log('Widget settings:', settings);
410
+ ```
411
+
412
+ ### Widget Customization Options
413
+
414
+ ```html
415
+ <script
416
+ src="https://api.natureco.me/widget.js"
417
+ data-bot-id="bot_123456"
418
+ data-theme="dark"
419
+ data-position="bottom-right"
420
+ data-welcome-message="Hi there! 👋"
421
+ data-primary-color="#22c55e"
422
+ data-button-size="60"
423
+ data-window-width="400"
424
+ data-window-height="600"
425
+ data-z-index="9999">
426
+ </script>
427
+ ```
428
+
429
+ ## 📊 Analytics
430
+
431
+ ### Get Bot Analytics
432
+
433
+ ```javascript
434
+ // Get weekly analytics
133
435
  const analytics = await client.analytics.get({
134
- botId: 'bot_id',
436
+ botId: 'bot_123456',
135
437
  period: 'week' // 'day', 'week', or 'month'
136
438
  });
137
439
 
138
- // Get message analytics
139
- const messageStats = await client.analytics.messages('bot_id', {
140
- startDate: '2026-05-01',
141
- endDate: '2026-05-09'
440
+ console.log('Total messages:', analytics.totalMessages);
441
+ console.log('Active users:', analytics.activeUsers);
442
+ console.log('Average response time:', analytics.avgResponseTime);
443
+ ```
444
+
445
+ ### Message Analytics
446
+
447
+ ```javascript
448
+ const messageStats = await client.analytics.messages('bot_123456', {
449
+ startDate: '2024-01-01',
450
+ endDate: '2024-01-31'
142
451
  });
143
452
 
144
- // Get channel analytics
145
- const channelStats = await client.analytics.channels('bot_id');
453
+ console.log('Messages sent:', messageStats.sent);
454
+ console.log('Messages received:', messageStats.received);
455
+ ```
456
+
457
+ ### Channel Analytics
458
+
459
+ ```javascript
460
+ const channelStats = await client.analytics.channels('bot_123456');
461
+
462
+ channelStats.forEach(channel => {
463
+ console.log(`${channel.platform}: ${channel.messageCount} messages`);
464
+ });
465
+ ```
466
+
467
+ ### User Analytics
146
468
 
147
- // Get user analytics
148
- const userStats = await client.analytics.users('bot_id', { limit: 100 });
469
+ ```javascript
470
+ const users = await client.analytics.users('bot_123456', { limit: 100 });
471
+
472
+ users.forEach(user => {
473
+ console.log(`${user.userId}: ${user.messageCount} messages, last seen ${user.lastSeen}`);
474
+ });
149
475
  ```
150
476
 
151
- ### User Management
477
+ ## 👤 User Management
478
+
479
+ ### Get Current User
152
480
 
153
481
  ```javascript
154
- // Get current user
155
482
  const user = await client.user.me();
156
483
 
157
- // Update user profile
484
+ console.log('User ID:', user.id);
485
+ console.log('Display name:', user.displayName);
486
+ console.log('Email:', user.email);
487
+ ```
488
+
489
+ ### Update User Profile
490
+
491
+ ```javascript
158
492
  await client.user.update({
159
- displayName: 'New Name',
160
- bio: 'My bio',
161
- avatar: 'https://example.com/avatar.png'
493
+ displayName: 'John Doe',
494
+ bio: 'AI enthusiast and developer',
495
+ avatar: 'https://example.com/avatar.jpg'
162
496
  });
163
497
  ```
164
498
 
165
- ### API Key Management
499
+ ## 🔐 API Key Management
500
+
501
+ ### List API Keys
166
502
 
167
503
  ```javascript
168
- // List API keys
169
504
  const keys = await client.apiKeys.list();
170
505
 
171
- // Create new API key
172
- const newKey = await client.apiKeys.create({
173
- name: 'Production Key',
174
- scopes: ['bots:read', 'bots:write']
506
+ keys.forEach(key => {
507
+ console.log(`${key.name}: ${key.scopes.join(', ')}`);
175
508
  });
176
-
177
- // Revoke API key
178
- await client.apiKeys.revoke('key_id');
179
509
  ```
180
510
 
181
- ### Web Widget
511
+ ### Create New API Key
182
512
 
183
513
  ```javascript
184
- // Get embed code (simple usage)
185
- const embedCode = client.widget.getEmbedCode('bot_id');
186
-
187
- // Get embed code (with options)
188
- const embedCode = client.widget.getEmbedCode({
189
- botId: 'bot_id',
190
- theme: 'light', // 'light' or 'dark'
191
- position: 'bottom-right' // 'bottom-right', 'bottom-left', etc.
514
+ const newKey = await client.apiKeys.create({
515
+ name: 'Production Key',
516
+ scopes: ['bots:read', 'bots:write', 'messages:send']
192
517
  });
193
518
 
194
- // Or with separate parameters
195
- const embedCode = client.widget.getEmbedCode('bot_id', 'dark', 'bottom-left');
519
+ console.log('New API key:', newKey.key);
520
+ // IMPORTANT: Save this key securely, it won't be shown again!
521
+ ```
196
522
 
197
- // Update widget settings
198
- await client.widget.updateSettings({
199
- botId: 'bot_id',
200
- theme: 'dark',
201
- position: 'bottom-right',
202
- welcomeMessage: 'Hello! How can I help you?',
203
- primaryColor: '#10B981'
204
- });
523
+ ### Revoke API Key
205
524
 
206
- // Get widget settings
207
- const settings = await client.widget.getSettings('bot_id');
525
+ ```javascript
526
+ await client.apiKeys.revoke('key_123456');
527
+ console.log('API key revoked');
208
528
  ```
209
529
 
210
- ## Error Handling
530
+ ## 🛠️ Advanced Usage
531
+
532
+ ### Error Handling
211
533
 
212
534
  ```javascript
213
535
  const { NatureCoClient, NatureCoError } = require('natureco-sdk');
214
536
 
215
- const client = new NatureCoClient('nco_your_api_key');
216
-
217
537
  try {
218
538
  const bot = await client.bots.create({
219
- name: 'Test Bot',
220
- systemPrompt: 'You are helpful'
539
+ name: 'My Bot',
540
+ systemPrompt: 'You are helpful.'
221
541
  });
222
542
  } catch (error) {
223
543
  if (error instanceof NatureCoError) {
224
544
  console.error('API Error:', error.message);
225
- console.error('Status Code:', error.statusCode);
545
+ console.error('Status code:', error.statusCode);
226
546
  console.error('Response:', error.response);
227
547
  } else {
228
548
  console.error('Unexpected error:', error);
@@ -230,69 +550,202 @@ try {
230
550
  }
231
551
  ```
232
552
 
233
- ## Configuration Options
553
+ ### Custom Timeout
234
554
 
235
555
  ```javascript
236
- const client = new NatureCoClient('nco_your_api_key', {
237
- baseURL: 'https://api.natureco.me/api/v1', // Custom API base URL
238
- timeout: 30000 // Request timeout in milliseconds (default: 30000)
556
+ const client = new NatureCoClient('nc_your_api_key', {
557
+ timeout: 60000 // 60 seconds
239
558
  });
240
559
  ```
241
560
 
242
- ## TypeScript Support
561
+ ### Custom Base URL (Self-hosted)
243
562
 
244
- TypeScript definitions are included. Import types:
563
+ ```javascript
564
+ const client = new NatureCoClient('nc_your_api_key', {
565
+ baseURL: 'https://your-custom-domain.com/api/v1'
566
+ });
567
+ ```
245
568
 
246
- ```typescript
247
- import { NatureCoClient, NatureCoError } from 'natureco-sdk';
569
+ ### Retry Logic
248
570
 
249
- const client = new NatureCoClient('nco_your_api_key');
571
+ ```javascript
572
+ async function retryRequest(fn, maxRetries = 3) {
573
+ for (let i = 0; i < maxRetries; i++) {
574
+ try {
575
+ return await fn();
576
+ } catch (error) {
577
+ if (i === maxRetries - 1) throw error;
578
+ await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
579
+ }
580
+ }
581
+ }
250
582
 
251
- // TypeScript will provide autocomplete and type checking
252
- const bot = await client.bots.create({
253
- name: 'My Bot',
254
- systemPrompt: 'You are helpful',
255
- model: 'gpt-4'
256
- });
583
+ // Usage
584
+ const bot = await retryRequest(() =>
585
+ client.bots.create({
586
+ name: 'My Bot',
587
+ systemPrompt: 'You are helpful.'
588
+ })
589
+ );
257
590
  ```
258
591
 
259
- ## Browser Usage
260
-
261
- You can also use the SDK in the browser via CDN:
592
+ ## 🌐 Browser Usage
262
593
 
263
594
  ```html
264
- <script src="https://cdn.natureco.me/sdk/v1/natureco-sdk.min.js"></script>
265
- <script>
266
- const client = new NatureCoClient('nco_your_api_key');
267
-
268
- client.bots.list().then(bots => {
269
- console.log('Bots:', bots);
270
- });
271
- </script>
595
+ <!DOCTYPE html>
596
+ <html>
597
+ <head>
598
+ <title>NatureCo SDK Browser Example</title>
599
+ </head>
600
+ <body>
601
+ <h1>Chat with Bot</h1>
602
+ <input type="text" id="message" placeholder="Type a message...">
603
+ <button onclick="sendMessage()">Send</button>
604
+ <div id="response"></div>
605
+
606
+ <script src="https://unpkg.com/natureco-sdk@latest/index.js"></script>
607
+ <script>
608
+ const client = new NatureCoClient('nc_your_api_key');
609
+
610
+ async function sendMessage() {
611
+ const message = document.getElementById('message').value;
612
+
613
+ try {
614
+ const response = await client.messages.send({
615
+ botId: 'bot_123456',
616
+ message: message,
617
+ channel: 'web',
618
+ userId: 'user_' + Date.now()
619
+ });
620
+
621
+ document.getElementById('response').innerText = response.reply;
622
+ } catch (error) {
623
+ console.error('Error:', error);
624
+ }
625
+ }
626
+ </script>
627
+ </body>
628
+ </html>
272
629
  ```
273
630
 
274
- ## Rate Limiting
275
-
276
- The SDK automatically handles rate limiting. When you hit a rate limit, the API will return a `429` status code with a `X-RateLimit-Reset` header indicating when you can retry.
631
+ ## 📚 Complete Example
277
632
 
278
633
  ```javascript
279
- try {
280
- await client.bots.create({ name: 'Bot' });
281
- } catch (error) {
282
- if (error.statusCode === 429) {
283
- const resetTime = error.response.headers['X-RateLimit-Reset'];
284
- console.log('Rate limited. Retry after:', new Date(resetTime * 1000));
634
+ const { NatureCoClient } = require('natureco-sdk');
635
+
636
+ async function main() {
637
+ // Initialize client
638
+ const client = new NatureCoClient('nc_your_api_key');
639
+
640
+ try {
641
+ // Create a bot
642
+ const bot = await client.bots.create({
643
+ name: 'Customer Support Bot',
644
+ systemPrompt: 'You are a helpful customer support assistant.',
645
+ model: 'gpt-4'
646
+ });
647
+ console.log('✅ Bot created:', bot.botId);
648
+
649
+ // Connect to Discord
650
+ await client.channels.connect({
651
+ botId: bot.botId,
652
+ platform: 'discord',
653
+ token: process.env.DISCORD_TOKEN
654
+ });
655
+ console.log('✅ Discord connected');
656
+
657
+ // Create webhook
658
+ const webhook = await client.webhooks.create({
659
+ botId: bot.botId,
660
+ url: 'https://your-domain.com/webhook',
661
+ events: ['message.received', 'message.sent'],
662
+ secret: 'your_secret'
663
+ });
664
+ console.log('✅ Webhook created:', webhook.id);
665
+
666
+ // Get embed code for website
667
+ const embedCode = client.widget.getEmbedCode({
668
+ botId: bot.botId,
669
+ theme: 'dark',
670
+ position: 'bottom-right'
671
+ });
672
+ console.log('✅ Widget embed code:', embedCode);
673
+
674
+ // Send a test message
675
+ const response = await client.messages.send({
676
+ botId: bot.botId,
677
+ message: 'Hello! This is a test.',
678
+ channel: 'web',
679
+ userId: 'test_user'
680
+ });
681
+ console.log('✅ Bot response:', response.reply);
682
+
683
+ // Get analytics
684
+ const analytics = await client.analytics.get({
685
+ botId: bot.botId,
686
+ period: 'week'
687
+ });
688
+ console.log('✅ Analytics:', analytics);
689
+
690
+ } catch (error) {
691
+ console.error('❌ Error:', error.message);
285
692
  }
286
693
  }
694
+
695
+ main();
287
696
  ```
288
697
 
289
- ## Support
698
+ ## 🔗 Useful Links
699
+
700
+ - [Official Documentation](https://natureco.me/docs)
701
+ - [API Reference](https://natureco.me/docs/api)
702
+ - [Developers Portal](https://natureco.me/developers)
703
+ - [GitHub Repository](https://github.com/natureco/natureco-sdk)
704
+ - [Support](https://natureco.me/support)
705
+
706
+ ## 📄 License
707
+
708
+ MIT License - see [LICENSE](LICENSE) file for details
709
+
710
+ ## 🤝 Contributing
711
+
712
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
713
+
714
+ ## 💬 Support
290
715
 
291
- - Documentation: https://natureco.me/docs
292
- - SDK Documentation: https://natureco.me/docs/sdk
293
716
  - Email: support@natureco.me
294
- - Developers Portal: https://developers.natureco.me
717
+ - Discord: [Join our community](https://discord.gg/natureco)
718
+ - Twitter: [@natureco](https://twitter.com/natureco)
719
+
720
+ ## 📝 Changelog
721
+
722
+ ### v1.0.5 (Latest)
723
+ - Updated README with comprehensive examples
724
+ - Added webhook signature verification
725
+ - Improved error handling documentation
726
+ - Added browser usage examples
727
+
728
+ ### v1.0.4
729
+ - Added widget customization options
730
+ - Improved API key validation
731
+ - Bug fixes and performance improvements
732
+
733
+ ### v1.0.3
734
+ - Added analytics module
735
+ - Added user management
736
+ - Added API key management
737
+
738
+ ### v1.0.2
739
+ - Added webhook support
740
+ - Improved error handling
741
+ - Added timeout configuration
742
+
743
+ ### v1.0.1
744
+ - Initial release
745
+ - Bot management
746
+ - Channel integration
747
+ - Messaging support
295
748
 
296
- ## License
749
+ ---
297
750
 
298
- MIT License - see LICENSE file for details
751
+ Made with ❤️ by [NatureCo](https://natureco.me)
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * NatureCo JavaScript SDK
3
- * @version 1.0.4
3
+ * @version 1.0.5
4
4
  * @description Official JavaScript SDK for NatureCo API
5
5
  */
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Official JavaScript SDK for NatureCo API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",