@developer.notchatbot/webchat 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.
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ChatBotProps } from '../types';
3
+ declare const ChatBot: React.FC<ChatBotProps>;
4
+ export default ChatBot;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ChatButtonProps } from '../types';
3
+ declare const ChatButton: React.FC<ChatButtonProps>;
4
+ export default ChatButton;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ChatHeaderProps } from '../types';
3
+ declare const ChatHeader: React.FC<ChatHeaderProps>;
4
+ export default ChatHeader;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ChatWindowProps } from '../types';
3
+ declare const ChatWindow: React.FC<ChatWindowProps>;
4
+ export default ChatWindow;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { MessageProps } from '../types';
3
+ declare const Message: React.FC<MessageProps>;
4
+ export default Message;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { MessageInputProps } from '../types';
3
+ declare const MessageInput: React.FC<MessageInputProps>;
4
+ export default MessageInput;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { MessageListProps } from '../types';
3
+ declare const MessageList: React.FC<MessageListProps>;
4
+ export default MessageList;
@@ -0,0 +1,6 @@
1
+ import { default as React } from 'react';
2
+ interface SkeletonLoadingProps {
3
+ avatar?: string;
4
+ }
5
+ declare const SkeletonLoading: React.FC<SkeletonLoadingProps>;
6
+ export default SkeletonLoading;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { TypingIndicatorProps } from '../types';
3
+ declare const TypingIndicator: React.FC<TypingIndicatorProps>;
4
+ export default TypingIndicator;
@@ -0,0 +1,26 @@
1
+ export declare const COMPANY_CONFIG: {
2
+ readonly apiKey: "78457365-24c0-4fc5-8d83-3324d6aa8ef5";
3
+ readonly chatbotId: 68;
4
+ readonly primaryColor: "#f5a203";
5
+ readonly avatar: "https://n3v6oj3tw5ouoeeb.public.blob.vercel-storage.com/almohadovar-YwigR5IYdZVfSNI8uWilFrzAeVo4JZ.png";
6
+ readonly title: "Almohadovar ChatBot";
7
+ readonly placeholder: "Escribe tu mensaje...";
8
+ readonly initialMessage: "¡Hola! ¿En qué puedo ayudarte con nuestros productos?";
9
+ readonly position: "bottom-right";
10
+ readonly marginBottom: 20;
11
+ readonly marginSide: 20;
12
+ readonly mobile: {
13
+ readonly position: "bottom-right";
14
+ readonly marginBottom: 15;
15
+ readonly marginSide: 15;
16
+ };
17
+ readonly desktop: {
18
+ readonly position: "bottom-right";
19
+ readonly marginBottom: 25;
20
+ readonly marginSide: 25;
21
+ };
22
+ readonly closeButtonIcon: "default";
23
+ readonly closeButtonText: "Cerrar";
24
+ readonly closeButtonCustomIcon: "";
25
+ readonly aiEnabled: true;
26
+ };
@@ -0,0 +1,26 @@
1
+ export declare const COMPANY_CONFIG: {
2
+ readonly apiKey: "{{ API_KEY }}";
3
+ readonly chatbotId: "{{ CHATBOT_ID }}";
4
+ readonly primaryColor: "{{ PRIMARY_COLOR }}";
5
+ readonly avatar: "{{ AVATAR_URL }}";
6
+ readonly title: "{{ TITLE }}";
7
+ readonly placeholder: "{{ PLACEHOLDER }}";
8
+ readonly initialMessage: "{{ INITIAL_MESSAGE }}";
9
+ readonly position: "{{ POSITION }}";
10
+ readonly marginBottom: "{{ MARGIN_BOTTOM }}";
11
+ readonly marginSide: "{{ MARGIN_SIDE }}";
12
+ readonly mobile: {
13
+ readonly position: "{{ MOBILE_POSITION }}";
14
+ readonly marginBottom: "{{ MOBILE_MARGIN_BOTTOM }}";
15
+ readonly marginSide: "{{ MOBILE_MARGIN_SIDE }}";
16
+ };
17
+ readonly desktop: {
18
+ readonly position: "{{ DESKTOP_POSITION }}";
19
+ readonly marginBottom: "{{ DESKTOP_MARGIN_BOTTOM }}";
20
+ readonly marginSide: "{{ DESKTOP_MARGIN_SIDE }}";
21
+ };
22
+ readonly closeButtonIcon: "{{ CLOSE_BUTTON_ICON }}";
23
+ readonly closeButtonText: "{{ CLOSE_BUTTON_TEXT }}";
24
+ readonly closeButtonCustomIcon: "{{ CLOSE_BUTTON_CUSTOM_ICON }}";
25
+ readonly aiEnabled: "{{ AI_ENABLED }}";
26
+ };
@@ -0,0 +1,16 @@
1
+ import { Message } from '../types';
2
+ /**
3
+ * Default configuration values for WebChat
4
+ */
5
+ /**
6
+ * Creates the default initial message with optional company name
7
+ * @param companyName Optional company name for personalization
8
+ * @returns Default initial message text
9
+ */
10
+ export declare const createDefaultInitialMessage: (companyName?: string) => string;
11
+ /**
12
+ * Creates the default initial message object
13
+ * @param companyName Optional company name for personalization
14
+ * @returns Default initial message
15
+ */
16
+ export declare const createDefaultInitialMessageObject: (companyName?: string) => Message;
@@ -0,0 +1,25 @@
1
+ export interface EndpointConfig {
2
+ baseUrl: string;
3
+ chatEndpoint: string;
4
+ conversationEndpoint: string;
5
+ }
6
+ /**
7
+ * Detecta si estamos en ambiente de desarrollo
8
+ */
9
+ export declare function isDevelopmentEnvironment(): boolean;
10
+ /**
11
+ * Obtiene la configuración de endpoints según el ambiente
12
+ */
13
+ export declare function getEndpointConfig(): EndpointConfig;
14
+ /**
15
+ * Obtiene el endpoint de chat
16
+ */
17
+ export declare function getChatEndpoint(): string;
18
+ /**
19
+ * Obtiene el endpoint de conversación
20
+ */
21
+ export declare function getConversationEndpoint(): string;
22
+ /**
23
+ * Obtiene la URL base según el ambiente
24
+ */
25
+ export declare function getBaseUrl(): string;
@@ -0,0 +1,3 @@
1
+ import { WebChatAPI } from './types';
2
+ declare const WebChat: WebChatAPI;
3
+ export default WebChat;
@@ -0,0 +1,93 @@
1
+ export interface WebChatPositionConfig {
2
+ position?: 'bottom-right' | 'bottom-left';
3
+ marginBottom?: number;
4
+ marginSide?: number;
5
+ }
6
+ export interface WebChatConfig {
7
+ elementId: string;
8
+ title?: string;
9
+ placeholder?: string;
10
+ primaryColor?: string;
11
+ avatar?: string;
12
+ apiKey?: string;
13
+ chatbotId?: number;
14
+ position?: 'bottom-right' | 'bottom-left';
15
+ conversationId?: string;
16
+ initialMessage?: string;
17
+ closeButtonIcon?: 'default' | 'text' | 'custom';
18
+ closeButtonText?: string;
19
+ closeButtonCustomIcon?: string;
20
+ marginBottom?: number;
21
+ marginSide?: number;
22
+ aiEnabled?: boolean;
23
+ mobile?: WebChatPositionConfig;
24
+ desktop?: WebChatPositionConfig;
25
+ }
26
+ export interface Message {
27
+ id: string;
28
+ text: string;
29
+ sender: 'user' | 'bot';
30
+ timestamp: Date;
31
+ conversationId?: string;
32
+ }
33
+ export interface ChatBotProps {
34
+ config: WebChatConfig;
35
+ }
36
+ export interface ChatButtonProps {
37
+ isOpen: boolean;
38
+ onClick: () => void;
39
+ primaryColor?: string;
40
+ position?: 'bottom-right' | 'bottom-left';
41
+ marginBottom?: number;
42
+ marginSide?: number;
43
+ hasNewMessages?: boolean;
44
+ isMobile?: boolean;
45
+ }
46
+ export interface ChatWindowProps {
47
+ isOpen: boolean;
48
+ onClose: () => void;
49
+ config: WebChatConfig;
50
+ messages: Message[];
51
+ onSendMessage: (message: string) => void;
52
+ isLoading?: boolean;
53
+ isAiTyping?: boolean;
54
+ position?: 'bottom-right' | 'bottom-left';
55
+ marginBottom?: number;
56
+ marginSide?: number;
57
+ isMobile?: boolean;
58
+ }
59
+ export interface ChatHeaderProps {
60
+ title: string;
61
+ onClose: () => void;
62
+ primaryColor?: string;
63
+ avatar?: string;
64
+ closeButtonIcon?: 'default' | 'text' | 'custom';
65
+ closeButtonText?: string;
66
+ closeButtonCustomIcon?: string;
67
+ }
68
+ export interface MessageListProps {
69
+ messages: Message[];
70
+ isTyping: boolean;
71
+ avatar?: string;
72
+ }
73
+ export interface MessageProps {
74
+ message: Message;
75
+ avatar?: string;
76
+ }
77
+ export interface MessageInputProps {
78
+ onSendMessage: (message: string) => void;
79
+ placeholder?: string;
80
+ primaryColor?: string;
81
+ disabled?: boolean;
82
+ }
83
+ export interface TypingIndicatorProps {
84
+ avatar?: string;
85
+ }
86
+ export interface WebChatInstance {
87
+ root: any;
88
+ destroy: () => void;
89
+ getConversationId: () => string | null;
90
+ }
91
+ export interface WebChatAPI {
92
+ initialize: (config?: Partial<WebChatConfig>) => WebChatInstance | null;
93
+ }
@@ -0,0 +1,28 @@
1
+ import { default as Ably } from 'ably';
2
+ import { Message } from '../types';
3
+ export interface AblyConnectionData {
4
+ client: Ably.Realtime;
5
+ channel: Ably.Types.RealtimeChannelBase;
6
+ }
7
+ /**
8
+ * Initializes Ably connection with provided token details
9
+ * @param tokenDetails Token details from API
10
+ * @param chatbotUid Chatbot UID
11
+ * @param conversationId Conversation ID
12
+ * @param onMessage Callback for new messages
13
+ * @param onConnectionChange Callback for connection status changes
14
+ * @returns Promise that resolves to Ably connection data
15
+ */
16
+ export declare const initializeAblyConnection: (tokenDetails: any, chatbotUid: string, conversationId: string, onMessage: (message: Message) => void, onConnectionChange?: (status: string) => void) => Promise<AblyConnectionData>;
17
+ /**
18
+ * Fetches Ably token from conversation endpoint
19
+ * @param conversationId Conversation ID
20
+ * @param apiKey API key for authentication
21
+ * @returns Promise that resolves to conversation data with token details
22
+ */
23
+ export declare const fetchAblyToken: (conversationId: string, apiKey: string) => Promise<any>;
24
+ /**
25
+ * Closes Ably connection safely
26
+ * @param client Ably client to close
27
+ */
28
+ export declare const closeAblyConnection: (client: Ably.Realtime | null) => void;
@@ -0,0 +1,22 @@
1
+ import { WebChatConfig, WebChatPositionConfig } from '../types';
2
+ /**
3
+ * Resolved configuration with device-specific overrides applied
4
+ */
5
+ export interface ResolvedWebChatConfig extends WebChatConfig {
6
+ position: 'bottom-right' | 'bottom-left';
7
+ marginBottom: number;
8
+ marginSide: number;
9
+ aiEnabled: boolean;
10
+ }
11
+ /**
12
+ * Resolves the final configuration by applying device-specific overrides
13
+ * @param config Base configuration
14
+ * @returns Resolved configuration with device-specific settings applied
15
+ */
16
+ export declare const resolveWebChatConfig: (config: WebChatConfig) => ResolvedWebChatConfig;
17
+ /**
18
+ * Gets only the position-related configuration for the current device
19
+ * @param config Base configuration
20
+ * @returns Position configuration for current device
21
+ */
22
+ export declare const getDevicePositionConfig: (config: WebChatConfig) => Required<WebChatPositionConfig>;
@@ -0,0 +1,21 @@
1
+ import { Message } from '../types';
2
+ /**
3
+ * Fetches conversation history from the API
4
+ * @param conversationId The conversation ID to fetch history for
5
+ * @param apiKey The API key for authentication
6
+ * @returns Promise that resolves to conversation data or null if failed
7
+ */
8
+ export declare const fetchConversationHistory: (conversationId: string, apiKey: string) => Promise<any>;
9
+ /**
10
+ * Transforms API messages to WebChat message format
11
+ * @param apiMessages Array of messages from the API
12
+ * @returns Array of WebChat Message objects
13
+ */
14
+ export declare const transformApiMessagesToWebChat: (apiMessages: any[]) => Message[];
15
+ /**
16
+ * Transforms WebChat messages to API format
17
+ * @param messages Array of WebChat Message objects
18
+ * @param conversationId The conversation ID
19
+ * @returns Array of messages in API format
20
+ */
21
+ export declare const transformWebChatMessagesToApi: (messages: Message[], conversationId: string) => any[];
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Secure cookie management utilities for WebChat
3
+ */
4
+ interface CookieOptions {
5
+ expires?: Date;
6
+ maxAge?: number;
7
+ domain?: string;
8
+ path?: string;
9
+ secure?: boolean;
10
+ sameSite?: 'strict' | 'lax' | 'none';
11
+ }
12
+ /**
13
+ * Set a secure cookie with proper security flags
14
+ */
15
+ export declare function setCookie(name: string, value: string, options?: CookieOptions): void;
16
+ /**
17
+ * Get a cookie value by name
18
+ */
19
+ export declare function getCookie(name: string): string | null;
20
+ /**
21
+ * Delete a cookie by setting it to expire in the past
22
+ */
23
+ export declare function deleteCookie(name: string, options?: Pick<CookieOptions, 'domain' | 'path'>): void;
24
+ /**
25
+ * Check if cookies are supported/enabled
26
+ */
27
+ export declare function areCookiesSupported(): boolean;
28
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Device detection utilities for WebChat
3
+ */
4
+ /**
5
+ * Detects if the current device is mobile based on user agent and screen size
6
+ * @returns {boolean} true if mobile, false if desktop
7
+ */
8
+ export declare const isMobileDevice: () => boolean;
9
+ /**
10
+ * Gets the current device type
11
+ * @returns {'mobile' | 'desktop'}
12
+ */
13
+ export declare const getDeviceType: () => "mobile" | "desktop";
14
+ /**
15
+ * Adds a resize listener to detect device type changes
16
+ * @param callback Function to call when device type changes
17
+ * @returns Cleanup function to remove the listener
18
+ */
19
+ export declare const onDeviceTypeChange: (callback: (deviceType: "mobile" | "desktop") => void) => (() => void);
@@ -0,0 +1,56 @@
1
+ import { Message } from '../types';
2
+ export interface SendMessagePayload {
3
+ conversationId: string;
4
+ conversation: {
5
+ id: string;
6
+ chatbotId: string | null;
7
+ senderId: string;
8
+ createdAt: string;
9
+ chatbotActivated: boolean;
10
+ updatedAt: string;
11
+ source: string;
12
+ lastUserMessage: null;
13
+ qualification: null;
14
+ contactId: null;
15
+ conversationType: null;
16
+ language: null;
17
+ region: null;
18
+ website: string;
19
+ messages: any[];
20
+ };
21
+ chatbotUid: string;
22
+ }
23
+ /**
24
+ * Creates a fallback bot message for error scenarios
25
+ * @returns Fallback bot message
26
+ */
27
+ export declare const createFallbackMessage: () => Message;
28
+ /**
29
+ * Creates a notification message for when AI is disabled
30
+ * @returns Notification message
31
+ */
32
+ export declare const createNotificationMessage: () => Message;
33
+ /**
34
+ * Builds the payload for sending messages to the API
35
+ * @param conversationId Conversation ID
36
+ * @param messages Array of messages
37
+ * @param config Chat configuration
38
+ * @param userIP User's IP address
39
+ * @returns API payload
40
+ */
41
+ export declare const buildMessagePayload: (conversationId: string, messages: Message[], config: {
42
+ apiKey: string;
43
+ chatbotId?: string;
44
+ }, userIP: string) => SendMessagePayload;
45
+ /**
46
+ * Sends messages to the chat API
47
+ * @param payload Message payload
48
+ * @returns Promise that resolves to API response or null if failed
49
+ */
50
+ export declare const sendMessageToAPI: (payload: SendMessagePayload) => Promise<any>;
51
+ /**
52
+ * Creates a bot message from API response
53
+ * @param responseData API response data
54
+ * @returns Bot message or null if no content
55
+ */
56
+ export declare const createBotMessageFromResponse: (responseData: any) => Message | null;
@@ -0,0 +1,32 @@
1
+ export interface NotChatbotCookieData {
2
+ conversationId: string;
3
+ conversationStarted: boolean;
4
+ }
5
+ /**
6
+ * Get the notchatbot cookie data, creating it if it doesn't exist
7
+ */
8
+ export declare function getNotChatbotCookie(): NotChatbotCookieData;
9
+ /**
10
+ * Set the notchatbot cookie with specified data
11
+ */
12
+ export declare function setNotChatbotCookie(data: NotChatbotCookieData): void;
13
+ /**
14
+ * Update the conversationStarted flag in the cookie
15
+ */
16
+ export declare function setConversationStarted(started: boolean): NotChatbotCookieData;
17
+ /**
18
+ * Get current conversation ID from the cookie
19
+ */
20
+ export declare function getConversationId(): string;
21
+ /**
22
+ * Check if conversation has been started
23
+ */
24
+ export declare function isConversationStarted(): boolean;
25
+ /**
26
+ * Reset the conversation by creating a new conversation ID and setting conversationStarted to false
27
+ */
28
+ export declare function resetConversation(): NotChatbotCookieData;
29
+ /**
30
+ * Delete the notchatbot cookie
31
+ */
32
+ export declare function deleteNotChatbotCookie(): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Fetches the user's IP address from an external service
3
+ * @returns Promise that resolves to the user's IP address or a fallback identifier
4
+ */
5
+ export declare const getUserIP: () => Promise<string>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generate a UUIDv7 (time-ordered UUID)
3
+ * UUIDv7 is designed to be time-ordered and includes a timestamp component
4
+ */
5
+ export declare function generateUUIDv7(): string;
6
+ /**
7
+ * Validate if a string is a valid UUIDv7
8
+ */
9
+ export declare function isValidUUIDv7(uuid: string): boolean;