wexa-chat 0.2.1 → 0.2.2
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 +32 -5
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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, source, kind?, parentMessageId?, rootThreadId? })`
|
|
124
|
+
- `sendMessage({ organizationId, conversationId, senderModel, senderId, text, source, kind?, parentMessageId?, rootThreadId?, connectorIds? })`
|
|
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,9 +209,9 @@ 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
|
-
###
|
|
212
|
+
### Sending messages and connectors
|
|
213
213
|
|
|
214
|
-
Messages
|
|
214
|
+
Messages include a required `source` field (array) to indicate one or more origins for a message. Valid values are enforced by an enum of strings:
|
|
215
215
|
|
|
216
216
|
```ts
|
|
217
217
|
export const sourceType = {
|
|
@@ -224,8 +224,35 @@ export const sourceType = {
|
|
|
224
224
|
export type SourceType = (typeof sourceType)[keyof typeof sourceType];
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
-
When sending a message via `sendMessage`, you must provide `source: SourceType[]`.
|
|
228
|
-
|
|
227
|
+
When sending a message via `sendMessage`, you must provide `source: SourceType[]`. For internal server‑generated messages, use `[sourceType.CORE]`.
|
|
228
|
+
|
|
229
|
+
If you include external connectors in the `source` (e.g., `linkedin`, `whatsapp`), you can optionally pass `connectorIds` to perform the external send and to persist identifiers for quick follow‑ups:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
await chat.services.messages.sendMessage({
|
|
233
|
+
organizationId: 'org-123',
|
|
234
|
+
conversationId: 'conv-456',
|
|
235
|
+
senderModel: 'User',
|
|
236
|
+
senderId: 'user-1',
|
|
237
|
+
text: 'Hello from Wexa',
|
|
238
|
+
source: [sourceType.CORE, sourceType.LINKEDIN, sourceType.WHATSAPP],
|
|
239
|
+
connectorIds: {
|
|
240
|
+
linkedin: { connectorId: 'ln-connector-1', contactId: 'https://linkedin.com/in/someone' },
|
|
241
|
+
whatsapp: { connectorId: 'wa-connector-1', contactId: '+1 234 567 8901' },
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Under the hood (`src/services/messages.service.ts`):
|
|
247
|
+
|
|
248
|
+
- LinkedIn: posts to the LinkedIn connector with `{ linkedin_url, text }`.
|
|
249
|
+
- WhatsApp: posts to the WhatsApp connector with `{ phone_numbers, text }` (phone is sanitized to remove spaces and a leading `+`).
|
|
250
|
+
- Each external task runs concurrently. A successful task's `source` remains in the stored message. Failures are collected into a `failed_source` array attached to the returned message instance at runtime: `message.failed_source: Array<{ source: string; message: string }>`.
|
|
251
|
+
- The conversation document is updated with last message metadata and, when applicable, with connector identifiers:
|
|
252
|
+
- `lastLinkedInId: string` — set from `connectorIds.linkedin.contactId` when `source` includes `linkedin`.
|
|
253
|
+
- `lastWhatsAppId: string` — set from a sanitized `connectorIds.whatsapp.contactId` when `source` includes `whatsapp`.
|
|
254
|
+
|
|
255
|
+
This allows subsequent UI actions to prefill the last known contact handles for LinkedIn and WhatsApp.
|
|
229
256
|
|
|
230
257
|
## Models
|
|
231
258
|
|
package/dist/index.d.cts
CHANGED
|
@@ -259,6 +259,8 @@ interface IConversation extends Document {
|
|
|
259
259
|
lastMessagePreview?: string;
|
|
260
260
|
lastMessageSenderId?: string;
|
|
261
261
|
lastMessageSenderModel?: string;
|
|
262
|
+
lastLinkedInId?: string;
|
|
263
|
+
lastWhatsAppId?: string;
|
|
262
264
|
metadata?: Record<string, any>;
|
|
263
265
|
createdAt: Date;
|
|
264
266
|
updatedAt: Date;
|
package/dist/index.d.ts
CHANGED
|
@@ -259,6 +259,8 @@ interface IConversation extends Document {
|
|
|
259
259
|
lastMessagePreview?: string;
|
|
260
260
|
lastMessageSenderId?: string;
|
|
261
261
|
lastMessageSenderModel?: string;
|
|
262
|
+
lastLinkedInId?: string;
|
|
263
|
+
lastWhatsAppId?: string;
|
|
262
264
|
metadata?: Record<string, any>;
|
|
263
265
|
createdAt: Date;
|
|
264
266
|
updatedAt: Date;
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,8 @@ function createConversationModel(options, conn) {
|
|
|
70
70
|
lastMessagePreview: String,
|
|
71
71
|
lastMessageSenderId: String,
|
|
72
72
|
lastMessageSenderModel: String,
|
|
73
|
+
lastLinkedInId: String,
|
|
74
|
+
lastWhatsAppId: String,
|
|
73
75
|
metadata: Schema.Types.Mixed
|
|
74
76
|
},
|
|
75
77
|
{ timestamps: true }
|
|
@@ -549,8 +551,11 @@ function createMessagesService(models, hooks = {}) {
|
|
|
549
551
|
const success_source = ["core"];
|
|
550
552
|
const failed_source = [];
|
|
551
553
|
const tasks = [];
|
|
554
|
+
let lastLinkedInId;
|
|
555
|
+
let lastWhatsAppId;
|
|
552
556
|
if (Array.isArray(source) && source.includes("linkedin")) {
|
|
553
557
|
const LinkedinConnector = connectorIds && connectorIds.linkedin;
|
|
558
|
+
lastLinkedInId = LinkedinConnector == null ? void 0 : LinkedinConnector.connectorId;
|
|
554
559
|
if (LinkedinConnector) {
|
|
555
560
|
tasks.push({
|
|
556
561
|
name: "linkedin",
|
|
@@ -568,6 +573,7 @@ function createMessagesService(models, hooks = {}) {
|
|
|
568
573
|
}
|
|
569
574
|
if (Array.isArray(source) && source.includes("whatsapp")) {
|
|
570
575
|
const whatsappConnector = connectorIds && connectorIds.whatsapp;
|
|
576
|
+
lastWhatsAppId = whatsappConnector == null ? void 0 : whatsappConnector.connectorId;
|
|
571
577
|
if (whatsappConnector) {
|
|
572
578
|
tasks.push({
|
|
573
579
|
name: "whatsapp",
|
|
@@ -613,13 +619,16 @@ function createMessagesService(models, hooks = {}) {
|
|
|
613
619
|
rootThreadId: rootThreadId || parentMessageId
|
|
614
620
|
});
|
|
615
621
|
await message.save();
|
|
622
|
+
const conversationUpdate = {
|
|
623
|
+
lastMessageAt: message.createdAt,
|
|
624
|
+
lastMessagePreview: text.substring(0, 100),
|
|
625
|
+
lastMessageSenderId: senderId,
|
|
626
|
+
lastMessageSenderModel: senderModel
|
|
627
|
+
};
|
|
628
|
+
if (lastLinkedInId) conversationUpdate.lastLinkedInId = lastLinkedInId;
|
|
629
|
+
if (lastWhatsAppId) conversationUpdate.lastWhatsAppId = lastWhatsAppId;
|
|
616
630
|
await Conversation.findByIdAndUpdate(conversationId, {
|
|
617
|
-
$set:
|
|
618
|
-
lastMessageAt: message.createdAt,
|
|
619
|
-
lastMessagePreview: text.substring(0, 100),
|
|
620
|
-
lastMessageSenderId: senderId,
|
|
621
|
-
lastMessageSenderModel: senderModel
|
|
622
|
-
}
|
|
631
|
+
$set: conversationUpdate
|
|
623
632
|
});
|
|
624
633
|
if (onMessageCreated) {
|
|
625
634
|
onMessageCreated(message);
|