@open-wa/wa-automate 4.32.13 → 4.32.16
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/api/Client.d.ts +10 -2
- package/dist/api/Client.js +17 -1
- package/dist/cli/integrations/chatwoot.js +13 -9
- package/package.json +1 -1
package/dist/api/Client.d.ts
CHANGED
@@ -43,6 +43,7 @@ export declare class Client {
|
|
43
43
|
private _onLogoutCallbacks;
|
44
44
|
private _queues;
|
45
45
|
private _autoEmojiSet;
|
46
|
+
private _autoEmojiQ;
|
46
47
|
private _onLogoutSet;
|
47
48
|
/**
|
48
49
|
* This is used to track if a listener is already used via webhook. Before, webhooks used to be set once per listener. Now a listener can be set via multiple webhooks, or revoked from a specific webhook.
|
@@ -1063,13 +1064,20 @@ export declare class Client {
|
|
1063
1064
|
* @param messageId Message ID of the message you want to star
|
1064
1065
|
* @returns `true`
|
1065
1066
|
*/
|
1066
|
-
starMessage(messageId
|
1067
|
+
starMessage(messageId: MessageId): Promise<boolean>;
|
1067
1068
|
/**
|
1068
1069
|
* Unstar a message
|
1069
1070
|
* @param messageId Message ID of the message you want to unstar
|
1070
1071
|
* @returns `true`
|
1071
1072
|
*/
|
1072
|
-
unstarMessage(messageId
|
1073
|
+
unstarMessage(messageId: MessageId): Promise<boolean>;
|
1074
|
+
/**
|
1075
|
+
* React to a message
|
1076
|
+
* @param messageId Message ID of the message you want to react to
|
1077
|
+
* @param emoji 1 single emoji to add to the message as a reacion
|
1078
|
+
* @returns boolean
|
1079
|
+
*/
|
1080
|
+
react(messageId: MessageId, emoji: string): Promise<boolean>;
|
1073
1081
|
/**
|
1074
1082
|
*
|
1075
1083
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
package/dist/api/Client.js
CHANGED
@@ -92,6 +92,11 @@ class Client {
|
|
92
92
|
this._onLogoutCallbacks = [];
|
93
93
|
this._queues = {};
|
94
94
|
this._autoEmojiSet = false;
|
95
|
+
this._autoEmojiQ = new p_queue_1.default({
|
96
|
+
concurrency: 1,
|
97
|
+
intervalCap: 1,
|
98
|
+
carryoverConcurrencyCount: true
|
99
|
+
});
|
95
100
|
this._onLogoutSet = false;
|
96
101
|
/**
|
97
102
|
* This is used to track if a listener is already used via webhook. Before, webhooks used to be set once per listener. Now a listener can be set via multiple webhooks, or revoked from a specific webhook.
|
@@ -257,7 +262,7 @@ class Client {
|
|
257
262
|
const emojiId = message.body.replace(new RegExp(ident, 'g'), "");
|
258
263
|
if (!emojiId)
|
259
264
|
return;
|
260
|
-
|
265
|
+
yield this._autoEmojiQ.add(() => __awaiter(this, void 0, void 0, function* () { return this.sendEmoji(message.from, emojiId, message.id).catch(() => { }); }));
|
261
266
|
}
|
262
267
|
}));
|
263
268
|
this._autoEmojiSet = true;
|
@@ -2281,6 +2286,17 @@ class Client {
|
|
2281
2286
|
return yield this.pup(messageId => WAPI.unstarMessage(messageId), messageId);
|
2282
2287
|
});
|
2283
2288
|
}
|
2289
|
+
/**
|
2290
|
+
* React to a message
|
2291
|
+
* @param messageId Message ID of the message you want to react to
|
2292
|
+
* @param emoji 1 single emoji to add to the message as a reacion
|
2293
|
+
* @returns boolean
|
2294
|
+
*/
|
2295
|
+
react(messageId, emoji) {
|
2296
|
+
return __awaiter(this, void 0, void 0, function* () {
|
2297
|
+
return yield this.pup(({ messageId, emoji }) => WAPI.react(messageId, emoji), { messageId, emoji });
|
2298
|
+
});
|
2299
|
+
}
|
2284
2300
|
/**
|
2285
2301
|
*
|
2286
2302
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
@@ -16,6 +16,14 @@ exports.setupChatwootOutgoingMessageHandler = exports.chatwootMiddleware = void
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
17
17
|
const form_data_1 = __importDefault(require("form-data"));
|
18
18
|
const mime_types_1 = __importDefault(require("mime-types"));
|
19
|
+
const contactReg = {
|
20
|
+
//WID : chatwoot contact ID
|
21
|
+
"example@c.us": "1"
|
22
|
+
};
|
23
|
+
const convoReg = {
|
24
|
+
//WID : chatwoot conversation ID
|
25
|
+
"example@c.us": "1"
|
26
|
+
};
|
19
27
|
const chatwootMiddleware = (cliConfig, client) => {
|
20
28
|
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
21
29
|
const processMesssage = () => __awaiter(void 0, void 0, void 0, function* () {
|
@@ -35,6 +43,8 @@ const chatwootMiddleware = (cliConfig, client) => {
|
|
35
43
|
return;
|
36
44
|
const { attachments, content } = m;
|
37
45
|
const to = `${contact}@c.us`;
|
46
|
+
if (!convoReg[to])
|
47
|
+
convoReg[to] = body.conversation.id;
|
38
48
|
if ((attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0) {
|
39
49
|
//has attachments
|
40
50
|
const [firstAttachment, ...restAttachments] = attachments;
|
@@ -97,14 +107,6 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
97
107
|
headers: Object.assign({ api_access_token }, _headers)
|
98
108
|
});
|
99
109
|
};
|
100
|
-
const contactReg = {
|
101
|
-
//WID : chatwoot contact ID
|
102
|
-
"example@c.us": "1"
|
103
|
-
};
|
104
|
-
const convoReg = {
|
105
|
-
//WID : chatwoot conversation ID
|
106
|
-
"example@c.us": "1"
|
107
|
-
};
|
108
110
|
const { data: get_inbox } = yield cwReq(`inboxes/${resolvedInbox}`, 'get');
|
109
111
|
// const inboxId = `openwa_${sessionId}`
|
110
112
|
/**
|
@@ -132,7 +134,9 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
132
134
|
const getContactConversation = (number) => __awaiter(void 0, void 0, void 0, function* () {
|
133
135
|
try {
|
134
136
|
const { data } = yield cwReq(`contacts/${contactReg[number]}/conversations`, 'get');
|
135
|
-
|
137
|
+
const allContactConversations = data.payload.filter(c => c.inbox_id === resolvedInbox).sort((a, b) => a.id - b.id);
|
138
|
+
const [opened, notOpen] = [allContactConversations.filter(c => c.status === 'open'), allContactConversations.filter(c => c.status != 'open')];
|
139
|
+
return opened[0] || notOpen[0];
|
136
140
|
}
|
137
141
|
catch (error) {
|
138
142
|
return;
|
package/package.json
CHANGED