ask-junkie 1.0.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 +864 -0
- package/dist/ask-junkie.css +485 -0
- package/dist/ask-junkie.esm.js +1847 -0
- package/dist/ask-junkie.esm.js.map +1 -0
- package/dist/ask-junkie.min.js +1858 -0
- package/dist/ask-junkie.min.js.map +1 -0
- package/dist/junkie-icon.png +0 -0
- package/package.json +43 -0
- package/src/ai/AIProviderFactory.js +43 -0
- package/src/ai/BaseProvider.js +68 -0
- package/src/ai/GeminiProvider.js +58 -0
- package/src/ai/GroqProvider.js +51 -0
- package/src/ai/OpenAIProvider.js +51 -0
- package/src/ai/OpenRouterProvider.js +53 -0
- package/src/analytics/FirebaseLogger.js +115 -0
- package/src/core/AskJunkie.js +585 -0
- package/src/core/EventEmitter.js +52 -0
- package/src/index.js +19 -0
- package/src/ui/ChatWidget.js +611 -0
- package/src/ui/styles.css +485 -0
- package/src/utils/DOMUtils.js +69 -0
- package/src/utils/StorageManager.js +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
# Ask Junkie SDK
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
**Add an AI-powered chatbot to any website in minutes**
|
|
11
|
+
|
|
12
|
+
[Installation](#-installation) • [Quick Start](#-quick-start) • [Dashboard Setup](#-dashboard-setup) • [Framework Guides](#-framework-integration-guides) • [API](#-api-methods)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## ✨ Features
|
|
19
|
+
|
|
20
|
+
- 🔑 **SDK Key Authentication** - Manage all settings from a centralized dashboard
|
|
21
|
+
- 🤖 **Multi-Provider AI** - Supports Groq (fastest), OpenAI, Google Gemini, and OpenRouter
|
|
22
|
+
- ⚡ **Universal Compatibility** - Works with React, Next.js, Vue, Angular, Svelte, or plain HTML
|
|
23
|
+
- 🎨 **Customizable** - 7 color presets, custom themes, and full CSS control
|
|
24
|
+
- 💬 **Smart Context** - Teach the AI about your website with custom context
|
|
25
|
+
- 🎤 **Voice Input** - Built-in speech recognition support
|
|
26
|
+
- 📊 **Analytics Dashboard** - View all chat conversations in one place
|
|
27
|
+
- 📱 **Responsive** - Works on all screen sizes
|
|
28
|
+
- 🖱️ **Draggable** - Users can move the chat icon anywhere
|
|
29
|
+
- 💾 **Persistent** - Chat history saved to localStorage
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🆕 What's New in v1.1.6
|
|
34
|
+
|
|
35
|
+
- **SDK Key Authentication** - Use a single SDK key to manage all settings from the dashboard
|
|
36
|
+
- **Centralized Settings** - Change bot name, colors, AI provider, and context without code changes
|
|
37
|
+
- **Chat Analytics** - All conversations are logged and viewable in the Super Admin Panel
|
|
38
|
+
- **Multi-site Management** - Manage multiple websites from one dashboard
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 📦 Installation
|
|
43
|
+
|
|
44
|
+
### Option 1: npm (Recommended for frameworks)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install ask-junkie-sdk
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Option 2: CDN (Quick integration)
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<!-- CSS -->
|
|
54
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.css">
|
|
55
|
+
|
|
56
|
+
<!-- JavaScript -->
|
|
57
|
+
<script src="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.min.js"></script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Option 3: unpkg CDN
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<link rel="stylesheet" href="https://unpkg.com/ask-junkie-sdk@latest/dist/ask-junkie.css">
|
|
64
|
+
<script src="https://unpkg.com/ask-junkie-sdk@latest/dist/ask-junkie.min.js"></script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 🎯 Dashboard Setup
|
|
70
|
+
|
|
71
|
+
### Step 1: Create an Account
|
|
72
|
+
|
|
73
|
+
1. Go to the **Ask Junkie Dashboard** at `https://http://ai.junkiescoder.com`
|
|
74
|
+
2. Sign up with Google or Email
|
|
75
|
+
3. Navigate to **API Keys** section
|
|
76
|
+
|
|
77
|
+
### Step 2: Create an SDK Key
|
|
78
|
+
|
|
79
|
+
1. Click **"+ Create New Key"**
|
|
80
|
+
2. Enter a **Name** (e.g., "My Website")
|
|
81
|
+
3. Enter your **Domain** (e.g., "mywebsite.com")
|
|
82
|
+
4. Click **"Create Key"**
|
|
83
|
+
5. Copy the generated SDK key (starts with `ak_...`)
|
|
84
|
+
|
|
85
|
+
### Step 3: Configure Settings
|
|
86
|
+
|
|
87
|
+
1. Go to **Settings** in the dashboard
|
|
88
|
+
2. Configure:
|
|
89
|
+
- **Bot Name** - The name shown in the chat header
|
|
90
|
+
- **AI Provider** - Choose Groq, OpenAI, Gemini, etc.
|
|
91
|
+
- **AI API Key** - Your AI provider's API key
|
|
92
|
+
- **Theme** - Choose colors and gradient presets
|
|
93
|
+
- **Context** - Add information about your business
|
|
94
|
+
3. Click **Save** - Changes apply instantly to all sites using this SDK key!
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 🚀 Quick Start
|
|
99
|
+
|
|
100
|
+
### Minimal Setup (with SDK Key)
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
104
|
+
import 'ask-junkie-sdk/dist/ask-junkie.css';
|
|
105
|
+
|
|
106
|
+
AskJunkie.init({
|
|
107
|
+
sdkKey: 'ak_your_sdk_key_here'
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
That's it! All settings are loaded from the dashboard.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 🖼️ Framework Integration Guides
|
|
116
|
+
|
|
117
|
+
### 📌 HTML/CSS/JavaScript (Vanilla)
|
|
118
|
+
|
|
119
|
+
The simplest way to add the chatbot to any static website.
|
|
120
|
+
|
|
121
|
+
**Method 1: CDN (Recommended)**
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<!DOCTYPE html>
|
|
125
|
+
<html lang="en">
|
|
126
|
+
<head>
|
|
127
|
+
<meta charset="UTF-8">
|
|
128
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
129
|
+
<title>My Website</title>
|
|
130
|
+
|
|
131
|
+
<!-- Ask Junkie CSS -->
|
|
132
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.css">
|
|
133
|
+
</head>
|
|
134
|
+
<body>
|
|
135
|
+
<h1>Welcome to My Website</h1>
|
|
136
|
+
<p>Your content here...</p>
|
|
137
|
+
|
|
138
|
+
<!-- Ask Junkie JavaScript -->
|
|
139
|
+
<script src="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.min.js"></script>
|
|
140
|
+
<script>
|
|
141
|
+
// Initialize with just your SDK key
|
|
142
|
+
AskJunkie.init({
|
|
143
|
+
sdkKey: 'ak_your_sdk_key_here'
|
|
144
|
+
});
|
|
145
|
+
</script>
|
|
146
|
+
</body>
|
|
147
|
+
</html>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Method 2: Downloaded Files**
|
|
151
|
+
|
|
152
|
+
1. Download the SDK files from npm or CDN
|
|
153
|
+
2. Place them in your project:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
your-website/
|
|
157
|
+
├── css/
|
|
158
|
+
│ └── ask-junkie.css
|
|
159
|
+
├── js/
|
|
160
|
+
│ └── ask-junkie.min.js
|
|
161
|
+
└── index.html
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```html
|
|
165
|
+
<!DOCTYPE html>
|
|
166
|
+
<html>
|
|
167
|
+
<head>
|
|
168
|
+
<link rel="stylesheet" href="css/ask-junkie.css">
|
|
169
|
+
</head>
|
|
170
|
+
<body>
|
|
171
|
+
<h1>My Website</h1>
|
|
172
|
+
|
|
173
|
+
<script src="js/ask-junkie.min.js"></script>
|
|
174
|
+
<script>
|
|
175
|
+
AskJunkie.init({
|
|
176
|
+
sdkKey: 'ak_your_sdk_key_here'
|
|
177
|
+
});
|
|
178
|
+
</script>
|
|
179
|
+
</body>
|
|
180
|
+
</html>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### ⚛️ React
|
|
186
|
+
|
|
187
|
+
**Step 1: Install the package**
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npm install ask-junkie-sdk
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Step 2: Create a Chatbot component**
|
|
194
|
+
|
|
195
|
+
```jsx
|
|
196
|
+
// src/components/AskJunkieChatbot.jsx
|
|
197
|
+
import { useEffect } from 'react';
|
|
198
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
199
|
+
import 'ask-junkie-sdk/dist/ask-junkie.css';
|
|
200
|
+
|
|
201
|
+
function AskJunkieChatbot() {
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
// Initialize with SDK key - all settings from dashboard
|
|
204
|
+
AskJunkie.init({
|
|
205
|
+
sdkKey: process.env.REACT_APP_SDK_KEY
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Cleanup on unmount
|
|
209
|
+
return () => {
|
|
210
|
+
AskJunkie.destroy();
|
|
211
|
+
};
|
|
212
|
+
}, []);
|
|
213
|
+
|
|
214
|
+
return null; // This component renders the chat widget via DOM
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default AskJunkieChatbot;
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Step 3: Add to your App**
|
|
221
|
+
|
|
222
|
+
```jsx
|
|
223
|
+
// src/App.jsx
|
|
224
|
+
import AskJunkieChatbot from './components/AskJunkieChatbot';
|
|
225
|
+
|
|
226
|
+
function App() {
|
|
227
|
+
return (
|
|
228
|
+
<div className="App">
|
|
229
|
+
<h1>My React App</h1>
|
|
230
|
+
<p>Your content here...</p>
|
|
231
|
+
|
|
232
|
+
{/* Chatbot will appear as a floating widget */}
|
|
233
|
+
<AskJunkieChatbot />
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default App;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Step 4: Add environment variable**
|
|
242
|
+
|
|
243
|
+
Create `.env` file:
|
|
244
|
+
```env
|
|
245
|
+
REACT_APP_SDK_KEY=ak_your_sdk_key_here
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### ▲ Next.js (App Router)
|
|
251
|
+
|
|
252
|
+
**Step 1: Install the package**
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
npm install ask-junkie-sdk
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Step 2: Create a client component**
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
// src/components/AskJunkieChatbot.tsx
|
|
262
|
+
'use client';
|
|
263
|
+
|
|
264
|
+
import { useEffect } from 'react';
|
|
265
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
266
|
+
import 'ask-junkie-sdk/dist/ask-junkie.css';
|
|
267
|
+
|
|
268
|
+
export default function AskJunkieChatbot() {
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
// ============================================
|
|
271
|
+
// SDK KEY AUTHENTICATION
|
|
272
|
+
// All settings (bot name, API key, theme, etc.)
|
|
273
|
+
// are managed from the dashboard Settings page
|
|
274
|
+
// ============================================
|
|
275
|
+
AskJunkie.init({
|
|
276
|
+
sdkKey: process.env.NEXT_PUBLIC_SDK_KEY!
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return () => {
|
|
280
|
+
AskJunkie.destroy();
|
|
281
|
+
};
|
|
282
|
+
}, []);
|
|
283
|
+
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**Step 3: Add to layout**
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
// src/app/layout.tsx
|
|
292
|
+
import AskJunkieChatbot from '@/components/AskJunkieChatbot';
|
|
293
|
+
|
|
294
|
+
export default function RootLayout({
|
|
295
|
+
children,
|
|
296
|
+
}: {
|
|
297
|
+
children: React.ReactNode;
|
|
298
|
+
}) {
|
|
299
|
+
return (
|
|
300
|
+
<html lang="en">
|
|
301
|
+
<body>
|
|
302
|
+
{children}
|
|
303
|
+
<AskJunkieChatbot />
|
|
304
|
+
</body>
|
|
305
|
+
</html>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Step 4: Add environment variable**
|
|
311
|
+
|
|
312
|
+
Create `.env.local` file:
|
|
313
|
+
```env
|
|
314
|
+
NEXT_PUBLIC_SDK_KEY=ak_your_sdk_key_here
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
**Step 5: Add TypeScript declaration (optional)**
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
// src/types/ask-junkie-sdk.d.ts
|
|
321
|
+
declare module 'ask-junkie-sdk' {
|
|
322
|
+
interface AskJunkieConfig {
|
|
323
|
+
sdkKey?: string;
|
|
324
|
+
apiKey?: string;
|
|
325
|
+
provider?: 'groq' | 'gemini' | 'openai' | 'openrouter';
|
|
326
|
+
botName?: string;
|
|
327
|
+
theme?: object;
|
|
328
|
+
context?: object;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface AskJunkieStatic {
|
|
332
|
+
init(config: AskJunkieConfig): void;
|
|
333
|
+
destroy(): void;
|
|
334
|
+
open(): void;
|
|
335
|
+
close(): void;
|
|
336
|
+
toggle(): void;
|
|
337
|
+
sendMessage(message: string): void;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const AskJunkie: AskJunkieStatic;
|
|
341
|
+
export default AskJunkie;
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
### ▲ Next.js (Pages Router)
|
|
348
|
+
|
|
349
|
+
```tsx
|
|
350
|
+
// pages/_app.tsx
|
|
351
|
+
import type { AppProps } from 'next/app';
|
|
352
|
+
import { useEffect } from 'react';
|
|
353
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
354
|
+
import 'ask-junkie-sdk/dist/ask-junkie.css';
|
|
355
|
+
|
|
356
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
357
|
+
useEffect(() => {
|
|
358
|
+
AskJunkie.init({
|
|
359
|
+
sdkKey: process.env.NEXT_PUBLIC_SDK_KEY!
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return () => AskJunkie.destroy();
|
|
363
|
+
}, []);
|
|
364
|
+
|
|
365
|
+
return <Component {...pageProps} />;
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
### 💚 Vue 3
|
|
372
|
+
|
|
373
|
+
**Step 1: Install the package**
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
npm install ask-junkie-sdk
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Step 2: Create a composable or component**
|
|
380
|
+
|
|
381
|
+
```vue
|
|
382
|
+
<!-- src/components/AskJunkieChatbot.vue -->
|
|
383
|
+
<script setup lang="ts">
|
|
384
|
+
import { onMounted, onUnmounted } from 'vue';
|
|
385
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
386
|
+
import 'ask-junkie-sdk/dist/ask-junkie.css';
|
|
387
|
+
|
|
388
|
+
onMounted(() => {
|
|
389
|
+
AskJunkie.init({
|
|
390
|
+
sdkKey: import.meta.env.VITE_SDK_KEY
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
onUnmounted(() => {
|
|
395
|
+
AskJunkie.destroy();
|
|
396
|
+
});
|
|
397
|
+
</script>
|
|
398
|
+
|
|
399
|
+
<template>
|
|
400
|
+
<!-- This component renders nothing, the widget is injected into the DOM -->
|
|
401
|
+
</template>
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**Step 3: Add to App.vue**
|
|
405
|
+
|
|
406
|
+
```vue
|
|
407
|
+
<!-- src/App.vue -->
|
|
408
|
+
<script setup>
|
|
409
|
+
import AskJunkieChatbot from './components/AskJunkieChatbot.vue';
|
|
410
|
+
</script>
|
|
411
|
+
|
|
412
|
+
<template>
|
|
413
|
+
<div id="app">
|
|
414
|
+
<h1>My Vue App</h1>
|
|
415
|
+
<AskJunkieChatbot />
|
|
416
|
+
</div>
|
|
417
|
+
</template>
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Step 4: Add environment variable**
|
|
421
|
+
|
|
422
|
+
Create `.env` file:
|
|
423
|
+
```env
|
|
424
|
+
VITE_SDK_KEY=ak_your_sdk_key_here
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
### 🅰️ Angular
|
|
430
|
+
|
|
431
|
+
**Step 1: Install the package**
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
npm install ask-junkie-sdk
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**Step 2: Add CSS to angular.json**
|
|
438
|
+
|
|
439
|
+
```json
|
|
440
|
+
{
|
|
441
|
+
"projects": {
|
|
442
|
+
"your-app": {
|
|
443
|
+
"architect": {
|
|
444
|
+
"build": {
|
|
445
|
+
"options": {
|
|
446
|
+
"styles": [
|
|
447
|
+
"node_modules/ask-junkie-sdk/dist/ask-junkie.css",
|
|
448
|
+
"src/styles.css"
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
**Step 3: Create a service or component**
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
// src/app/ask-junkie.component.ts
|
|
462
|
+
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
463
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
464
|
+
import { environment } from '../environments/environment';
|
|
465
|
+
|
|
466
|
+
@Component({
|
|
467
|
+
selector: 'app-ask-junkie',
|
|
468
|
+
template: '',
|
|
469
|
+
standalone: true
|
|
470
|
+
})
|
|
471
|
+
export class AskJunkieComponent implements OnInit, OnDestroy {
|
|
472
|
+
ngOnInit(): void {
|
|
473
|
+
AskJunkie.init({
|
|
474
|
+
sdkKey: environment.sdkKey
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
ngOnDestroy(): void {
|
|
479
|
+
AskJunkie.destroy();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**Step 4: Add to app.component.ts**
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
// src/app/app.component.ts
|
|
488
|
+
import { Component } from '@angular/core';
|
|
489
|
+
import { AskJunkieComponent } from './ask-junkie.component';
|
|
490
|
+
|
|
491
|
+
@Component({
|
|
492
|
+
selector: 'app-root',
|
|
493
|
+
standalone: true,
|
|
494
|
+
imports: [AskJunkieComponent],
|
|
495
|
+
template: `
|
|
496
|
+
<h1>My Angular App</h1>
|
|
497
|
+
<app-ask-junkie />
|
|
498
|
+
`
|
|
499
|
+
})
|
|
500
|
+
export class AppComponent {}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
**Step 5: Add environment variable**
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
// src/environments/environment.ts
|
|
507
|
+
export const environment = {
|
|
508
|
+
sdkKey: 'ak_your_sdk_key_here'
|
|
509
|
+
};
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
### 🧡 Svelte
|
|
515
|
+
|
|
516
|
+
**Step 1: Install the package**
|
|
517
|
+
|
|
518
|
+
```bash
|
|
519
|
+
npm install ask-junkie-sdk
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
**Step 2: Create a component**
|
|
523
|
+
|
|
524
|
+
```svelte
|
|
525
|
+
<!-- src/lib/AskJunkieChatbot.svelte -->
|
|
526
|
+
<script>
|
|
527
|
+
import { onMount, onDestroy } from 'svelte';
|
|
528
|
+
import AskJunkie from 'ask-junkie-sdk';
|
|
529
|
+
import 'ask-junkie-sdk/dist/ask-junkie.css';
|
|
530
|
+
|
|
531
|
+
onMount(() => {
|
|
532
|
+
AskJunkie.init({
|
|
533
|
+
sdkKey: import.meta.env.VITE_SDK_KEY
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
onDestroy(() => {
|
|
538
|
+
AskJunkie.destroy();
|
|
539
|
+
});
|
|
540
|
+
</script>
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
**Step 3: Add to your app**
|
|
544
|
+
|
|
545
|
+
```svelte
|
|
546
|
+
<!-- src/App.svelte -->
|
|
547
|
+
<script>
|
|
548
|
+
import AskJunkieChatbot from './lib/AskJunkieChatbot.svelte';
|
|
549
|
+
</script>
|
|
550
|
+
|
|
551
|
+
<main>
|
|
552
|
+
<h1>My Svelte App</h1>
|
|
553
|
+
<AskJunkieChatbot />
|
|
554
|
+
</main>
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
---
|
|
558
|
+
|
|
559
|
+
### 🟢 Node.js / Express (Server-Rendered Pages)
|
|
560
|
+
|
|
561
|
+
For server-rendered pages, inject the CDN scripts into your HTML templates:
|
|
562
|
+
|
|
563
|
+
```javascript
|
|
564
|
+
// server.js
|
|
565
|
+
const express = require('express');
|
|
566
|
+
const app = express();
|
|
567
|
+
|
|
568
|
+
app.get('/', (req, res) => {
|
|
569
|
+
res.send(`
|
|
570
|
+
<!DOCTYPE html>
|
|
571
|
+
<html>
|
|
572
|
+
<head>
|
|
573
|
+
<title>My Express App</title>
|
|
574
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.css">
|
|
575
|
+
</head>
|
|
576
|
+
<body>
|
|
577
|
+
<h1>Welcome to My Express App</h1>
|
|
578
|
+
|
|
579
|
+
<script src="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.min.js"></script>
|
|
580
|
+
<script>
|
|
581
|
+
AskJunkie.init({
|
|
582
|
+
sdkKey: '${process.env.SDK_KEY}'
|
|
583
|
+
});
|
|
584
|
+
</script>
|
|
585
|
+
</body>
|
|
586
|
+
</html>
|
|
587
|
+
`);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
app.listen(3000);
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
### 🎨 WordPress
|
|
596
|
+
|
|
597
|
+
For WordPress sites, add this to your theme's `footer.php`:
|
|
598
|
+
|
|
599
|
+
```php
|
|
600
|
+
<!-- Ask Junkie Chatbot -->
|
|
601
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.css">
|
|
602
|
+
<script src="https://cdn.jsdelivr.net/npm/ask-junkie-sdk@latest/dist/ask-junkie.min.js"></script>
|
|
603
|
+
<script>
|
|
604
|
+
AskJunkie.init({
|
|
605
|
+
sdkKey: '<?php echo esc_js(get_option("ask_junkie_sdk_key")); ?>'
|
|
606
|
+
});
|
|
607
|
+
</script>
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
Or use the **Ask Junkie WordPress Plugin** for easier integration.
|
|
611
|
+
|
|
612
|
+
---
|
|
613
|
+
|
|
614
|
+
### 📱 React Native / Mobile
|
|
615
|
+
|
|
616
|
+
The SDK is designed for web browsers. For React Native apps, you can:
|
|
617
|
+
|
|
618
|
+
1. Use a **WebView** to display a web page with the chatbot
|
|
619
|
+
2. Build a custom chat UI and use the AI providers directly
|
|
620
|
+
|
|
621
|
+
---
|
|
622
|
+
|
|
623
|
+
## ⚙️ Configuration Options
|
|
624
|
+
|
|
625
|
+
### Using SDK Key (Recommended)
|
|
626
|
+
|
|
627
|
+
```javascript
|
|
628
|
+
AskJunkie.init({
|
|
629
|
+
sdkKey: 'ak_your_sdk_key_here'
|
|
630
|
+
});
|
|
631
|
+
// All settings loaded from dashboard!
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
### Using Direct Configuration (Legacy)
|
|
635
|
+
|
|
636
|
+
```javascript
|
|
637
|
+
AskJunkie.init({
|
|
638
|
+
// ═══════════════════════════════════════════════════════════
|
|
639
|
+
// REQUIRED
|
|
640
|
+
// ═══════════════════════════════════════════════════════════
|
|
641
|
+
apiKey: 'gsk_xxx...', // Your AI provider API key
|
|
642
|
+
|
|
643
|
+
// ═══════════════════════════════════════════════════════════
|
|
644
|
+
// AI PROVIDER SETTINGS
|
|
645
|
+
// ═══════════════════════════════════════════════════════════
|
|
646
|
+
provider: 'groq', // 'groq' | 'gemini' | 'openai' | 'openrouter'
|
|
647
|
+
model: null, // Optional: Override default model
|
|
648
|
+
|
|
649
|
+
// ═══════════════════════════════════════════════════════════
|
|
650
|
+
// APPEARANCE
|
|
651
|
+
// ═══════════════════════════════════════════════════════════
|
|
652
|
+
botName: 'AI Assistant',
|
|
653
|
+
botAvatar: null, // URL to custom avatar image
|
|
654
|
+
welcomeMessage: "Hi! 👋 I'm your AI assistant. How can I help you today?",
|
|
655
|
+
position: 'bottom-right', // 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
|
|
656
|
+
|
|
657
|
+
theme: {
|
|
658
|
+
mode: 'gradient', // 'gradient' | 'solid'
|
|
659
|
+
preset: 1, // 1-7 for preset gradients
|
|
660
|
+
primary: '#6366f1', // Primary color (purple)
|
|
661
|
+
secondary: '#ec4899' // Secondary color (pink)
|
|
662
|
+
},
|
|
663
|
+
|
|
664
|
+
// ═══════════════════════════════════════════════════════════
|
|
665
|
+
// BEHAVIOR
|
|
666
|
+
// ═══════════════════════════════════════════════════════════
|
|
667
|
+
draggable: false, // Allow users to drag the toggle button
|
|
668
|
+
persistChat: true, // Save chat history to localStorage
|
|
669
|
+
voiceInput: true, // Enable microphone button
|
|
670
|
+
openOnLoad: false, // Auto-open chat when page loads
|
|
671
|
+
|
|
672
|
+
suggestions: [ // Quick reply buttons
|
|
673
|
+
'Contact us',
|
|
674
|
+
'Pricing',
|
|
675
|
+
'Help'
|
|
676
|
+
],
|
|
677
|
+
|
|
678
|
+
// ═══════════════════════════════════════════════════════════
|
|
679
|
+
// AI CONTEXT (Teach the AI about your website)
|
|
680
|
+
// ═══════════════════════════════════════════════════════════
|
|
681
|
+
context: {
|
|
682
|
+
siteName: 'My Website',
|
|
683
|
+
siteDescription: 'We are a software company that builds amazing products',
|
|
684
|
+
customInfo: `
|
|
685
|
+
- Business hours: 9 AM - 5 PM EST
|
|
686
|
+
- Support email: help@example.com
|
|
687
|
+
- We offer free trials for all plans
|
|
688
|
+
`,
|
|
689
|
+
restrictions: 'Do not discuss competitor pricing'
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
// ═══════════════════════════════════════════════════════════
|
|
693
|
+
// ANALYTICS
|
|
694
|
+
// ═══════════════════════════════════════════════════════════
|
|
695
|
+
analytics: {
|
|
696
|
+
enabled: true // Log chats to Firebase for analytics
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
---
|
|
702
|
+
|
|
703
|
+
## 🎨 Theme Presets
|
|
704
|
+
|
|
705
|
+
| Preset | Colors | Description |
|
|
706
|
+
|--------|--------|-------------|
|
|
707
|
+
| 1 | 🟣→🔴 | Purple to Pink (Default) |
|
|
708
|
+
| 2 | 🔵→🔵 | Blue to Cyan |
|
|
709
|
+
| 3 | 🟢→🟢 | Green to Teal |
|
|
710
|
+
| 4 | 🟠→🔴 | Orange to Red |
|
|
711
|
+
| 5 | 🟣→🔵 | Violet to Blue |
|
|
712
|
+
| 6 | 🟡→🔴 | Yellow to Red (Sunset) |
|
|
713
|
+
| 7 | 🔵→🟢 | Blue to Green (Ocean) |
|
|
714
|
+
|
|
715
|
+
---
|
|
716
|
+
|
|
717
|
+
## 🤖 AI Providers
|
|
718
|
+
|
|
719
|
+
| Provider | Default Model | Get API Key | Notes |
|
|
720
|
+
|----------|---------------|-------------|-------|
|
|
721
|
+
| **Groq** | `llama-3.3-70b-versatile` | [console.groq.com](https://console.groq.com) | ⚡ Fastest, Free tier |
|
|
722
|
+
| **Google Gemini** | `gemini-1.5-flash` | [aistudio.google.com](https://aistudio.google.com/apikey) | Free tier |
|
|
723
|
+
| **OpenAI** | `gpt-3.5-turbo` | [platform.openai.com](https://platform.openai.com/api-keys) | Most popular |
|
|
724
|
+
| **OpenRouter** | `meta-llama/llama-3-8b-instruct` | [openrouter.ai](https://openrouter.ai/keys) | Multi-model |
|
|
725
|
+
|
|
726
|
+
---
|
|
727
|
+
|
|
728
|
+
## 🎮 API Methods
|
|
729
|
+
|
|
730
|
+
```javascript
|
|
731
|
+
// Open the chat window
|
|
732
|
+
AskJunkie.open();
|
|
733
|
+
|
|
734
|
+
// Close the chat window
|
|
735
|
+
AskJunkie.close();
|
|
736
|
+
|
|
737
|
+
// Toggle chat open/closed
|
|
738
|
+
AskJunkie.toggle();
|
|
739
|
+
|
|
740
|
+
// Send a message programmatically
|
|
741
|
+
AskJunkie.sendMessage('Hello, I need help!');
|
|
742
|
+
|
|
743
|
+
// Update AI context dynamically
|
|
744
|
+
AskJunkie.setContext({
|
|
745
|
+
customInfo: 'New information for the AI'
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// Listen to events
|
|
749
|
+
AskJunkie.on('message', (data) => {
|
|
750
|
+
console.log('Message:', data);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
// Clean up and remove widget
|
|
754
|
+
AskJunkie.destroy();
|
|
755
|
+
|
|
756
|
+
// Get SDK version
|
|
757
|
+
console.log(AskJunkie.getVersion()); // "1.1.6"
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
---
|
|
761
|
+
|
|
762
|
+
## 🎨 Custom Styling
|
|
763
|
+
|
|
764
|
+
Override default styles with CSS:
|
|
765
|
+
|
|
766
|
+
```css
|
|
767
|
+
/* Custom toggle button */
|
|
768
|
+
.ask-junkie-toggle {
|
|
769
|
+
width: 70px !important;
|
|
770
|
+
height: 70px !important;
|
|
771
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/* Custom chat window size */
|
|
775
|
+
.ask-junkie-window {
|
|
776
|
+
width: 420px !important;
|
|
777
|
+
height: 600px !important;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/* Custom message bubbles */
|
|
781
|
+
.ask-junkie-message.user .message-content {
|
|
782
|
+
background: linear-gradient(135deg, #10b981, #059669) !important;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/* Custom input styling */
|
|
786
|
+
.ask-junkie-input-row input {
|
|
787
|
+
border-radius: 24px !important;
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
---
|
|
792
|
+
|
|
793
|
+
## 🔒 Security Notes
|
|
794
|
+
|
|
795
|
+
- **SDK Keys**: The SDK key only provides access to your chatbot settings. Your AI provider API keys are stored securely in Firebase and never exposed to the client.
|
|
796
|
+
|
|
797
|
+
- **Domain Restriction**: Configure allowed domains in the dashboard to prevent unauthorized use of your SDK key.
|
|
798
|
+
|
|
799
|
+
- **Data Privacy**: Chat analytics are logged to Firebase. Disable with:
|
|
800
|
+
```javascript
|
|
801
|
+
AskJunkie.init({
|
|
802
|
+
sdkKey: 'ak_xxx',
|
|
803
|
+
analytics: { enabled: false }
|
|
804
|
+
});
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
---
|
|
808
|
+
|
|
809
|
+
## 📁 Project Structure
|
|
810
|
+
|
|
811
|
+
```
|
|
812
|
+
ask-junkie-sdk/
|
|
813
|
+
├── dist/
|
|
814
|
+
│ ├── ask-junkie.min.js # UMD bundle (script tag)
|
|
815
|
+
│ ├── ask-junkie.esm.js # ES Module bundle
|
|
816
|
+
│ └── ask-junkie.css # Styles
|
|
817
|
+
├── src/
|
|
818
|
+
│ ├── core/ # Core SDK logic
|
|
819
|
+
│ ├── ai/ # AI provider implementations
|
|
820
|
+
│ ├── ui/ # Chat widget UI
|
|
821
|
+
│ ├── analytics/ # Firebase logging
|
|
822
|
+
│ └── utils/ # Utilities
|
|
823
|
+
├── package.json
|
|
824
|
+
└── README.md
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
---
|
|
828
|
+
|
|
829
|
+
## 🛠️ Development
|
|
830
|
+
|
|
831
|
+
```bash
|
|
832
|
+
# Clone the repo
|
|
833
|
+
git clone https://github.com/junkiescoder/ask-junkie-sdk.git
|
|
834
|
+
|
|
835
|
+
# Install dependencies
|
|
836
|
+
npm install
|
|
837
|
+
|
|
838
|
+
# Development mode (watch)
|
|
839
|
+
npm run dev
|
|
840
|
+
|
|
841
|
+
# Build for production
|
|
842
|
+
npm run build
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
---
|
|
846
|
+
|
|
847
|
+
## 📄 License
|
|
848
|
+
|
|
849
|
+
MIT License - Created by [Junkies Coder](https://junkiescoder.com)
|
|
850
|
+
|
|
851
|
+
---
|
|
852
|
+
|
|
853
|
+
## 🔗 Links
|
|
854
|
+
|
|
855
|
+
- **npm**: [npmjs.com/package/ask-junkie-sdk](https://www.npmjs.com/package/ask-junkie-sdk)
|
|
856
|
+
- **CDN**: [cdn.jsdelivr.net/npm/ask-junkie-sdk](https://cdn.jsdelivr.net/npm/ask-junkie-sdk)
|
|
857
|
+
- **GitHub**: [github.com/junkiescoder/ask-junkie-sdk](https://github.com/junkiescoder/ask-junkie-sdk)
|
|
858
|
+
- **Dashboard**: Contact us for dashboard access
|
|
859
|
+
|
|
860
|
+
---
|
|
861
|
+
|
|
862
|
+
<div align="center">
|
|
863
|
+
Made with ❤️ by Junkies Coder
|
|
864
|
+
</div>
|