@open-wa/wa-automate 4.32.14 → 4.32.17

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.
@@ -1064,13 +1064,20 @@ export declare class Client {
1064
1064
  * @param messageId Message ID of the message you want to star
1065
1065
  * @returns `true`
1066
1066
  */
1067
- starMessage(messageId?: ChatId): Promise<boolean>;
1067
+ starMessage(messageId: MessageId): Promise<boolean>;
1068
1068
  /**
1069
1069
  * Unstar a message
1070
1070
  * @param messageId Message ID of the message you want to unstar
1071
1071
  * @returns `true`
1072
1072
  */
1073
- unstarMessage(messageId?: ChatId): Promise<boolean>;
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>;
1074
1081
  /**
1075
1082
  *
1076
1083
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
@@ -2130,6 +2130,7 @@ class Client {
2130
2130
  getGroupMembers(groupId) {
2131
2131
  return __awaiter(this, void 0, void 0, function* () {
2132
2132
  const membersIds = yield this.getGroupMembersId(groupId);
2133
+ logging_1.log.info("group members ids", membersIds);
2133
2134
  const actions = membersIds.map(memberId => {
2134
2135
  return this.getContact(memberId);
2135
2136
  });
@@ -2286,6 +2287,17 @@ class Client {
2286
2287
  return yield this.pup(messageId => WAPI.unstarMessage(messageId), messageId);
2287
2288
  });
2288
2289
  }
2290
+ /**
2291
+ * React to a message
2292
+ * @param messageId Message ID of the message you want to react to
2293
+ * @param emoji 1 single emoji to add to the message as a reacion
2294
+ * @returns boolean
2295
+ */
2296
+ react(messageId, emoji) {
2297
+ return __awaiter(this, void 0, void 0, function* () {
2298
+ return yield this.pup(({ messageId, emoji }) => WAPI.react(messageId, emoji), { messageId, emoji });
2299
+ });
2300
+ }
2289
2301
  /**
2290
2302
  *
2291
2303
  * [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
- return data.payload.filter(c => c.inbox_id === resolvedInbox).sort((a, b) => a.id - b.id)[0];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.32.14",
3
+ "version": "4.32.17",
4
4
  "licenseCheckUrl": "https://funcs.openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://funcs.openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",