@elqnt/chat 2.0.8 → 3.0.1

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 (52) hide show
  1. package/README.md +433 -0
  2. package/dist/api/index.d.mts +250 -8
  3. package/dist/api/index.d.ts +250 -8
  4. package/dist/api/index.js +115 -0
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/api/index.mjs +109 -0
  7. package/dist/api/index.mjs.map +1 -1
  8. package/dist/hooks/index.d.mts +80 -0
  9. package/dist/hooks/index.d.ts +80 -0
  10. package/dist/hooks/index.js +741 -0
  11. package/dist/hooks/index.js.map +1 -0
  12. package/dist/hooks/index.mjs +715 -0
  13. package/dist/hooks/index.mjs.map +1 -0
  14. package/dist/index.d.mts +4 -109
  15. package/dist/index.d.ts +4 -109
  16. package/dist/index.js +731 -2039
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +722 -2016
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/models/index.d.mts +76 -6
  21. package/dist/models/index.d.ts +76 -6
  22. package/dist/models/index.js +21 -0
  23. package/dist/models/index.js.map +1 -1
  24. package/dist/models/index.mjs +14 -0
  25. package/dist/models/index.mjs.map +1 -1
  26. package/dist/transport/index.d.mts +243 -0
  27. package/dist/transport/index.d.ts +243 -0
  28. package/dist/transport/index.js +972 -0
  29. package/dist/transport/index.js.map +1 -0
  30. package/dist/transport/index.mjs +940 -0
  31. package/dist/transport/index.mjs.map +1 -0
  32. package/dist/types-7UNI1iYv.d.ts +250 -0
  33. package/dist/types-CQHtUQ6p.d.mts +250 -0
  34. package/package.json +20 -38
  35. package/dist/hooks/use-websocket-chat-admin.d.mts +0 -17
  36. package/dist/hooks/use-websocket-chat-admin.d.ts +0 -17
  37. package/dist/hooks/use-websocket-chat-admin.js +0 -1196
  38. package/dist/hooks/use-websocket-chat-admin.js.map +0 -1
  39. package/dist/hooks/use-websocket-chat-admin.mjs +0 -1172
  40. package/dist/hooks/use-websocket-chat-admin.mjs.map +0 -1
  41. package/dist/hooks/use-websocket-chat-base.d.mts +0 -81
  42. package/dist/hooks/use-websocket-chat-base.d.ts +0 -81
  43. package/dist/hooks/use-websocket-chat-base.js +0 -1025
  44. package/dist/hooks/use-websocket-chat-base.js.map +0 -1
  45. package/dist/hooks/use-websocket-chat-base.mjs +0 -1001
  46. package/dist/hooks/use-websocket-chat-base.mjs.map +0 -1
  47. package/dist/hooks/use-websocket-chat-customer.d.mts +0 -24
  48. package/dist/hooks/use-websocket-chat-customer.d.ts +0 -24
  49. package/dist/hooks/use-websocket-chat-customer.js +0 -1092
  50. package/dist/hooks/use-websocket-chat-customer.js.map +0 -1
  51. package/dist/hooks/use-websocket-chat-customer.mjs +0 -1068
  52. package/dist/hooks/use-websocket-chat-customer.mjs.map +0 -1
