wexa-chat 0.2.6 → 0.2.9
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/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +30 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -247,6 +247,22 @@ type SearchConversationsArgs = {
|
|
|
247
247
|
cursor?: string;
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Represents a successful chat start response
|
|
252
|
+
*/
|
|
253
|
+
interface ChatStartedResponse {
|
|
254
|
+
object: 'ChatStarted';
|
|
255
|
+
chat_id: string;
|
|
256
|
+
message_id: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Common response type for chat API operations
|
|
260
|
+
*/
|
|
261
|
+
type ChatApiResponse = ChatStartedResponse | {
|
|
262
|
+
error: string;
|
|
263
|
+
details?: unknown;
|
|
264
|
+
};
|
|
265
|
+
|
|
250
266
|
interface IConversation extends Document {
|
|
251
267
|
organizationId: string;
|
|
252
268
|
participants: Array<{
|
|
@@ -582,4 +598,4 @@ interface ChatServices {
|
|
|
582
598
|
*/
|
|
583
599
|
declare function initChat(mongooseInstance: typeof mongoose, options: InitOptions, server?: Server): Promise<ChatServices>;
|
|
584
600
|
|
|
585
|
-
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 };
|
|
601
|
+
export { type Actor, type ChatApiResponse, type ChatServices, type ChatStartedResponse, 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
|
@@ -247,6 +247,22 @@ type SearchConversationsArgs = {
|
|
|
247
247
|
cursor?: string;
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Represents a successful chat start response
|
|
252
|
+
*/
|
|
253
|
+
interface ChatStartedResponse {
|
|
254
|
+
object: 'ChatStarted';
|
|
255
|
+
chat_id: string;
|
|
256
|
+
message_id: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Common response type for chat API operations
|
|
260
|
+
*/
|
|
261
|
+
type ChatApiResponse = ChatStartedResponse | {
|
|
262
|
+
error: string;
|
|
263
|
+
details?: unknown;
|
|
264
|
+
};
|
|
265
|
+
|
|
250
266
|
interface IConversation extends Document {
|
|
251
267
|
organizationId: string;
|
|
252
268
|
participants: Array<{
|
|
@@ -582,4 +598,4 @@ interface ChatServices {
|
|
|
582
598
|
*/
|
|
583
599
|
declare function initChat(mongooseInstance: typeof mongoose, options: InitOptions, server?: Server): Promise<ChatServices>;
|
|
584
600
|
|
|
585
|
-
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 };
|
|
601
|
+
export { type Actor, type ChatApiResponse, type ChatServices, type ChatStartedResponse, 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.js
CHANGED
|
@@ -555,6 +555,8 @@ function createMessagesService(models, hooks = {}) {
|
|
|
555
555
|
const tasks = [];
|
|
556
556
|
let lastLinkedInId;
|
|
557
557
|
let lastWhatsAppId;
|
|
558
|
+
let linkedinChatId;
|
|
559
|
+
let whatsappChatId;
|
|
558
560
|
if (Array.isArray(source) && source.includes("linkedin")) {
|
|
559
561
|
const LinkedinConnector = connectorIds && connectorIds.linkedin;
|
|
560
562
|
lastLinkedInId = LinkedinConnector == null ? void 0 : LinkedinConnector.connectorId;
|
|
@@ -563,10 +565,18 @@ function createMessagesService(models, hooks = {}) {
|
|
|
563
565
|
name: "linkedin",
|
|
564
566
|
run: async () => {
|
|
565
567
|
const path = paths.linkedin.startChat(String(LinkedinConnector.connectorId));
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
try {
|
|
569
|
+
const res = await getAxios().post(path, {
|
|
570
|
+
linkedin_url: LinkedinConnector.contactId,
|
|
571
|
+
text
|
|
572
|
+
});
|
|
573
|
+
const data = res.data;
|
|
574
|
+
console.log("linkedinChatId", data);
|
|
575
|
+
linkedinChatId = data.chat_data.chat_id;
|
|
576
|
+
return { status: "fulfilled", value: data };
|
|
577
|
+
} catch (error) {
|
|
578
|
+
return { status: "rejected", reason: error };
|
|
579
|
+
}
|
|
570
580
|
}
|
|
571
581
|
});
|
|
572
582
|
} else {
|
|
@@ -587,7 +597,14 @@ function createMessagesService(models, hooks = {}) {
|
|
|
587
597
|
phone_numbers: sanitize(raw),
|
|
588
598
|
text
|
|
589
599
|
};
|
|
590
|
-
|
|
600
|
+
try {
|
|
601
|
+
const res = await getAxios().post(path, body);
|
|
602
|
+
const data = res.data;
|
|
603
|
+
whatsappChatId = data.chat_id;
|
|
604
|
+
return { status: "fulfilled", value: data };
|
|
605
|
+
} catch (error) {
|
|
606
|
+
return { status: "rejected", reason: error };
|
|
607
|
+
}
|
|
591
608
|
}
|
|
592
609
|
});
|
|
593
610
|
} else {
|
|
@@ -596,22 +613,21 @@ function createMessagesService(models, hooks = {}) {
|
|
|
596
613
|
}
|
|
597
614
|
if (tasks.length > 0) {
|
|
598
615
|
const results = await Promise.allSettled(tasks.map((t) => t.run()));
|
|
599
|
-
results.forEach((
|
|
616
|
+
results.forEach((result, idx) => {
|
|
617
|
+
var _a, _b, _c, _d, _e, _f;
|
|
600
618
|
const name = tasks[idx].name;
|
|
601
|
-
if (
|
|
619
|
+
if (result.status === "fulfilled") {
|
|
602
620
|
success_source.push(name);
|
|
603
621
|
} else {
|
|
604
|
-
const
|
|
605
|
-
res.reason.response.data.detail || res.reason.response.data || "Unknown error";
|
|
622
|
+
const error = ((_c = (_b = (_a = result.reason) == null ? void 0 : _a.response) == null ? void 0 : _b.data) == null ? void 0 : _c.detail) || ((_e = (_d = result.reason) == null ? void 0 : _d.response) == null ? void 0 : _e.data) || ((_f = result.reason) == null ? void 0 : _f.message) || "Unknown error";
|
|
606
623
|
failed_source.push({
|
|
607
624
|
source: name,
|
|
608
|
-
message: typeof
|
|
625
|
+
message: typeof error === "string" ? error : JSON.stringify(error)
|
|
609
626
|
});
|
|
627
|
+
console.error(`${name} failed:`, error);
|
|
610
628
|
}
|
|
611
629
|
});
|
|
612
|
-
console.log("results", results);
|
|
613
630
|
}
|
|
614
|
-
console.log("success_source", success_source);
|
|
615
631
|
const message = new Message({
|
|
616
632
|
organizationId,
|
|
617
633
|
conversationId,
|
|
@@ -632,6 +648,8 @@ function createMessagesService(models, hooks = {}) {
|
|
|
632
648
|
};
|
|
633
649
|
if (lastLinkedInId) conversationUpdate.lastLinkedInId = lastLinkedInId;
|
|
634
650
|
if (lastWhatsAppId) conversationUpdate.lastWhatsAppId = lastWhatsAppId;
|
|
651
|
+
if (linkedinChatId) conversationUpdate.linkedinChatId = linkedinChatId;
|
|
652
|
+
if (whatsappChatId) conversationUpdate.whatsappChatId = whatsappChatId;
|
|
635
653
|
await Conversation.findByIdAndUpdate(conversationId, {
|
|
636
654
|
$set: conversationUpdate
|
|
637
655
|
});
|