@aakash58/chatbot 1.0.40 → 1.0.42

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/index.d.ts CHANGED
@@ -1,15 +1,9 @@
1
+ import * as _aakash58_chatbot from '@aakash58/chatbot';
1
2
  import * as _angular_core from '@angular/core';
2
- import { RendererFactory2, ElementRef, Renderer2, SimpleChanges } from '@angular/core';
3
+ import { RendererFactory2, InjectionToken, OnDestroy, ElementRef, Renderer2, SimpleChanges } from '@angular/core';
3
4
  import { OverlayContainer } from '@angular/cdk/overlay';
4
-
5
- interface Message {
6
- id: string;
7
- sender: 'user' | 'bot';
8
- senderName?: string;
9
- text: string;
10
- timestamp?: Date;
11
- showSuggestions?: boolean;
12
- }
5
+ import * as rxjs from 'rxjs';
6
+ import { Observable } from 'rxjs';
13
7
 
14
8
  type ThemeMode = 'light' | 'dark' | 'system';
15
9
  declare class ThemeService {
@@ -46,7 +40,65 @@ declare class DoohbotInput {
46
40
  readonly botAvatarUrl: string;
47
41
  }
48
42
 
49
- declare class Doohbot extends DoohbotInput {
43
+ /**
44
+ * Configuration for Doohbot API integration
45
+ */
46
+ interface DoohbotApiConfig {
47
+ /**
48
+ * Backend API endpoint URL
49
+ * Example: 'https://api.example.com/chat'
50
+ */
51
+ apiUrl: string;
52
+ /**
53
+ * Optional API key for authentication
54
+ */
55
+ apiKey?: string;
56
+ /**
57
+ * Request timeout in milliseconds
58
+ * @default 30000 (30 seconds)
59
+ */
60
+ timeout?: number;
61
+ /**
62
+ * Enable API mode (true) or use local intent matching (false)
63
+ * @default false
64
+ */
65
+ enableApi?: boolean;
66
+ /**
67
+ * Include message history in API requests
68
+ * @default false
69
+ */
70
+ includeHistory?: boolean;
71
+ /**
72
+ * Maximum number of history messages to include in requests
73
+ * @default 10
74
+ */
75
+ maxHistoryMessages?: number;
76
+ /**
77
+ * Custom headers to include in API requests
78
+ */
79
+ customHeaders?: Record<string, string>;
80
+ /**
81
+ * Enable retry on failure
82
+ * @default true
83
+ */
84
+ enableRetry?: boolean;
85
+ /**
86
+ * Number of retry attempts
87
+ * @default 2
88
+ */
89
+ retryAttempts?: number;
90
+ /**
91
+ * Delay between retries in milliseconds
92
+ * @default 1000
93
+ */
94
+ retryDelay?: number;
95
+ }
96
+ /**
97
+ * Injection token for providing Doohbot API configuration
98
+ */
99
+ declare const DOOHBOT_API_CONFIG: InjectionToken<DoohbotApiConfig>;
100
+
101
+ declare class Doohbot extends DoohbotInput implements OnDestroy {
50
102
  private elementRef;
51
103
  private renderer;
52
104
  config: DoohbotInput;
@@ -57,13 +109,16 @@ declare class Doohbot extends DoohbotInput {
57
109
  enableDrag: boolean;
58
110
  enableResize: boolean;
59
111
  primaryColor: string | undefined;
112
+ apiConfig?: DoohbotApiConfig;
60
113
  isFullScreen: boolean;
61
114
  isChatOpen: _angular_core.WritableSignal<boolean>;
62
115
  isBotTyping: _angular_core.WritableSignal<boolean>;
63
116
  private messageService;
64
- messages: _angular_core.WritableSignal<Message[]>;
117
+ messages: _angular_core.WritableSignal<_aakash58_chatbot.Message[]>;
65
118
  private lastReadMessageId;
66
119
  themeService: ThemeService;
120
+ private tenantContextService;
121
+ private contextSubscription?;
67
122
  maxMessageLength: number;
68
123
  messageError: _angular_core.WritableSignal<string | null>;
69
124
  dismissTimeout: number | null;
@@ -73,10 +128,19 @@ declare class Doohbot extends DoohbotInput {
73
128
  constructor(elementRef: ElementRef, renderer: Renderer2);
74
129
  ngOnChanges(changes: SimpleChanges): void;
75
130
  ngOnInit(): void;
131
+ ngOnDestroy(): void;
76
132
  private updateCssVariables;
133
+ /**
134
+ * Update context when tenant or agent inputs change
135
+ */
136
+ private updateContext;
137
+ /**
138
+ * Update API configuration
139
+ */
140
+ private updateApiConfig;
77
141
  toggleChat(): void;
78
142
  clearChat(): void;
79
- sendMessage(text: string): void;
143
+ sendMessage(text: string): Promise<void>;
80
144
  clearMessageError(): void;
81
145
  showSuggestionChips: _angular_core.Signal<boolean>;
82
146
  markAsReadEffect: _angular_core.EffectRef;
@@ -89,7 +153,300 @@ declare class Doohbot extends DoohbotInput {
89
153
  } | null;
90
154
  toggleFullScreen(): void;
91
155
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<Doohbot, never>;
92
- static ɵcmp: _angular_core.ɵɵComponentDeclaration<Doohbot, "app-doohbot", never, { "config": { "alias": "config"; "required": false; }; "platformTenant": { "alias": "platformTenant"; "required": false; }; "subTenant": { "alias": "subTenant"; "required": false; }; "agent": { "alias": "agent"; "required": false; }; "buttonStyle": { "alias": "buttonStyle"; "required": false; }; "enableDrag": { "alias": "enableDrag"; "required": false; }; "enableResize": { "alias": "enableResize"; "required": false; }; "primaryColor": { "alias": "primaryColor"; "required": false; }; }, {}, never, never, true, never>;
156
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<Doohbot, "app-doohbot", never, { "config": { "alias": "config"; "required": false; }; "platformTenant": { "alias": "platformTenant"; "required": false; }; "subTenant": { "alias": "subTenant"; "required": false; }; "agent": { "alias": "agent"; "required": false; }; "buttonStyle": { "alias": "buttonStyle"; "required": false; }; "enableDrag": { "alias": "enableDrag"; "required": false; }; "enableResize": { "alias": "enableResize"; "required": false; }; "primaryColor": { "alias": "primaryColor"; "required": false; }; "apiConfig": { "alias": "apiConfig"; "required": false; }; }, {}, never, never, true, never>;
157
+ }
158
+
159
+ interface ChatContext$1 {
160
+ platformTenant: string;
161
+ subTenant: string;
162
+ agent: string;
163
+ }
164
+ interface Message {
165
+ id: string;
166
+ sender: 'user' | 'bot';
167
+ senderName?: string;
168
+ text: string;
169
+ timestamp?: Date;
170
+ showSuggestions?: boolean;
171
+ platformTenant?: string;
172
+ subTenant?: string;
173
+ agent?: string;
174
+ }
175
+ interface ChatIntent {
176
+ patterns: string[];
177
+ response: string;
178
+ }
179
+
180
+ /**
181
+ * Request payload for chat API
182
+ */
183
+ interface ChatApiRequest {
184
+ /**
185
+ * User's message text
186
+ */
187
+ message: string;
188
+ /**
189
+ * Platform tenant identifier
190
+ */
191
+ platformTenant: string;
192
+ /**
193
+ * Sub-tenant or organization identifier
194
+ */
195
+ subTenant: string;
196
+ /**
197
+ * Agent or user identifier
198
+ */
199
+ agent: string;
200
+ /**
201
+ * Optional message history for context
202
+ */
203
+ history?: Message[];
204
+ /**
205
+ * Optional metadata
206
+ */
207
+ metadata?: Record<string, any>;
208
+ /**
209
+ * Timestamp of the request
210
+ */
211
+ timestamp?: string;
212
+ }
213
+ /**
214
+ * Response from chat API
215
+ */
216
+ interface ChatApiResponse {
217
+ /**
218
+ * Bot's reply message
219
+ */
220
+ reply: string;
221
+ /**
222
+ * Optional confidence score (0-1)
223
+ */
224
+ confidence?: number;
225
+ /**
226
+ * Whether to show suggestion chips
227
+ */
228
+ showSuggestions?: boolean;
229
+ /**
230
+ * Optional suggested responses
231
+ */
232
+ suggestions?: string[];
233
+ /**
234
+ * Optional metadata from the API
235
+ */
236
+ metadata?: Record<string, any>;
237
+ /**
238
+ * Optional message ID from the backend
239
+ */
240
+ messageId?: string;
241
+ }
242
+ /**
243
+ * Error response from chat API
244
+ */
245
+ interface ChatApiError {
246
+ /**
247
+ * Error message
248
+ */
249
+ message: string;
250
+ /**
251
+ * Error code
252
+ */
253
+ code?: string;
254
+ /**
255
+ * HTTP status code
256
+ */
257
+ statusCode?: number;
258
+ /**
259
+ * Additional error details
260
+ */
261
+ details?: any;
262
+ }
263
+ /**
264
+ * API request state
265
+ */
266
+ declare enum ApiRequestState {
267
+ IDLE = "idle",
268
+ LOADING = "loading",
269
+ SUCCESS = "success",
270
+ ERROR = "error"
271
+ }
272
+
273
+ declare class MessageService {
274
+ private messageStore;
275
+ private currentContextKey;
276
+ messages: _angular_core.WritableSignal<Message[]>;
277
+ audioUnlocked: boolean;
278
+ private enablePersistence;
279
+ private readonly STORAGE_PREFIX;
280
+ private apiService;
281
+ isLoadingApi: _angular_core.WritableSignal<boolean>;
282
+ apiError: _angular_core.WritableSignal<ChatApiError | null>;
283
+ constructor();
284
+ /**
285
+ * Switch to a new context
286
+ */
287
+ switchContext(contextKey: string): void;
288
+ /**
289
+ * Get current context key
290
+ */
291
+ getCurrentContextKey(): string;
292
+ /**
293
+ * Clear messages for current context
294
+ */
295
+ clearMessages(): void;
296
+ /**
297
+ * Clear all messages across all contexts
298
+ */
299
+ clearAllMessages(): void;
300
+ /**
301
+ * Add message to current context
302
+ */
303
+ addMessage(message: Message): void;
304
+ /**
305
+ * Get messages for a specific context
306
+ */
307
+ getMessagesForContext(contextKey: string): Message[];
308
+ /**
309
+ * Get all context keys that have messages
310
+ */
311
+ getAllContextKeys(): string[];
312
+ /**
313
+ * Get bot reply - supports both API and local modes
314
+ * @param userText User's message
315
+ * @returns Promise with bot reply
316
+ */
317
+ getBotReply(userText: string): Promise<string>;
318
+ /**
319
+ * Get bot reply from API
320
+ */
321
+ private getBotReplyFromApi;
322
+ /**
323
+ * Get bot reply using local intent matching
324
+ */
325
+ private getBotReplyLocal;
326
+ getFallbackReply(): string;
327
+ isFallbackIntent(userText: string): boolean;
328
+ unlockAudio(): void;
329
+ playBotSound(): void;
330
+ /**
331
+ * Enable or disable localStorage persistence
332
+ */
333
+ setPersistence(enabled: boolean): void;
334
+ /**
335
+ * Private: Save context messages to store and persist
336
+ */
337
+ private saveContextMessages;
338
+ /**
339
+ * Private: Persist messages to localStorage
340
+ */
341
+ private persistMessages;
342
+ /**
343
+ * Private: Load all persisted messages from localStorage
344
+ */
345
+ private loadPersistedMessages;
346
+ /**
347
+ * Private: Clear all persisted messages from localStorage
348
+ */
349
+ private clearAllPersistedMessages;
350
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<MessageService, never>;
351
+ static ɵprov: _angular_core.ɵɵInjectableDeclaration<MessageService>;
352
+ }
353
+
354
+ declare class ChatbotApiService {
355
+ private http;
356
+ private tenantContext;
357
+ private config;
358
+ /**
359
+ * Send a chat message to the API
360
+ * @param message User's message text
361
+ * @param history Optional message history for context
362
+ * @returns Observable of the API response
363
+ */
364
+ sendMessage(message: string, history?: Message[]): Observable<ChatApiResponse>;
365
+ /**
366
+ * Build request payload with current tenant context
367
+ */
368
+ private buildRequest;
369
+ /**
370
+ * Build HTTP headers
371
+ */
372
+ private buildHeaders;
373
+ /**
374
+ * Apply retry strategy based on configuration
375
+ */
376
+ private applyRetryStrategy;
377
+ /**
378
+ * Determine if error should trigger a retry
379
+ */
380
+ private shouldRetry;
381
+ /**
382
+ * Validate API response
383
+ */
384
+ private validateResponse;
385
+ /**
386
+ * Handle API errors
387
+ */
388
+ private handleError;
389
+ /**
390
+ * Check if API is enabled
391
+ */
392
+ isApiEnabled(): boolean;
393
+ /**
394
+ * Get current API configuration
395
+ */
396
+ getConfig(): DoohbotApiConfig;
397
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ChatbotApiService, never>;
398
+ static ɵprov: _angular_core.ɵɵInjectableDeclaration<ChatbotApiService>;
399
+ }
400
+
401
+ interface ChatContext {
402
+ platformTenant: string;
403
+ subTenant: string;
404
+ agent: string;
405
+ }
406
+ interface ContextChangeEvent {
407
+ previous: ChatContext | null;
408
+ current: ChatContext;
409
+ contextKey: string;
410
+ }
411
+ declare class TenantContextService {
412
+ private platformTenant;
413
+ private subTenant;
414
+ private agent;
415
+ currentContext: _angular_core.Signal<ChatContext>;
416
+ contextKey: _angular_core.Signal<string>;
417
+ private contextChangeSubject;
418
+ contextChange$: rxjs.Observable<ContextChangeEvent>;
419
+ private previousContext;
420
+ constructor();
421
+ /**
422
+ * Update the complete context
423
+ */
424
+ setContext(context: Partial<ChatContext>): void;
425
+ /**
426
+ * Update individual context properties
427
+ */
428
+ setPlatformTenant(platformTenant: string): void;
429
+ setSubTenant(subTenant: string): void;
430
+ setAgent(agent: string): void;
431
+ /**
432
+ * Get current context values
433
+ */
434
+ getPlatformTenant(): string;
435
+ getSubTenant(): string;
436
+ getAgent(): string;
437
+ getContextKey(): string;
438
+ getContext(): ChatContext;
439
+ /**
440
+ * Check if context has changed
441
+ */
442
+ private hasContextChanged;
443
+ /**
444
+ * Reset context to default
445
+ */
446
+ resetContext(): void;
447
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<TenantContextService, never>;
448
+ static ɵprov: _angular_core.ɵɵInjectableDeclaration<TenantContextService>;
93
449
  }
94
450
 
95
- export { Doohbot };
451
+ export { ApiRequestState, ChatbotApiService, DOOHBOT_API_CONFIG, Doohbot, DoohbotInput, MessageService, TenantContextService, ThemeService };
452
+ export type { ChatApiError, ChatApiRequest, ChatApiResponse, ChatContext$1 as ChatContext, ChatIntent, ContextChangeEvent, DoohbotApiConfig, Message, ThemeMode };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aakash58/chatbot",
3
- "version": "1.0.40",
4
- "description": "",
3
+ "version": "1.0.42",
4
+ "description": "multi-tenant switch feature",
5
5
  "peerDependencies": {
6
6
  "@angular/common": "^20.3.0",
7
7
  "@angular/core": "^20.3.0"
Binary file
Binary file