@@ -0,0 +1,243 @@
1
+ import { R as RetryConfig, T as TransportLogger, C as ChatTransport, a as TransportConfig } from '../types-7UNI1iYv.js';
2
+ export { b as ConnectionMetrics, c as CreateChatOptions, D as DEFAULT_RETRY_CONFIG, E as EndChatOptions, d as EventHandler, L as LoadChatOptions, S as SendMessageOptions, e as TransportError, f as TransportFactory, g as TransportState, U as Unsubscribe, h as calculateRetryInterval, i as createLogger } from '../types-7UNI1iYv.js';
3
+ import { ChatEvent } from '../models/index.js';
4
+ import '@elqnt/types';
5
+
6
+ /**
7
+ * SSE Transport (Browser)
8
+ *
9
+ * Uses native EventSource for receiving server events and fetch POST for sending.
10
+ * This is the default transport for browser environments.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { createSSETransport } from "@elqnt/chat/transport";
15
+ *
16
+ * const transport = createSSETransport();
17
+ * await transport.connect({ baseUrl, orgId, userId, clientType: "customer" });
18
+ * ```
19
+ */
20
+
21
+ /**
22
+ * SSE Transport options
23
+ */
24
+ interface SSETransportOptions {
25
+ /** Retry configuration */
26
+ retryConfig?: RetryConfig;
27
+ /** Enable debug logging */
28
+ debug?: boolean;
29
+ /** Custom logger */
30
+ logger?: TransportLogger;
31
+ }
32
+ /**
33
+ * Create an SSE transport for browser environments
34
+ */
35
+ declare function createSSETransport(options?: SSETransportOptions): ChatTransport;
36
+
37
+ /**
38
+ * SSE Transport (Fetch-based)
39
+ *
40
+ * Uses fetch with ReadableStream for receiving server events and fetch POST for sending.
41
+ * Designed for React Native and environments without native EventSource support.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { createFetchSSETransport } from "@elqnt/chat/transport";
46
+ *
47
+ * const transport = createFetchSSETransport();
48
+ * await transport.connect({ baseUrl, orgId, userId, clientType: "customer" });
49
+ * ```
50
+ */
51
+
52
+ /**
53
+ * Fetch SSE Transport options
54
+ */
55
+ interface FetchSSETransportOptions {
56
+ /** Retry configuration */
57
+ retryConfig?: RetryConfig;
58
+ /** Enable debug logging */
59
+ debug?: boolean;
60
+ /** Custom logger */
61
+ logger?: TransportLogger;
62
+ /** Custom fetch implementation (useful for React Native) */
63
+ customFetch?: typeof fetch;
64
+ }
65
+ /**
66
+ * Create a fetch-based SSE transport for React Native and polyfill environments
67
+ */
68
+ declare function createFetchSSETransport(options?: FetchSSETransportOptions): ChatTransport;
69
+
70
+ /**
71
+ * WhatsApp Business API Transport (Stub)
72
+ *
73
+ * This module provides the interface for integrating with WhatsApp Business API.
74
+ * The implementation connects to a webhook receiver that bridges WhatsApp messages
75
+ * to the chat system.
76
+ *
77
+ * ## Integration Architecture
78
+ *
79
+ * ```
80
+ * WhatsApp User → WhatsApp Cloud API → Your Webhook → Chat Service → SSE to Admin
81
+ * ↓
82
+ * NATS Events
83
+ * ```
84
+ *
85
+ * ## Setup Requirements
86
+ *
87
+ * 1. Register a WhatsApp Business Account
88
+ * 2. Create a Meta Business App with WhatsApp integration
89
+ * 3. Configure webhook URL pointing to your chat service
90
+ * 4. Set up message templates for outbound messages
91
+ *
92
+ * ## Backend Integration
93
+ *
94
+ * Your backend should expose webhook endpoints that:
95
+ * - Verify webhook (GET /webhook with hub.verify_token)
96
+ * - Receive messages (POST /webhook with message payload)
97
+ * - Map WhatsApp user IDs to chat users
98
+ * - Create/load chats for new conversations
99
+ *
100
+ * @example Backend Webhook Handler (Go)
101
+ * ```go
102
+ * func HandleWhatsAppWebhook(w http.ResponseWriter, r *http.Request) {
103
+ * if r.Method == "GET" {
104
+ * // Webhook verification
105
+ * verifyToken := r.URL.Query().Get("hub.verify_token")
106
+ * if verifyToken == os.Getenv("WHATSAPP_VERIFY_TOKEN") {
107
+ * w.Write([]byte(r.URL.Query().Get("hub.challenge")))
108
+ * return
109
+ * }
110
+ * http.Error(w, "Invalid verify token", 403)
111
+ * return
112
+ * }
113
+ *
114
+ * // Handle incoming message
115
+ * var payload WhatsAppPayload
116
+ * json.NewDecoder(r.Body).Decode(&payload)
117
+ *
118
+ * // Map to chat event and publish to NATS
119
+ * chatEvent := mapWhatsAppToChatEvent(payload)
120
+ * natsClient.Publish("chat.events", chatEvent)
121
+ * }
122
+ * ```
123
+ *
124
+ * @see https://developers.facebook.com/docs/whatsapp/cloud-api
125
+ */
126
+
127
+ /**
128
+ * WhatsApp transport configuration
129
+ */
130
+ interface WhatsAppTransportConfig extends TransportConfig {
131
+ /** WhatsApp Business API access token */
132
+ accessToken: string;
133
+ /** Phone number ID from Meta Business */
134
+ phoneNumberId: string;
135
+ /** Webhook verify token for setup */
136
+ verifyToken?: string;
137
+ }
138
+ /**
139
+ * WhatsApp transport options
140
+ */
141
+ interface WhatsAppTransportOptions {
142
+ /** Enable debug logging */
143
+ debug?: boolean;
144
+ /** Custom logger */
145
+ logger?: TransportLogger;
146
+ }
147
+ /**
148
+ * WhatsApp message types
149
+ */
150
+ type WhatsAppMessageType = "text" | "image" | "document" | "audio" | "video" | "sticker" | "location" | "contacts" | "interactive" | "template";
151
+ /**
152
+ * Create a WhatsApp Business API transport
153
+ *
154
+ * NOTE: This is a stub implementation. The actual WhatsApp integration
155
+ * happens on the backend via webhooks. This transport is for:
156
+ * - Type definitions
157
+ * - Documentation
158
+ * - Future client-side WhatsApp Web integration
159
+ */
160
+ declare function createWhatsAppTransport(options?: WhatsAppTransportOptions): ChatTransport;
161
+ /**
162
+ * Helper: Convert WhatsApp webhook payload to ChatEvent
163
+ *
164
+ * Use this in your backend webhook handler to map incoming
165
+ * WhatsApp messages to the chat system format.
166
+ */
167
+ interface WhatsAppWebhookPayload {
168
+ object: "whatsapp_business_account";
169
+ entry: Array<{
170
+ id: string;
171
+ changes: Array<{
172
+ value: {
173
+ messaging_product: "whatsapp";
174
+ metadata: {
175
+ display_phone_number: string;
176
+ phone_number_id: string;
177
+ };
178
+ contacts?: Array<{
179
+ profile: {
180
+ name: string;
181
+ };
182
+ wa_id: string;
183
+ }>;
184
+ messages?: Array<{
185
+ from: string;
186
+ id: string;
187
+ timestamp: string;
188
+ type: WhatsAppMessageType;
189
+ text?: {
190
+ body: string;
191
+ };
192
+ image?: {
193
+ id: string;
194
+ mime_type: string;
195
+ sha256: string;
196
+ };
197
+ document?: {
198
+ id: string;
199
+ mime_type: string;
200
+ filename: string;
201
+ };
202
+ audio?: {
203
+ id: string;
204
+ mime_type: string;
205
+ };
206
+ video?: {
207
+ id: string;
208
+ mime_type: string;
209
+ };
210
+ location?: {
211
+ latitude: number;
212
+ longitude: number;
213
+ name?: string;
214
+ };
215
+ }>;
216
+ statuses?: Array<{
217
+ id: string;
218
+ status: "sent" | "delivered" | "read" | "failed";
219
+ timestamp: string;
220
+ recipient_id: string;
221
+ }>;
222
+ };
223
+ }>;
224
+ }>;
225
+ }
226
+ /**
227
+ * Example: Map WhatsApp payload to ChatEvent (for backend use)
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * // In your backend webhook handler
232
+ * import { mapWhatsAppToChatEvent } from "@elqnt/chat/transport";
233
+ *
234
+ * app.post("/webhook/whatsapp", (req, res) => {
235
+ * const events = mapWhatsAppToChatEvent(req.body, orgId);
236
+ * events.forEach(event => publishToChatService(event));
237
+ * res.sendStatus(200);
238
+ * });
239
+ * ```
240
+ */
241
+ declare function mapWhatsAppToChatEvent(payload: WhatsAppWebhookPayload, orgId: string): ChatEvent[];
242
+
243
+ export { ChatTransport, type FetchSSETransportOptions, RetryConfig, type SSETransportOptions, TransportConfig, TransportLogger, type WhatsAppMessageType, type WhatsAppTransportConfig, type WhatsAppTransportOptions, type WhatsAppWebhookPayload, createFetchSSETransport, createSSETransport, createWhatsAppTransport, mapWhatsAppToChatEvent };