wexa-chat 0.1.35 → 0.2.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 CHANGED
@@ -121,7 +121,7 @@ export type InitOptions = {
121
121
  - `searchByParticipantPair({ organizationId, a, b })`
122
122
 
123
123
  - Messages
124
- - `sendMessage({ organizationId, conversationId, senderModel, senderId, text, kind?, parentMessageId?, rootThreadId? })`
124
+ - `sendMessage({ organizationId, conversationId, senderModel, senderId, text, source, kind?, parentMessageId?, rootThreadId? })`
125
125
  - `listMessages({ organizationId, conversationId, limit?, cursor? })`
126
126
  - `listMessagesWithSenders({ organizationId, conversationId, limit?, cursor?, populateSenders: true, populateOptions? })`
127
127
  - `markRead({ organizationId, conversationId, participantModel, participantId, messageId })`
@@ -209,6 +209,24 @@ The method returns messages sorted by creation time (newest first), making it id
209
209
 
210
210
  The type `MessageWithSender` is exported from the package for proper TypeScript support.
211
211
 
212
+ ### Message Source
213
+
214
+ Messages now include a required `source` field (array) to indicate one or more origins for a message. The model enforces `source` values via an enum of strings:
215
+
216
+ ```ts
217
+ export const sourceType = {
218
+ LINKEDIN: 'linkedin',
219
+ WHATSAPP: 'whatsapp',
220
+ EMAIL: 'email',
221
+ CORE: 'core',
222
+ } as const;
223
+
224
+ export type SourceType = (typeof sourceType)[keyof typeof sourceType];
225
+ ```
226
+
227
+ When sending a message via `sendMessage`, you must provide `source: SourceType[]`.
228
+ For internal server-generated messages, use `[sourceType.CORE]`.
229
+
212
230
  ## Models
213
231
 
214
232
  The package exports the following model types which can be imported directly:
package/dist/index.d.cts CHANGED
@@ -108,8 +108,75 @@ type InitOptions = {
108
108
  sendPerMin?: number;
109
109
  typingPerMin?: number;
110
110
  };
111
+ /**
112
+ * Optional external data service endpoint accessible across the package
113
+ */
114
+ dataServiceEndpoint?: string;
115
+ /**
116
+ * Optional secret id to access the external service
117
+ */
118
+ secretId?: string;
119
+ };
120
+
121
+ declare const sourceType: {
122
+ readonly LINKEDIN: "linkedin";
123
+ readonly WHATSAPP: "whatsapp";
124
+ readonly EMAIL: "email";
125
+ readonly CORE: "core";
126
+ };
127
+ type SourceType = (typeof sourceType)[keyof typeof sourceType];
128
+ interface IMessage extends Document {
129
+ organizationId: string;
130
+ conversationId: string;
131
+ senderModel: string;
132
+ senderId: string;
133
+ text: string;
134
+ kind: 'text' | 'system';
135
+ source: SourceType[];
136
+ failed_source?: Array<{
137
+ source: string;
138
+ message: string;
139
+ }>;
140
+ parentMessageId?: string;
141
+ rootThreadId?: string;
142
+ editedAt?: Date;
143
+ deletedAt?: Date;
144
+ createdAt: Date;
145
+ updatedAt: Date;
146
+ }
147
+ /**
148
+ * Create (or retrieve) Message model safely
149
+ */
150
+ declare function createMessageModel(options: InitOptions, conn?: Connection): Model<IMessage>;
151
+
152
+ declare const modelRegistry: Map<string, mongoose.Model<any, {}, {}, {}, any, any>>;
153
+ /**
154
+ * Create Mongoose models with applied configuration
155
+ * @param mongooseInstance Mongoose instance
156
+ * @param options Initialization options
157
+ * @returns Object containing Conversation and Message models
158
+ */
159
+ declare function createModels(mongooseInstance: typeof mongoose, options: InitOptions): {
160
+ Conversation: mongoose.Model<IConversation, {}, {}, {}, mongoose.Document<unknown, {}, IConversation> & IConversation & {
161
+ _id: mongoose.Types.ObjectId;
162
+ }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
163
+ Message: mongoose.Model<IMessage, {}, {}, {}, mongoose.Document<unknown, {}, IMessage> & IMessage & {
164
+ _id: mongoose.Types.ObjectId;
165
+ }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
111
166
  };
112
167
 
168
+ /**
169
+ * Ensure all indexes are created on models
170
+ * @param models Object containing Mongoose models
171
+ */
172
+ declare function ensureIndexes(models: {
173
+ Conversation: Model<IConversation>;
174
+ Message: Model<IMessage>;
175
+ }): Promise<void>;
176
+
177
+ type ConversationModel = Model<IConversation>;
178
+ type MessageModel = Model<IMessage>;
179
+
113
180
  type CreateConversationArgs = {
114
181
  organizationId: string;
115
182
  a: {
@@ -126,10 +193,15 @@ type SendMessageArgs = {
126
193
  conversationId: string;
127
194
  senderModel: string;
128
195
  senderId: string;
196
+ source: SourceType[];
129
197
  text: string;
130
- kind?: "text" | "system";
198
+ kind?: 'text' | 'system';
131
199
  parentMessageId?: string;
132
200
  rootThreadId?: string;
201
+ connectorIds?: Record<string, {
202
+ contactId: string;
203
+ connectorId: string;
204
+ }>;
133
205
  };
134
206
  type ListMessagesArgs = {
135
207
  organizationId: string;
@@ -155,7 +227,7 @@ type SearchMessagesArgs = {
155
227
  conversationId?: string;
156
228
  senderModel?: string;
157
229
  senderId?: string;
158
- kind?: "text" | "system";
230
+ kind?: 'text' | 'system';
159
231
  dateFrom?: string;
160
232
  dateTo?: string;
161
233
  threadRootId?: string;
@@ -196,25 +268,6 @@ interface IConversation extends Document {
196
268
  */
197
269
  declare function createConversationModel(options: InitOptions, conn?: Connection): Model<IConversation>;
198
270
 
199
- interface IMessage extends Document {
200
- organizationId: string;
201
- conversationId: string;
202
- senderModel: string;
203
- senderId: string;
204
- text: string;
205
- kind: 'text' | 'system';
206
- parentMessageId?: string;
207
- rootThreadId?: string;
208
- editedAt?: Date;
209
- deletedAt?: Date;
210
- createdAt: Date;
211
- updatedAt: Date;
212
- }
213
- /**
214
- * Create (or retrieve) Message model safely
215
- */
216
- declare function createMessageModel(options: InitOptions, conn?: Connection): Model<IMessage>;
217
-
218
271
  /**
219
272
  * Pagination result interface
220
273
  */
@@ -401,34 +454,6 @@ declare function createTransport(config?: TransportConfig, server?: Server): Tra
401
454
  socket?: SocketTransport;
402
455
  };
403
456
 
404
- declare const modelRegistry: Map<string, mongoose.Model<any, {}, {}, {}, any, any>>;
405
- /**
406
- * Create Mongoose models with applied configuration
407
- * @param mongooseInstance Mongoose instance
408
- * @param options Initialization options
409
- * @returns Object containing Conversation and Message models
410
- */
411
- declare function createModels(mongooseInstance: typeof mongoose, options: InitOptions): {
412
- Conversation: mongoose.Model<IConversation, {}, {}, {}, mongoose.Document<unknown, {}, IConversation> & IConversation & {
413
- _id: mongoose.Types.ObjectId;
414
- }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
415
- Message: mongoose.Model<IMessage, {}, {}, {}, mongoose.Document<unknown, {}, IMessage> & IMessage & {
416
- _id: mongoose.Types.ObjectId;
417
- }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
418
- };
419
-
420
- /**
421
- * Ensure all indexes are created on models
422
- * @param models Object containing Mongoose models
423
- */
424
- declare function ensureIndexes(models: {
425
- Conversation: Model<IConversation>;
426
- Message: Model<IMessage>;
427
- }): Promise<void>;
428
-
429
- type ConversationModel = Model<IConversation>;
430
- type MessageModel = Model<IMessage>;
431
-
432
457
  /**
433
458
  * Generates a random string ID with the specified length
434
459
  * @param length The length of the ID to generate (default: 24)
@@ -521,6 +546,13 @@ declare function searchByParticipantPair(model: Model<IConversation>, params: {
521
546
  };
522
547
  }): Promise<IConversation | null>;
523
548
 
549
+ type RuntimeConfig = {
550
+ dataServiceEndpoint?: string;
551
+ secretId?: string;
552
+ };
553
+ declare function setRuntimeConfig(cfg: RuntimeConfig): void;
554
+ declare function getRuntimeConfig(): RuntimeConfig;
555
+
524
556
  /**
525
557
  * Chat services container
526
558
  */
@@ -546,4 +578,4 @@ interface ChatServices {
546
578
  */
547
579
  declare function initChat(mongooseInstance: typeof mongoose, options: InitOptions, server?: Server): Promise<ChatServices>;
548
580
 
549
- export { type Actor, type ChatServices, type ConversationModel, type ConversationReadEvent, type ConversationsService, type CreateConversationArgs, type EnvironmentConfig, type IConversation, type IMessage, type InitOptions, type ListMessagesArgs, type MarkReadArgs, type MessageCreatedEvent, type MessageModel, type MessageServiceHooks, type MessageWithSender, type MessagesService, type PaginatedResult, type PresenceEvent, type RedisConfig, type SearchConversationsArgs, type SearchMessagesArgs, type SendMessageArgs, type SocketConfig$1 as SocketConfig, type Transport, type TransportConfig, type TypingEvent, createConversationId, createConversationModel, createConversationsService, createCursor, createMessageId, createMessageModel, createMessagesService, createModels, createPaginatedResponse, createThreadId, createTransport, ensureIndexes, generateId, getRedisConfig, initChat, modelRegistry, parseCursor, searchByParticipantPair, searchConversations, searchMessages, validateCreateConversationArgs, validateInitOptions, validateMarkReadArgs, validatePagination, validateSendMessageArgs };
581
+ export { type Actor, type ChatServices, type ConversationModel, type ConversationReadEvent, type ConversationsService, type CreateConversationArgs, type EnvironmentConfig, type IConversation, type IMessage, type InitOptions, type ListMessagesArgs, type MarkReadArgs, type MessageCreatedEvent, type MessageModel, type MessageServiceHooks, type MessageWithSender, type MessagesService, type PaginatedResult, type PresenceEvent, type RedisConfig, type RuntimeConfig, type SearchConversationsArgs, type SearchMessagesArgs, type SendMessageArgs, type SocketConfig$1 as SocketConfig, type SourceType, type Transport, type TransportConfig, type TypingEvent, createConversationId, createConversationModel, createConversationsService, createCursor, createMessageId, createMessageModel, createMessagesService, createModels, createPaginatedResponse, createThreadId, createTransport, ensureIndexes, generateId, getRedisConfig, getRuntimeConfig, initChat, modelRegistry, parseCursor, searchByParticipantPair, searchConversations, searchMessages, setRuntimeConfig, sourceType, validateCreateConversationArgs, validateInitOptions, validateMarkReadArgs, validatePagination, validateSendMessageArgs };
package/dist/index.d.ts CHANGED
@@ -108,8 +108,75 @@ type InitOptions = {
108
108
  sendPerMin?: number;
109
109
  typingPerMin?: number;
110
110
  };
111
+ /**
112
+ * Optional external data service endpoint accessible across the package
113
+ */
114
+ dataServiceEndpoint?: string;
115
+ /**
116
+ * Optional secret id to access the external service
117
+ */
118
+ secretId?: string;
119
+ };
120
+
121
+ declare const sourceType: {
122
+ readonly LINKEDIN: "linkedin";
123
+ readonly WHATSAPP: "whatsapp";
124
+ readonly EMAIL: "email";
125
+ readonly CORE: "core";
126
+ };
127
+ type SourceType = (typeof sourceType)[keyof typeof sourceType];
128
+ interface IMessage extends Document {
129
+ organizationId: string;
130
+ conversationId: string;
131
+ senderModel: string;
132
+ senderId: string;
133
+ text: string;
134
+ kind: 'text' | 'system';
135
+ source: SourceType[];
136
+ failed_source?: Array<{
137
+ source: string;
138
+ message: string;
139
+ }>;
140
+ parentMessageId?: string;
141
+ rootThreadId?: string;
142
+ editedAt?: Date;
143
+ deletedAt?: Date;
144
+ createdAt: Date;
145
+ updatedAt: Date;
146
+ }
147
+ /**
148
+ * Create (or retrieve) Message model safely
149
+ */
150
+ declare function createMessageModel(options: InitOptions, conn?: Connection): Model<IMessage>;
151
+
152
+ declare const modelRegistry: Map<string, mongoose.Model<any, {}, {}, {}, any, any>>;
153
+ /**
154
+ * Create Mongoose models with applied configuration
155
+ * @param mongooseInstance Mongoose instance
156
+ * @param options Initialization options
157
+ * @returns Object containing Conversation and Message models
158
+ */
159
+ declare function createModels(mongooseInstance: typeof mongoose, options: InitOptions): {
160
+ Conversation: mongoose.Model<IConversation, {}, {}, {}, mongoose.Document<unknown, {}, IConversation> & IConversation & {
161
+ _id: mongoose.Types.ObjectId;
162
+ }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
163
+ Message: mongoose.Model<IMessage, {}, {}, {}, mongoose.Document<unknown, {}, IMessage> & IMessage & {
164
+ _id: mongoose.Types.ObjectId;
165
+ }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
111
166
  };
112
167
 
168
+ /**
169
+ * Ensure all indexes are created on models
170
+ * @param models Object containing Mongoose models
171
+ */
172
+ declare function ensureIndexes(models: {
173
+ Conversation: Model<IConversation>;
174
+ Message: Model<IMessage>;
175
+ }): Promise<void>;
176
+
177
+ type ConversationModel = Model<IConversation>;
178
+ type MessageModel = Model<IMessage>;
179
+
113
180
  type CreateConversationArgs = {
114
181
  organizationId: string;
115
182
  a: {
@@ -126,10 +193,15 @@ type SendMessageArgs = {
126
193
  conversationId: string;
127
194
  senderModel: string;
128
195
  senderId: string;
196
+ source: SourceType[];
129
197
  text: string;
130
- kind?: "text" | "system";
198
+ kind?: 'text' | 'system';
131
199
  parentMessageId?: string;
132
200
  rootThreadId?: string;
201
+ connectorIds?: Record<string, {
202
+ contactId: string;
203
+ connectorId: string;
204
+ }>;
133
205
  };
134
206
  type ListMessagesArgs = {
135
207
  organizationId: string;
@@ -155,7 +227,7 @@ type SearchMessagesArgs = {
155
227
  conversationId?: string;
156
228
  senderModel?: string;
157
229
  senderId?: string;
158
- kind?: "text" | "system";
230
+ kind?: 'text' | 'system';
159
231
  dateFrom?: string;
160
232
  dateTo?: string;
161
233
  threadRootId?: string;
@@ -196,25 +268,6 @@ interface IConversation extends Document {
196
268
  */
197
269
  declare function createConversationModel(options: InitOptions, conn?: Connection): Model<IConversation>;
198
270
 
199
- interface IMessage extends Document {
200
- organizationId: string;
201
- conversationId: string;
202
- senderModel: string;
203
- senderId: string;
204
- text: string;
205
- kind: 'text' | 'system';
206
- parentMessageId?: string;
207
- rootThreadId?: string;
208
- editedAt?: Date;
209
- deletedAt?: Date;
210
- createdAt: Date;
211
- updatedAt: Date;
212
- }
213
- /**
214
- * Create (or retrieve) Message model safely
215
- */
216
- declare function createMessageModel(options: InitOptions, conn?: Connection): Model<IMessage>;
217
-
218
271
  /**
219
272
  * Pagination result interface
220
273
  */
@@ -401,34 +454,6 @@ declare function createTransport(config?: TransportConfig, server?: Server): Tra
401
454
  socket?: SocketTransport;
402
455
  };
403
456
 
404
- declare const modelRegistry: Map<string, mongoose.Model<any, {}, {}, {}, any, any>>;
405
- /**
406
- * Create Mongoose models with applied configuration
407
- * @param mongooseInstance Mongoose instance
408
- * @param options Initialization options
409
- * @returns Object containing Conversation and Message models
410
- */
411
- declare function createModels(mongooseInstance: typeof mongoose, options: InitOptions): {
412
- Conversation: mongoose.Model<IConversation, {}, {}, {}, mongoose.Document<unknown, {}, IConversation> & IConversation & {
413
- _id: mongoose.Types.ObjectId;
414
- }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
415
- Message: mongoose.Model<IMessage, {}, {}, {}, mongoose.Document<unknown, {}, IMessage> & IMessage & {
416
- _id: mongoose.Types.ObjectId;
417
- }, any> | mongoose.Model<any, {}, {}, {}, any, any>;
418
- };
419
-
420
- /**
421
- * Ensure all indexes are created on models
422
- * @param models Object containing Mongoose models
423
- */
424
- declare function ensureIndexes(models: {
425
- Conversation: Model<IConversation>;
426
- Message: Model<IMessage>;
427
- }): Promise<void>;
428
-
429
- type ConversationModel = Model<IConversation>;
430
- type MessageModel = Model<IMessage>;
431
-
432
457
  /**
433
458
  * Generates a random string ID with the specified length
434
459
  * @param length The length of the ID to generate (default: 24)
@@ -521,6 +546,13 @@ declare function searchByParticipantPair(model: Model<IConversation>, params: {
521
546
  };
522
547
  }): Promise<IConversation | null>;
523
548
 
549
+ type RuntimeConfig = {
550
+ dataServiceEndpoint?: string;
551
+ secretId?: string;
552
+ };
553
+ declare function setRuntimeConfig(cfg: RuntimeConfig): void;
554
+ declare function getRuntimeConfig(): RuntimeConfig;
555
+
524
556
  /**
525
557
  * Chat services container
526
558
  */
@@ -546,4 +578,4 @@ interface ChatServices {
546
578
  */
547
579
  declare function initChat(mongooseInstance: typeof mongoose, options: InitOptions, server?: Server): Promise<ChatServices>;
548
580
 
549
- export { type Actor, type ChatServices, type ConversationModel, type ConversationReadEvent, type ConversationsService, type CreateConversationArgs, type EnvironmentConfig, type IConversation, type IMessage, type InitOptions, type ListMessagesArgs, type MarkReadArgs, type MessageCreatedEvent, type MessageModel, type MessageServiceHooks, type MessageWithSender, type MessagesService, type PaginatedResult, type PresenceEvent, type RedisConfig, type SearchConversationsArgs, type SearchMessagesArgs, type SendMessageArgs, type SocketConfig$1 as SocketConfig, type Transport, type TransportConfig, type TypingEvent, createConversationId, createConversationModel, createConversationsService, createCursor, createMessageId, createMessageModel, createMessagesService, createModels, createPaginatedResponse, createThreadId, createTransport, ensureIndexes, generateId, getRedisConfig, initChat, modelRegistry, parseCursor, searchByParticipantPair, searchConversations, searchMessages, validateCreateConversationArgs, validateInitOptions, validateMarkReadArgs, validatePagination, validateSendMessageArgs };
581
+ export { type Actor, type ChatServices, type ConversationModel, type ConversationReadEvent, type ConversationsService, type CreateConversationArgs, type EnvironmentConfig, type IConversation, type IMessage, type InitOptions, type ListMessagesArgs, type MarkReadArgs, type MessageCreatedEvent, type MessageModel, type MessageServiceHooks, type MessageWithSender, type MessagesService, type PaginatedResult, type PresenceEvent, type RedisConfig, type RuntimeConfig, type SearchConversationsArgs, type SearchMessagesArgs, type SendMessageArgs, type SocketConfig$1 as SocketConfig, type SourceType, type Transport, type TransportConfig, type TypingEvent, createConversationId, createConversationModel, createConversationsService, createCursor, createMessageId, createMessageModel, createMessagesService, createModels, createPaginatedResponse, createThreadId, createTransport, ensureIndexes, generateId, getRedisConfig, getRuntimeConfig, initChat, modelRegistry, parseCursor, searchByParticipantPair, searchConversations, searchMessages, setRuntimeConfig, sourceType, validateCreateConversationArgs, validateInitOptions, validateMarkReadArgs, validatePagination, validateSendMessageArgs };