@wppconnect/server 1.8.2 → 1.8.4

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/CHANGELOG.md CHANGED
@@ -1,228 +1,137 @@
1
- ## 1.8.2 (2023-01-13)
2
-
1
+ ## 1.8.4 (2023-02-19)
3
2
 
4
3
  ### Bug Fixes
5
4
 
6
- * Fixed send message to groups (close [#1049](https://github.com/wppconnect-team/wppconnect-server/issues/1049)) ([f8bc6e4](https://github.com/wppconnect-team/wppconnect-server/commit/f8bc6e4ee14b36e266b86bcf9998acf96629019f))
5
+ - **deps:** update dependency @wppconnect-team/wppconnect to ^1.22.0 ([#1104](https://github.com/wppconnect-team/wppconnect-server/issues/1104)) ([b444adb](https://github.com/wppconnect-team/wppconnect-server/commit/b444adbe9b5e135ba327e4f7cce6b8b623deedde))
7
6
 
7
+ ## 1.8.3 (2023-02-03)
8
8
 
9
+ ## 1.8.2 (2023-01-13)
9
10
 
10
- ## 1.8.1 (2022-12-28)
11
+ ### Bug Fixes
11
12
 
13
+ - Fixed send message to groups (close [#1049](https://github.com/wppconnect-team/wppconnect-server/issues/1049)) ([f8bc6e4](https://github.com/wppconnect-team/wppconnect-server/commit/f8bc6e4ee14b36e266b86bcf9998acf96629019f))
12
14
 
15
+ ## 1.8.1 (2022-12-28)
13
16
 
14
17
  # 1.8.0 (2022-12-15)
15
18
 
16
-
17
-
18
19
  ## 1.7.4 (2022-12-12)
19
20
 
20
-
21
21
  ### Bug Fixes
22
22
 
23
- * Fixed return undefined on sendListMsg ([eb830ce](https://github.com/wppconnect-team/wppconnect-server/commit/eb830cee97384a0c9a84db8abc0d5f75ea688c86))
24
-
25
-
23
+ - Fixed return undefined on sendListMsg ([eb830ce](https://github.com/wppconnect-team/wppconnect-server/commit/eb830cee97384a0c9a84db8abc0d5f75ea688c86))
26
24
 
27
25
  ## 1.7.3 (2022-12-03)
28
26
 
29
-
30
-
31
27
  ## 1.7.2 (2022-11-18)
32
28
 
33
-
34
29
  ### Bug Fixes
35
30
 
36
- * **deps:** update dependency @wppconnect-team/wppconnect to ^1.19.1 ([#988](https://github.com/wppconnect-team/wppconnect-server/issues/988)) ([1c391e0](https://github.com/wppconnect-team/wppconnect-server/commit/1c391e00e65e70356de26b286e423a649f0ef7af))
37
-
38
-
31
+ - **deps:** update dependency @wppconnect-team/wppconnect to ^1.19.1 ([#988](https://github.com/wppconnect-team/wppconnect-server/issues/988)) ([1c391e0](https://github.com/wppconnect-team/wppconnect-server/commit/1c391e00e65e70356de26b286e423a649f0ef7af))
39
32
 
40
33
  ## 1.7.1 (2022-11-02)
41
34
 
42
-
43
-
44
35
  # 1.7.0 (2022-11-02)
45
36
 
46
-
47
-
48
37
  ## 1.6.4 (2022-10-20)
49
38
 
50
-
51
-
52
39
  ## 1.6.3 (2022-10-10)
53
40
 
54
-
55
41
  ### Bug Fixes
56
42
 
57
- * **deps:** update dependency @wppconnect-team/wppconnect to ^1.17.1 ([#931](https://github.com/wppconnect-team/wppconnect-server/issues/931)) ([04326bf](https://github.com/wppconnect-team/wppconnect-server/commit/04326bf1a142d07d8ca63a807211b407023898d1))
58
-
59
-
43
+ - **deps:** update dependency @wppconnect-team/wppconnect to ^1.17.1 ([#931](https://github.com/wppconnect-team/wppconnect-server/issues/931)) ([04326bf](https://github.com/wppconnect-team/wppconnect-server/commit/04326bf1a142d07d8ca63a807211b407023898d1))
60
44
 
61
45
  ## 1.6.2 (2022-08-09)
62
46
 
63
-
64
47
  ### Bug Fixes
65
48
 
66
- * **deps:** update dependency @wppconnect-team/wppconnect to ^1.16.1 ([#866](https://github.com/wppconnect-team/wppconnect-server/issues/866)) ([a824339](https://github.com/wppconnect-team/wppconnect-server/commit/a8243392f8daadef5dec2205263d5a44840ae4ef))
67
-
68
-
49
+ - **deps:** update dependency @wppconnect-team/wppconnect to ^1.16.1 ([#866](https://github.com/wppconnect-team/wppconnect-server/issues/866)) ([a824339](https://github.com/wppconnect-team/wppconnect-server/commit/a8243392f8daadef5dec2205263d5a44840ae4ef))
69
50
 
70
51
  ## 1.6.1 (2022-08-05)
71
52
 
72
-
73
53
  ### Bug Fixes
74
54
 
75
- * **deps:** update dependency @wppconnect-team/wppconnect to ^1.16.0 ([#860](https://github.com/wppconnect-team/wppconnect-server/issues/860)) ([5f72973](https://github.com/wppconnect-team/wppconnect-server/commit/5f72973788d2844d2297acd73b96e76001b70c37))
76
-
77
-
55
+ - **deps:** update dependency @wppconnect-team/wppconnect to ^1.16.0 ([#860](https://github.com/wppconnect-team/wppconnect-server/issues/860)) ([5f72973](https://github.com/wppconnect-team/wppconnect-server/commit/5f72973788d2844d2297acd73b96e76001b70c37))
78
56
 
79
57
  # 1.6.0 (2022-07-20)
80
58
 
81
-
82
-
83
59
  # 1.5.0 (2022-07-12)
84
60
 
85
-
86
61
  ### Features
87
62
 
88
- * Delete all chats close [#483](https://github.com/wppconnect-team/wppconnect-server/issues/483) ([f47a253](https://github.com/wppconnect-team/wppconnect-server/commit/f47a253b1024778f9c3ed5d14a638689be464936))
89
-
90
-
63
+ - Delete all chats close [#483](https://github.com/wppconnect-team/wppconnect-server/issues/483) ([f47a253](https://github.com/wppconnect-team/wppconnect-server/commit/f47a253b1024778f9c3ed5d14a638689be464936))
91
64
 
92
65
  # 1.4.0 (2022-06-29)
93
66
 
94
-
95
-
96
67
  ## 1.3.4 (2022-06-20)
97
68
 
98
-
99
-
100
69
  ## 1.3.3 (2022-06-01)
101
70
 
102
-
103
-
104
71
  ## 1.3.2 (2022-05-31)
105
72
 
106
-
107
-
108
73
  ## 1.3.1 (2022-05-10)
109
74
 
110
-
111
-
112
75
  # 1.3.0 (2022-05-10)
113
76
 
114
-
115
77
  ### Features
116
78
 
117
- * Updated all packages ([5e7b9f2](https://github.com/wppconnect-team/wppconnect-server/commit/5e7b9f2240ccc0e44a129296e92dd6fb5393380e))
118
-
119
-
79
+ - Updated all packages ([5e7b9f2](https://github.com/wppconnect-team/wppconnect-server/commit/5e7b9f2240ccc0e44a129296e92dd6fb5393380e))
120
80
 
121
81
  # 1.2.0 (2022-04-25)
122
82
 
123
-
124
-
125
83
  ## 1.1.23 (2022-03-13)
126
84
 
127
-
128
-
129
85
  ## 1.1.22 (2022-03-07)
130
86
 
131
-
132
-
133
87
  ## 1.1.21 (2022-02-24)
134
88
 
135
-
136
-
137
89
  ## 1.1.20 (2022-01-23)
138
90
 
139
-
140
-
141
91
  ## 1.1.19 (2022-01-21)
142
92
 
143
-
144
-
145
93
  ## 1.1.18 (2022-01-17)
146
94
 
147
-
148
-
149
95
  ## 1.1.17 (2022-01-16)
150
96
 
151
-
152
-
153
97
  ## 1.1.16 (2022-01-14)
154
98
 
155
-
156
-
157
99
  ## 1.1.15 (2022-01-09)
158
100
 
159
-
160
-
161
101
  ## 1.1.14 (2021-12-21)
162
102
 
163
-
164
-
165
103
  ## 1.1.13 (2021-12-09)
166
104
 
167
-
168
-
169
105
  ## 1.1.12 (2021-12-09)
170
106
 
171
-
172
-
173
107
  ## 1.1.11 (2021-11-16)
174
108
 
175
-
176
-
177
109
  ## 1.1.10 (2021-11-12)
178
110
 
179
-
180
-
181
111
  ## 1.1.9 (2021-11-08)
182
112
 
183
-
184
-
185
113
  ## 1.1.8 (2021-11-08)
186
114
 
187
-
188
-
189
115
  ## 1.1.7 (2021-10-21)
190
116
 
191
-
192
-
193
117
  ## 1.1.6 (2021-10-13)
194
118
 
195
-
196
119
  ### Bug Fixes
197
120
 
198
- * block/unblock contato. ([9401b16](https://github.com/wppconnect-team/wppconnect-server/commit/9401b168ce08eb62c5ea392db82df34b69753775))
199
-
200
-
121
+ - block/unblock contato. ([9401b16](https://github.com/wppconnect-team/wppconnect-server/commit/9401b168ce08eb62c5ea392db82df34b69753775))
201
122
 
202
123
  ## 1.1.5 (2021-10-01)
203
124
 
204
-
205
-
206
125
  ## 1.1.4 (2021-09-22)
207
126
 
208
-
209
-
210
127
  ## 1.1.3 (2021-08-13)
211
128
 
212
-
213
-
214
129
  ## 1.1.2 (2021-08-11)
215
130
 
216
-
217
-
218
131
  ## 1.1.1 (2021-08-06)
219
132
 
220
-
221
-
222
133
  # 1.1.0 (2021-08-04)
223
134
 
224
-
225
-
226
135
  ## 1.0.3 (2021-07-15)
227
136
 
228
137
  ## 1.0.2 (2021-07-14)
package/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:14-alpine as base
1
+ FROM node:lts-alpine3.16 as base
2
2
  WORKDIR /usr/src/wpp-server
3
3
  ENV NODE_ENV=production PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
4
4
  COPY package.json yarn.lock ./
@@ -22,4 +22,4 @@ RUN yarn cache clean
22
22
  COPY . .
23
23
  COPY --from=build /usr/src/wpp-server/ /usr/src/wpp-server/
24
24
  EXPOSE 21465
25
- ENTRYPOINT ["node", "dist/server.js"]
25
+ ENTRYPOINT ["node", "dist/server.js"]
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Downloads](https://img.shields.io/npm/dm/@wppconnect/server.svg)](https://www.npmjs.com/package/@wppconnect/server)
8
8
  [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/wppconnect-team/wppconnect-server.svg)](https://isitmaintained.com/project/wppconnect-team/wppconnect-server 'Average time to resolve an issue')
9
9
  [![Percentage of issues still open](https://isitmaintained.com/badge/open/wppconnect-team/wppconnect-server.svg)](https://isitmaintained.com/badge/open/wppconnect-team/wppconnect-server.svg 'Percentage of issues still open')
10
- [![Build Status](https://img.shields.io/github/workflow/status/wppconnect-team/wppconnect-server/build.svg)](https://github.com/wppconnect-team/wppconnect-serer/actions)
10
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/wppconnect-team/wppconnect-server/build.yml)](https://github.com/wppconnect-team/wppconnect-serer/actions)
11
11
  [![Build](https://github.com/wppconnect-team/wppconnect-server/actions/workflows/build.yml/badge.svg)](https://github.com/wppconnect-team/wppconnect-server/actions/workflows/build.yml)
12
12
  [![release-it](https://img.shields.io/badge/%F0%9F%93%A6%F0%9F%9A%80-release--it-e10079.svg)](https://github.com/release-it/release-it)
13
13
 
@@ -23,7 +23,7 @@ Wppconnect Server is a ready-to-use API, just download, install, and start using
23
23
 
24
24
  [![Discord](https://img.shields.io/discord/844351092758413353?color=blueviolet&label=Discord&logo=discord&style=flat)](https://discord.gg/JU5JGGKGNG)
25
25
  [![Telegram Group](https://img.shields.io/badge/Telegram-Group-32AFED?logo=telegram)](https://t.me/wppconnect)
26
- [![WhatsApp Group](https://img.shields.io/badge/WhatsApp-Group-25D366?logo=whatsapp)](https://chat.whatsapp.com/C1ChjyShl5cA7KvmtecF3L)
26
+ [![WhatsApp Group](https://img.shields.io/badge/WhatsApp-Group-25D366?logo=whatsapp)](https://chat.whatsapp.com/LJaQu6ZyNvnBPNAVRbX00K)
27
27
  [![YouTube](https://img.shields.io/youtube/channel/subscribers/UCD7J9LG08PmGQrF5IS7Yv9A?label=YouTube)](https://www.youtube.com/c/wppconnect)
28
28
 
29
29
  ## Documentations
@@ -1,4 +1,19 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.addProductImage = addProductImage;exports.changeProductImage = changeProductImage;exports.createCollection = createCollection;exports.delProducts = delProducts;exports.deleteCollection = deleteCollection;exports.editCollection = editCollection;exports.editProduct = editProduct;exports.getCollections = getCollections;exports.getProductById = getProductById;exports.getProducts = getProducts;exports.removeProductImage = removeProductImage;exports.setProductVisibility = setProductVisibility;exports.updateCartEnabled = updateCartEnabled; /*
1
+ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.addProductImage = addProductImage;exports.changeProductImage = changeProductImage;exports.createCollection = createCollection;exports.delProducts = delProducts;exports.deleteCollection = deleteCollection;exports.editCollection = editCollection;exports.editProduct = editProduct;exports.getCollections = getCollections;exports.getProductById = getProductById;exports.getProducts = getProducts;exports.removeProductImage = removeProductImage;exports.sendLinkCatalog = sendLinkCatalog;exports.setProductVisibility = setProductVisibility;exports.updateCartEnabled = updateCartEnabled;
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+ var _functions = require("../util/functions"); /*
2
17
  * Copyright 2021 WPPConnect Team
3
18
  *
4
19
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,20 +27,7 @@
12
27
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
28
  * See the License for the specific language governing permissions and
14
29
  * limitations under the License.
15
- */
16
- async function getProducts(req, res) {
17
- const { phone, qnt } = req.query;
18
- if (!phone)
19
- return res.status(401).send({
20
- message: 'Please send the contact number you wish to return the products.'
21
- });
22
-
23
- try {
24
- const result = await req.client.getProducts(phone, qnt);
25
- res.status(201).json({ status: 'success', response: result });
26
- } catch (error) {
27
- res.status(500).json({ status: 'Error', message: 'Error on get products', error: error });
28
- }
30
+ */async function getProducts(req, res) {const { phone, qnt } = req.query;if (!phone) return res.status(401).send({ message: 'Please send the contact number you wish to return the products.' });try {const result = await req.client.getProducts(phone, qnt);res.status(201).json({ status: 'success', response: result });} catch (error) {res.status(500).json({ status: 'Error', message: 'Error on get products', error: error });}
29
31
  }
30
32
 
31
33
  async function getProductById(req, res) {
@@ -42,6 +44,7 @@ async function getProductById(req, res) {
42
44
  res.status(500).json({ status: 'Error', message: 'Error on get product', error: error });
43
45
  }
44
46
  }
47
+
45
48
  async function editProduct(req, res) {
46
49
  const { id, options } = req.body;
47
50
  if (!id || !options)
@@ -200,10 +203,38 @@ async function updateCartEnabled(req, res) {
200
203
  });
201
204
 
202
205
  try {
203
- const result = await req.client.setProductVisibility(enabled);
206
+ const result = await req.client.updateCartEnabled(enabled);
204
207
  res.status(201).json({ status: 'success', response: result });
205
208
  } catch (error) {
206
209
  res.status(500).json({ status: 'Error', message: 'Error on set enabled cart.', error: error });
207
210
  }
208
211
  }
212
+
213
+ async function sendLinkCatalog(req, res) {
214
+ const { phones, message } = req.body;
215
+ if (!phones)
216
+ return res.status(401).send({
217
+ message: 'phones was not informed'
218
+ });
219
+ const results = [];
220
+ try {
221
+ const session = await req.client.getWid();
222
+ const catalogLink = (0, _functions.createCatalogLink)(session);
223
+ for (const phone of phones) {
224
+ const result = await req.client.sendText(phone, `${message} ${catalogLink}`, {
225
+ useTemplateButtons: true,
226
+ buttons: [
227
+ {
228
+ url: catalogLink,
229
+ text: 'Abrir catálogo'
230
+ }]
231
+
232
+ });
233
+ results.push({ phone, status: result.id });
234
+ }
235
+ return res.status(200).json({ status: 'success', response: results });
236
+ } catch (error) {
237
+ res.status(500).json({ status: 'Error', message: 'Error on set enabled cart.', error: error });
238
+ }
239
+ }
209
240
  //# sourceMappingURL=catalogController.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalogController.js","names":["getProducts","req","res","phone","qnt","query","status","send","message","result","client","json","response","error","getProductById","id","editProduct","options","body","delProducts","changeProductImage","base64","addProductImage","removeProductImage","index","getCollections","max","createCollection","name","products","editCollection","deleteCollection","setProductVisibility","value","updateCartEnabled","enabled"],"sources":["../../src/controller/catalogController.js"],"sourcesContent":["/*\n * Copyright 2021 WPPConnect Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport async function getProducts(req, res) {\n const { phone, qnt } = req.query;\n if (!phone)\n return res.status(401).send({\n message: 'Please send the contact number you wish to return the products.',\n });\n\n try {\n const result = await req.client.getProducts(phone, qnt);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on get products', error: error });\n }\n}\n\nexport async function getProductById(req, res) {\n const { phone, id } = req.query;\n if (!phone || !id)\n return res.status(401).send({\n message: 'Please send the contact number and productId.',\n });\n\n try {\n const result = await req.client.getProductById(phone, id);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on get product', error: error });\n }\n}\nexport async function editProduct(req, res) {\n const { id, options } = req.body;\n if (!id || !options)\n return res.status(401).send({\n message: 'productId or options was not informed',\n });\n\n try {\n const result = await req.client.editProduct(id, options);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on edit product.', error: error });\n }\n}\n\nexport async function delProducts(req, res) {\n const { id } = req.body;\n if (!id)\n return res.status(401).send({\n message: 'products Id was not informed',\n });\n\n try {\n const result = await req.client.delProducts(id);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on delete product.', error: error });\n }\n}\n\nexport async function changeProductImage(req, res) {\n const { id, base64 } = req.body;\n if (!id || !base64)\n return res.status(401).send({\n message: 'productId and base64 was not informed',\n });\n\n try {\n const result = await req.client.changeProductImage(id, base64);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on change product image.', error: error });\n }\n}\n\nexport async function addProductImage(req, res) {\n const { id, base64 } = req.body;\n if (!id || !base64)\n return res.status(401).send({\n message: 'productId and base64 was not informed',\n });\n\n try {\n const result = await req.client.addProductImage(id, base64);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on add product image.', error: error });\n }\n}\n\nexport async function removeProductImage(req, res) {\n const { id, index } = req.body;\n if (!id || !index)\n return res.status(401).send({\n message: 'productId and index image was not informed',\n });\n\n try {\n const result = await req.client.addProductImage(id, index);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on remove product image.', error: error });\n }\n}\n\nexport async function getCollections(req, res) {\n const { phone, qnt, max } = req.query;\n if (!phone)\n return res.status(401).send({\n message: 'phone was not informed',\n });\n\n try {\n const result = await req.client.getCollections(phone, qnt, max);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on get collections.', error: error });\n }\n}\n\nexport async function createCollection(req, res) {\n const { name, products } = req.body;\n if (!name || !products)\n return res.status(401).send({\n message: 'name or products was not informed',\n });\n\n try {\n const result = await req.client.createCollection(name, products);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on create collection.', error: error });\n }\n}\n\nexport async function editCollection(req, res) {\n const { id, options } = req.body;\n if (!id || !options)\n return res.status(401).send({\n message: 'id or options was not informed',\n });\n\n try {\n const result = await req.client.createCollection(id, options);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on edit collection.', error: error });\n }\n}\n\nexport async function deleteCollection(req, res) {\n const { id } = req.body;\n if (!id)\n return res.status(401).send({\n message: 'id was not informed',\n });\n\n try {\n const result = await req.client.deleteCollection(id);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on delete collection.', error: error });\n }\n}\n\nexport async function setProductVisibility(req, res) {\n const { id, value } = req.body;\n if (!id || !value)\n return res.status(401).send({\n message: 'product id or value (false, true) was not informed',\n });\n\n try {\n const result = await req.client.setProductVisibility(id, value);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on set product visibility.', error: error });\n }\n}\n\nexport async function updateCartEnabled(req, res) {\n const { enabled } = req.body;\n if (!enabled)\n return res.status(401).send({\n message: 'enabled (false, true) was not informed',\n });\n\n try {\n const result = await req.client.setProductVisibility(enabled);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on set enabled cart.', error: error });\n }\n}\n"],"mappings":"8mBAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,WAAW,CAACC,GAAG,EAAEC,GAAG,EAAE;EAC1C,MAAM,EAAEC,KAAK,EAA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EC,GAAG,EAAE;EAChD,MAAM,EAAEiC,OAAO,CAAC,CAAC,GAAGlC,GAAG,CAACiB,IAAI;EAC5B,IAAI,CAACiB,OAAO;EACV,OAAOjC,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;IAC1BC,OAAO,EAAE;EACX,CAAC,CAAC;;EAEJ,IAAI;IACF,MAAMC,MAAM,GAAG,MAAMR,GAAG,CAACS,MAAM,CAACsB,oBAAoB,CAACG,OAAO,CAAC;IAC7DjC,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACK,IAAI,CAAC,EAAEL,MAAM,EAAE,SAAS,EAAEM,QAAQ,EAAEH,MAAM,CAAC,CAAC,CAAC;EAC/D,CAAC,CAAC,OAAOI,KAAK,EAAE;IACdX,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACK,IAAI,CAAC,EAAEL,MAAM,EAAE,OAAO,EAAEE,OAAO,EAAE,4BAA4B,EAAEK,KAAK,EAAEA,KAAK,CAAC,CAAC,CAAC;EAChG;AACF"}
1
+ {"version":3,"file":"catalogController.js","names":["getProducts","req","res","phone","qnt","query","status","send","message","result","client","json","response","error","getProductById","id","editProduct","options","body","delProducts","changeProductImage","base64","addProductImage","removeProductImage","index","getCollections","max","createCollection","name","products","editCollection","deleteCollection","setProductVisibility","value","updateCartEnabled","enabled","sendLinkCatalog","phones","results","session","getWid","catalogLink","createCatalogLink","sendText","useTemplateButtons","buttons","url","text","push"],"sources":["../../src/controller/catalogController.js"],"sourcesContent":["/*\n * Copyright 2021 WPPConnect Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createCatalogLink, groupNameToArray } from '../util/functions';\n\nexport async function getProducts(req, res) {\n const { phone, qnt } = req.query;\n if (!phone)\n return res.status(401).send({\n message: 'Please send the contact number you wish to return the products.',\n });\n\n try {\n const result = await req.client.getProducts(phone, qnt);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on get products', error: error });\n }\n}\n\nexport async function getProductById(req, res) {\n const { phone, id } = req.query;\n if (!phone || !id)\n return res.status(401).send({\n message: 'Please send the contact number and productId.',\n });\n\n try {\n const result = await req.client.getProductById(phone, id);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on get product', error: error });\n }\n}\n\nexport async function editProduct(req, res) {\n const { id, options } = req.body;\n if (!id || !options)\n return res.status(401).send({\n message: 'productId or options was not informed',\n });\n\n try {\n const result = await req.client.editProduct(id, options);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on edit product.', error: error });\n }\n}\n\nexport async function delProducts(req, res) {\n const { id } = req.body;\n if (!id)\n return res.status(401).send({\n message: 'products Id was not informed',\n });\n\n try {\n const result = await req.client.delProducts(id);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on delete product.', error: error });\n }\n}\n\nexport async function changeProductImage(req, res) {\n const { id, base64 } = req.body;\n if (!id || !base64)\n return res.status(401).send({\n message: 'productId and base64 was not informed',\n });\n\n try {\n const result = await req.client.changeProductImage(id, base64);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on change product image.', error: error });\n }\n}\n\nexport async function addProductImage(req, res) {\n const { id, base64 } = req.body;\n if (!id || !base64)\n return res.status(401).send({\n message: 'productId and base64 was not informed',\n });\n\n try {\n const result = await req.client.addProductImage(id, base64);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on add product image.', error: error });\n }\n}\n\nexport async function removeProductImage(req, res) {\n const { id, index } = req.body;\n if (!id || !index)\n return res.status(401).send({\n message: 'productId and index image was not informed',\n });\n\n try {\n const result = await req.client.addProductImage(id, index);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on remove product image.', error: error });\n }\n}\n\nexport async function getCollections(req, res) {\n const { phone, qnt, max } = req.query;\n if (!phone)\n return res.status(401).send({\n message: 'phone was not informed',\n });\n\n try {\n const result = await req.client.getCollections(phone, qnt, max);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on get collections.', error: error });\n }\n}\n\nexport async function createCollection(req, res) {\n const { name, products } = req.body;\n if (!name || !products)\n return res.status(401).send({\n message: 'name or products was not informed',\n });\n\n try {\n const result = await req.client.createCollection(name, products);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on create collection.', error: error });\n }\n}\n\nexport async function editCollection(req, res) {\n const { id, options } = req.body;\n if (!id || !options)\n return res.status(401).send({\n message: 'id or options was not informed',\n });\n\n try {\n const result = await req.client.createCollection(id, options);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on edit collection.', error: error });\n }\n}\n\nexport async function deleteCollection(req, res) {\n const { id } = req.body;\n if (!id)\n return res.status(401).send({\n message: 'id was not informed',\n });\n\n try {\n const result = await req.client.deleteCollection(id);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on delete collection.', error: error });\n }\n}\n\nexport async function setProductVisibility(req, res) {\n const { id, value } = req.body;\n if (!id || !value)\n return res.status(401).send({\n message: 'product id or value (false, true) was not informed',\n });\n\n try {\n const result = await req.client.setProductVisibility(id, value);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on set product visibility.', error: error });\n }\n}\n\nexport async function updateCartEnabled(req, res) {\n const { enabled } = req.body;\n if (!enabled)\n return res.status(401).send({\n message: 'enabled (false, true) was not informed',\n });\n\n try {\n const result = await req.client.updateCartEnabled(enabled);\n res.status(201).json({ status: 'success', response: result });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on set enabled cart.', error: error });\n }\n}\n\nexport async function sendLinkCatalog(req, res) {\n const { phones, message } = req.body;\n if (!phones)\n return res.status(401).send({\n message: 'phones was not informed',\n });\n const results = [];\n try {\n const session = await req.client.getWid();\n const catalogLink = createCatalogLink(session);\n for (const phone of phones) {\n const result = await req.client.sendText(phone, `${message} ${catalogLink}`, {\n useTemplateButtons: true,\n buttons: [\n {\n url: catalogLink,\n text: 'Abrir catálogo',\n },\n ],\n });\n results.push({ phone, status: result.id });\n }\n return res.status(200).json({ status: 'success', response: results });\n } catch (error) {\n res.status(500).json({ status: 'Error', message: 'Error on set enabled cart.', error: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,8CAAwE,CAfxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAGO,eAAeA,WAAW,CAACC,GAAG,EAAEC,GAAG,EAAE,CAC1C,MAAM,EAAEC,KAAK,EAAEC,GAAG,CAAC,CAAC,GAAGH,GAAG,CAACI,KAAK,CAChC,IAAI,CAACF,KAAK,EACR,OAAOD,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAC1BC,OAAO,EAAE,iEAAiE,CAC5E,CAAC,CAAC,CAEJ,IAAI,CACF,MAAMC,MAAM,GAAG,MAAMR,GAAG,CAACS,MAAM,CAACV,WAAW,CAACG,KAAK,EAAEC,GAAG,CAAC,CACvDF,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACK,IAAI,CAAC,EAAEL,MAAM,EAAE,SAAS,EAAEM,QAAQ,EAAEH,MAAM,CAAC,CAAC,CAAC,CAC/D,CAAC,CAAC,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OzB,KAAK,EAAE;IACdX,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACK,IAAI,CAAC,EAAEL,MAAM,EAAE,OAAO,EAAEE,OAAO,EAAE,4BAA4B,EAAEK,KAAK,EAAEA,KAAK,CAAC,CAAC,CAAC;EAChG;AACF"}
@@ -20,7 +20,8 @@ var _getAllTokens = _interopRequireDefault(require("../util/getAllTokens"));
20
20
  var _fs = _interopRequireDefault(require("fs"));
21
21
  var _mimeTypes = _interopRequireDefault(require("mime-types"));
22
22
  var _package = require("../../package.json");
23
- var _qrcode = _interopRequireDefault(require("qrcode")); /*
23
+ var _qrcode = _interopRequireDefault(require("qrcode"));
24
+ var _config = _interopRequireDefault(require("../config.json")); /*
24
25
  * Copyright 2021 WPPConnect Team
25
26
  *
26
27
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -154,13 +155,21 @@ async function startSession(req, res) {
154
155
 
155
156
  async function closeSession(req, res) {
156
157
  const session = req.session;
158
+ const { clearSession = true } = req.body;
157
159
  try {
158
160
  if (_sessionUtil.clientsArray[session].status === null) {
159
161
  return await res.status(200).json({ status: true, message: 'Session successfully closed' });
160
162
  } else {
161
163
  _sessionUtil.clientsArray[session] = { status: null };
162
- await req.client.close();
163
164
 
165
+ if (clearSession) {
166
+ let sessionFolder = `${_config.default.customUserDataDir}/${session}`;
167
+ if (_fs.default.existsSync(sessionFolder)) {
168
+ console.log('Deletando pasta: ' + sessionFolder);
169
+ _fs.default.rmdirSync(sessionFolder, { recursive: true });
170
+ }
171
+ }
172
+ await req.client.close();
164
173
  req.io.emit('whatsapp-status', false);
165
174
  (0, _functions.callWebHook)(req.client, req, 'closesession', {
166
175
  message: `Session: ${session} disconnected`,
@@ -1 +1 @@
1
- {"version":3,"file":"sessionController.js","names":["SessionUtil","CreateSessionUtil","downloadFileFunction","message","client","logger","buffer","decryptFile","filename","t","fs","existsSync","result","type","mime","extension","mimetype","writeFile","err","error","e","warn","downloadMedia","download","path","replace","startAllSessions","req","res","secretkey","params","authorization","token","headers","tokenDecrypt","undefined","split","allSessions","getAllTokens","serverOptions","secretKey","status","json","response","map","session","util","opendata","showAllSessions","arr","Object","keys","clientsArray","forEach","item","push","startSession","waitQrCode","body","getSessionState","closeSession","close","io","emit","callWebHook","connected","logOutSession","logout","checkConnectionSession","isConnected","downloadMediaByMessage","messageId","isMedia","getMessageById","isMMS","base64","toString","getMediaByMessage","ex","qr","urlcode","QRCode","toDataURL","qrcode","version","getQrCode","img","Buffer","from","writeHead","length","end","killServiceWorker","restartService","subscribePresence","phone","isGroup","all","contacts","groups","getAllGroups","p","id","_serialized","chats","getAllContacts","c","contato","contactToArray"],"sources":["../../src/controller/sessionController.js"],"sourcesContent":["/*\n * Copyright 2021 WPPConnect Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientsArray } from '../util/sessionUtil';\nimport { callWebHook, contactToArray } from '../util/functions';\nimport CreateSessionUtil from '../util/createSessionUtil';\nimport getAllTokens from '../util/getAllTokens';\nimport fs from 'fs';\nimport mime from 'mime-types';\nimport { version } from '../../package.json';\nimport QRCode from 'qrcode';\n\nconst SessionUtil = new CreateSessionUtil();\n\nasync function downloadFileFunction(message, client, logger) {\n try {\n const buffer = await client.decryptFile(message);\n\n let filename = `./WhatsAppImages/file${message.t}`;\n if (!fs.existsSync(filename)) {\n let result = '';\n if (message.type === 'ptt') {\n result = `${filename}.oga`;\n } else {\n result = `${filename}.${mime.extension(message.mimetype)}`;\n }\n\n await fs.writeFile(result, buffer, (err) => {\n if (err) {\n logger.error(err);\n }\n });\n\n return result;\n } else {\n return `${filename}.${mime.extension(message.mimetype)}`;\n }\n } catch (e) {\n logger.error(e);\n logger.warn('Erro ao descriptografar a midia, tentando fazer o download direto...');\n try {\n const buffer = await client.downloadMedia(message);\n const filename = `./WhatsAppImages/file${message.t}`;\n if (!fs.existsSync(filename)) {\n let result = '';\n if (message.type === 'ptt') {\n result = `${filename}.oga`;\n } else {\n result = `${filename}.${mime.extension(message.mimetype)}`;\n }\n\n await fs.writeFile(result, buffer, (err) => {\n if (err) {\n logger.error(err);\n }\n });\n\n return result;\n } else {\n return `${filename}.${mime.extension(message.mimetype)}`;\n }\n } catch (e) {\n logger.error(e);\n logger.warn('Não foi possível baixar a mídia...');\n }\n }\n}\n\nexport async function download(message, client, logger) {\n try {\n const path = await downloadFileFunction(message, client, logger);\n return path.replace('./', '');\n } catch (e) {\n logger.error(e);\n }\n}\n\nexport async function startAllSessions(req, res) {\n const { secretkey } = req.params;\n const { authorization: token } = req.headers;\n\n let tokenDecrypt = '';\n\n if (secretkey === undefined) {\n tokenDecrypt = token.split(' ')[0];\n } else {\n tokenDecrypt = secretkey;\n }\n\n const allSessions = await getAllTokens(req);\n\n if (tokenDecrypt !== req.serverOptions.secretKey) {\n return res.status(400).json({\n response: 'error',\n message: 'The token is incorrect',\n });\n }\n\n allSessions.map(async (session) => {\n const util = new CreateSessionUtil();\n await util.opendata(req, session);\n });\n\n return await res.status(201).json({ status: 'success', message: 'Starting all sessions' });\n}\n\nexport async function showAllSessions(req, res) {\n const { secretkey } = req.params;\n const { authorization: token } = req.headers;\n\n let tokenDecrypt = '';\n\n if (secretkey === undefined) {\n tokenDecrypt = token.split(' ')[0];\n } else {\n tokenDecrypt = secretkey;\n }\n\n const arr = [];\n\n if (tokenDecrypt !== req.serverOptions.secretKey) {\n return res.status(400).json({\n response: false,\n message: 'The token is incorrect',\n });\n }\n\n Object.keys(clientsArray).forEach((item) => {\n arr.push({ session: item });\n });\n\n return res.status(200).json({ response: arr });\n}\n\nexport async function startSession(req, res) {\n const session = req.session;\n const { waitQrCode = false } = req.body;\n\n await getSessionState(req, res);\n await SessionUtil.opendata(req, session, waitQrCode ? res : null);\n}\n\nexport async function closeSession(req, res) {\n const session = req.session;\n try {\n if (clientsArray[session].status === null) {\n return await res.status(200).json({ status: true, message: 'Session successfully closed' });\n } else {\n clientsArray[session] = { status: null };\n await req.client.close();\n\n req.io.emit('whatsapp-status', false);\n callWebHook(req.client, req, 'closesession', {\n message: `Session: ${session} disconnected`,\n connected: false,\n });\n\n return await res.status(200).json({ status: true, message: 'Session successfully closed' });\n }\n } catch (error) {\n req.logger.error(error);\n return await res.status(500).json({ status: false, message: 'Error closing session', error });\n }\n}\n\nexport async function logOutSession(req, res) {\n try {\n const session = req.session;\n await req.client.logout();\n\n req.io.emit('whatsapp-status', false);\n callWebHook(req.client, req, 'logoutsession', {\n message: `Session: ${session} logged out`,\n connected: false,\n });\n\n return await res.status(200).json({ status: true, message: 'Session successfully closed' });\n } catch (error) {\n req.logger.error(error);\n return await res.status(500).json({ status: false, message: 'Error closing session', error });\n }\n}\n\nexport async function checkConnectionSession(req, res) {\n try {\n await req.client.isConnected();\n\n return res.status(200).json({ status: true, message: 'Connected' });\n } catch (error) {\n return res.status(200).json({ status: false, message: 'Disconnected' });\n }\n}\n\nexport async function downloadMediaByMessage(req, res) {\n const client = req.client;\n const { messageId } = req.body;\n\n let message;\n\n try {\n if (!messageId.isMedia || !messageId.type) {\n message = await client.getMessageById(messageId);\n } else {\n message = messageId;\n }\n\n if (!message)\n return res.status(400).json({\n status: 'error',\n message: 'Message not found',\n });\n\n if (!(message['mimetype'] || message.isMedia || message.isMMS))\n return res.status(400).json({\n status: 'error',\n message: 'Message does not contain media',\n });\n\n const buffer = await client.decryptFile(message);\n\n return res.status(200).json({ base64: buffer.toString('base64'), mimetype: message.mimetype });\n } catch (e) {\n req.logger.error(e);\n return res.status(400).json({\n status: 'error',\n message: 'Decrypt file error',\n error: e,\n });\n }\n}\n\nexport async function getMediaByMessage(req, res) {\n const client = req.client;\n const { messageId } = req.params;\n\n try {\n const message = await client.getMessageById(messageId);\n\n if (!message)\n return res.status(400).json({\n status: 'error',\n message: 'Message not found',\n });\n\n if (!(message['mimetype'] || message.isMedia || message.isMMS))\n return res.status(400).json({\n status: 'error',\n message: 'Message does not contain media',\n });\n\n const buffer = await client.decryptFile(message);\n\n return res.status(200).json({ base64: buffer.toString('base64'), mimetype: message.mimetype });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'The session is not active', error: ex });\n }\n}\n\nexport async function getSessionState(req, res) {\n try {\n const { waitQrCode = false } = req.body;\n const client = req.client;\n const qr = client?.urlcode != null && client?.urlcode != '' ? await QRCode.toDataURL(client.urlcode) : null;\n\n if ((client == null || client.status == null) && !waitQrCode)\n return res.status(200).json({ status: 'CLOSED', qrcode: null });\n else if (client != null)\n return res.status(200).json({\n status: client.status,\n qrcode: qr,\n urlcode: client.urlcode,\n version: version,\n });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'The session is not active', error: ex });\n }\n}\n\nexport async function getQrCode(req, res) {\n try {\n if (req.client.urlcode) {\n const qr = req.client.urlcode ? await QRCode.toDataURL(req.client.urlcode) : null;\n const img = Buffer.from(qr.replace(/^data:image\\/(png|jpeg|jpg);base64,/, ''), 'base64');\n\n res.writeHead(200, {\n 'Content-Type': 'image/png',\n 'Content-Length': img.length,\n });\n res.end(img);\n } else {\n return res.status(200).json({ status: req.client.status, message: 'QRCode is not available...' });\n }\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'Error retrieving QRCode', error: ex });\n }\n}\n\nexport async function killServiceWorker(req, res) {\n try {\n return res.status(200).json({ status: 'success', response: req.client.killServiceWorker() });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'The session is not active', error: ex });\n }\n}\n\nexport async function restartService(req, res) {\n try {\n return res.status(200).json({ status: 'success', response: req.client.restartService() });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', response: { message: 'The session is not active', error: ex } });\n }\n}\n\nexport async function subscribePresence(req, res) {\n try {\n const { phone, isGroup = false, all = false } = req.body;\n\n if (all) {\n let contacts;\n if (isGroup) {\n const groups = await req.client.getAllGroups(false);\n contacts = groups.map((p) => p.id._serialized);\n } else {\n const chats = await req.client.getAllContacts();\n contacts = chats.map((c) => c.id._serialized);\n }\n await req.client.subscribePresence(contacts);\n } else\n for (const contato of contactToArray(phone, isGroup)) {\n await req.client.subscribePresence(contato);\n }\n\n return await res.status(200).json({ status: 'success', response: { message: 'Subscribe presence executed' } });\n } catch (error) {\n return await res.status(500).json({ status: 'error', message: 'Error on subscribe presence', error: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wDAA4B,CAtB5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAUA,MAAMA,WAAW,GAAG,IAAIC,0BAAiB,EAAE,CAE3C,eAAeC,oBAAoB,CAACC,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAE,CAC3D,IAAI,CACF,MAAMC,MAAM,GAAG,MAAMF,MAAM,CAACG,WAAW,CAACJ,OAAO,CAAC,CAEhD,IAAIK,QAAQ,GAAI,wBAAuBL,OAAO,CAACM,CAAE,EAAC,CAClD,IAAI,CAACC,WAAE,CAACC,UAAU,CAACH,QAAQ,CAAC,EAAE,CAC5B,IAAII,MAAM,GAAG,EAAE,CACf,IAAIT,OAAO,CAACU,IAAI,KAAK,KAAK,EAAE,CAC1BD,MAAM,GAAI,GAAEJ,QAAS,MAAK,CAC5B,CAAC,MAAM,CACLI,MAAM,GAAI,GAAEJ,QAAS,IAAGM,kBAAI,CAACC,SAAS,CAACZ,OAAO,CAACa,QAAQ,CAAE,EAAC;MAC5D;;MAEA,MAAMN,WAAE,CAACO,SAAS,CAACL,MAAM,EAAEN,MAAM,EAAE,CAACY,GAAG,KAAK;QAC1C,IAAIA,GAAG,EAA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,GAAG,CAAC,CAACyD,CAAC,KAAKA,CAAC,CAACC,EAAE,CAACC,WAAW,CAAC;MAChD,CAAC,MAAM;QACL,MAAMC,KAAK,GAAG,MAAM7E,GAAG,CAACvB,MAAM,CAACqG,cAAc,EAAE;QAC/CP,QAAQ,GAAGM,KAAK,CAAC5D,GAAG,CAAC,CAAC8D,CAAC,KAAKA,CAAC,CAACJ,EAAE,CAACC,WAAW,CAAC;MAC/C;MACA,MAAM5E,GAAG,CAACvB,MAAM,CAAC0F,iBAAiB,CAACI,QAAQ,CAAC;IAC9C,CAAC;IACC,KAAK,MAAMS,OAAO,IAAI,IAAAC,yBAAc,EAACb,KAAK,EAAEC,OAAO,CAAC,EAAE;MACpD,MAAMrE,GAAG,CAACvB,MAAM,CAAC0F,iBAAiB,CAACa,OAAO,CAAC;IAC7C;;IAEF,OAAO,MAAM/E,GAAG,CAACa,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAED,MAAM,EAAE,SAAS,EAAEE,QAAQ,EAAE,EAAExC,OAAO,EAAE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC;EAChH,CAAC,CAAC,OAAOgB,KAAK,EAAE;IACd,OAAO,MAAMS,GAAG,CAACa,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAED,MAAM,EAAE,OAAO,EAAEtC,OAAO,EAAE,6BAA6B,EAAEgB,KAAK,EAAEA,KAAK,CAAC,CAAC,CAAC;EAC9G;AACF"}
1
+ {"version":3,"file":"sessionController.js","names":["SessionUtil","CreateSessionUtil","downloadFileFunction","message","client","logger","buffer","decryptFile","filename","t","fs","existsSync","result","type","mime","extension","mimetype","writeFile","err","error","e","warn","downloadMedia","download","path","replace","startAllSessions","req","res","secretkey","params","authorization","token","headers","tokenDecrypt","undefined","split","allSessions","getAllTokens","serverOptions","secretKey","status","json","response","map","session","util","opendata","showAllSessions","arr","Object","keys","clientsArray","forEach","item","push","startSession","waitQrCode","body","getSessionState","closeSession","clearSession","sessionFolder","config","customUserDataDir","console","log","rmdirSync","recursive","close","io","emit","callWebHook","connected","logOutSession","logout","checkConnectionSession","isConnected","downloadMediaByMessage","messageId","isMedia","getMessageById","isMMS","base64","toString","getMediaByMessage","ex","qr","urlcode","QRCode","toDataURL","qrcode","version","getQrCode","img","Buffer","from","writeHead","length","end","killServiceWorker","restartService","subscribePresence","phone","isGroup","all","contacts","groups","getAllGroups","p","id","_serialized","chats","getAllContacts","c","contato","contactToArray"],"sources":["../../src/controller/sessionController.js"],"sourcesContent":["/*\n * Copyright 2021 WPPConnect Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientsArray } from '../util/sessionUtil';\nimport { callWebHook, contactToArray } from '../util/functions';\nimport CreateSessionUtil from '../util/createSessionUtil';\nimport getAllTokens from '../util/getAllTokens';\nimport fs from 'fs';\nimport mime from 'mime-types';\nimport { version } from '../../package.json';\nimport QRCode from 'qrcode';\nimport config from '../config.json';\n\nconst SessionUtil = new CreateSessionUtil();\n\nasync function downloadFileFunction(message, client, logger) {\n try {\n const buffer = await client.decryptFile(message);\n\n let filename = `./WhatsAppImages/file${message.t}`;\n if (!fs.existsSync(filename)) {\n let result = '';\n if (message.type === 'ptt') {\n result = `${filename}.oga`;\n } else {\n result = `${filename}.${mime.extension(message.mimetype)}`;\n }\n\n await fs.writeFile(result, buffer, (err) => {\n if (err) {\n logger.error(err);\n }\n });\n\n return result;\n } else {\n return `${filename}.${mime.extension(message.mimetype)}`;\n }\n } catch (e) {\n logger.error(e);\n logger.warn('Erro ao descriptografar a midia, tentando fazer o download direto...');\n try {\n const buffer = await client.downloadMedia(message);\n const filename = `./WhatsAppImages/file${message.t}`;\n if (!fs.existsSync(filename)) {\n let result = '';\n if (message.type === 'ptt') {\n result = `${filename}.oga`;\n } else {\n result = `${filename}.${mime.extension(message.mimetype)}`;\n }\n\n await fs.writeFile(result, buffer, (err) => {\n if (err) {\n logger.error(err);\n }\n });\n\n return result;\n } else {\n return `${filename}.${mime.extension(message.mimetype)}`;\n }\n } catch (e) {\n logger.error(e);\n logger.warn('Não foi possível baixar a mídia...');\n }\n }\n}\n\nexport async function download(message, client, logger) {\n try {\n const path = await downloadFileFunction(message, client, logger);\n return path.replace('./', '');\n } catch (e) {\n logger.error(e);\n }\n}\n\nexport async function startAllSessions(req, res) {\n const { secretkey } = req.params;\n const { authorization: token } = req.headers;\n\n let tokenDecrypt = '';\n\n if (secretkey === undefined) {\n tokenDecrypt = token.split(' ')[0];\n } else {\n tokenDecrypt = secretkey;\n }\n\n const allSessions = await getAllTokens(req);\n\n if (tokenDecrypt !== req.serverOptions.secretKey) {\n return res.status(400).json({\n response: 'error',\n message: 'The token is incorrect',\n });\n }\n\n allSessions.map(async (session) => {\n const util = new CreateSessionUtil();\n await util.opendata(req, session);\n });\n\n return await res.status(201).json({ status: 'success', message: 'Starting all sessions' });\n}\n\nexport async function showAllSessions(req, res) {\n const { secretkey } = req.params;\n const { authorization: token } = req.headers;\n\n let tokenDecrypt = '';\n\n if (secretkey === undefined) {\n tokenDecrypt = token.split(' ')[0];\n } else {\n tokenDecrypt = secretkey;\n }\n\n const arr = [];\n\n if (tokenDecrypt !== req.serverOptions.secretKey) {\n return res.status(400).json({\n response: false,\n message: 'The token is incorrect',\n });\n }\n\n Object.keys(clientsArray).forEach((item) => {\n arr.push({ session: item });\n });\n\n return res.status(200).json({ response: arr });\n}\n\nexport async function startSession(req, res) {\n const session = req.session;\n const { waitQrCode = false } = req.body;\n\n await getSessionState(req, res);\n await SessionUtil.opendata(req, session, waitQrCode ? res : null);\n}\n\nexport async function closeSession(req, res) {\n const session = req.session;\n const { clearSession = true } = req.body;\n try {\n if (clientsArray[session].status === null) {\n return await res.status(200).json({ status: true, message: 'Session successfully closed' });\n } else {\n clientsArray[session] = { status: null };\n\n if (clearSession) {\n let sessionFolder = `${config.customUserDataDir}/${session}`;\n if (fs.existsSync(sessionFolder)) {\n console.log('Deletando pasta: ' + sessionFolder);\n fs.rmdirSync(sessionFolder, { recursive: true });\n }\n }\n await req.client.close();\n req.io.emit('whatsapp-status', false);\n callWebHook(req.client, req, 'closesession', {\n message: `Session: ${session} disconnected`,\n connected: false,\n });\n\n return await res.status(200).json({ status: true, message: 'Session successfully closed' });\n }\n } catch (error) {\n req.logger.error(error);\n return await res.status(500).json({ status: false, message: 'Error closing session', error });\n }\n}\n\nexport async function logOutSession(req, res) {\n try {\n const session = req.session;\n await req.client.logout();\n\n req.io.emit('whatsapp-status', false);\n callWebHook(req.client, req, 'logoutsession', {\n message: `Session: ${session} logged out`,\n connected: false,\n });\n\n return await res.status(200).json({ status: true, message: 'Session successfully closed' });\n } catch (error) {\n req.logger.error(error);\n return await res.status(500).json({ status: false, message: 'Error closing session', error });\n }\n}\n\nexport async function checkConnectionSession(req, res) {\n try {\n await req.client.isConnected();\n\n return res.status(200).json({ status: true, message: 'Connected' });\n } catch (error) {\n return res.status(200).json({ status: false, message: 'Disconnected' });\n }\n}\n\nexport async function downloadMediaByMessage(req, res) {\n const client = req.client;\n const { messageId } = req.body;\n\n let message;\n\n try {\n if (!messageId.isMedia || !messageId.type) {\n message = await client.getMessageById(messageId);\n } else {\n message = messageId;\n }\n\n if (!message)\n return res.status(400).json({\n status: 'error',\n message: 'Message not found',\n });\n\n if (!(message['mimetype'] || message.isMedia || message.isMMS))\n return res.status(400).json({\n status: 'error',\n message: 'Message does not contain media',\n });\n\n const buffer = await client.decryptFile(message);\n\n return res.status(200).json({ base64: buffer.toString('base64'), mimetype: message.mimetype });\n } catch (e) {\n req.logger.error(e);\n return res.status(400).json({\n status: 'error',\n message: 'Decrypt file error',\n error: e,\n });\n }\n}\n\nexport async function getMediaByMessage(req, res) {\n const client = req.client;\n const { messageId } = req.params;\n\n try {\n const message = await client.getMessageById(messageId);\n\n if (!message)\n return res.status(400).json({\n status: 'error',\n message: 'Message not found',\n });\n\n if (!(message['mimetype'] || message.isMedia || message.isMMS))\n return res.status(400).json({\n status: 'error',\n message: 'Message does not contain media',\n });\n\n const buffer = await client.decryptFile(message);\n\n return res.status(200).json({ base64: buffer.toString('base64'), mimetype: message.mimetype });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'The session is not active', error: ex });\n }\n}\n\nexport async function getSessionState(req, res) {\n try {\n const { waitQrCode = false } = req.body;\n const client = req.client;\n const qr = client?.urlcode != null && client?.urlcode != '' ? await QRCode.toDataURL(client.urlcode) : null;\n\n if ((client == null || client.status == null) && !waitQrCode)\n return res.status(200).json({ status: 'CLOSED', qrcode: null });\n else if (client != null)\n return res.status(200).json({\n status: client.status,\n qrcode: qr,\n urlcode: client.urlcode,\n version: version,\n });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'The session is not active', error: ex });\n }\n}\n\nexport async function getQrCode(req, res) {\n try {\n if (req.client.urlcode) {\n const qr = req.client.urlcode ? await QRCode.toDataURL(req.client.urlcode) : null;\n const img = Buffer.from(qr.replace(/^data:image\\/(png|jpeg|jpg);base64,/, ''), 'base64');\n\n res.writeHead(200, {\n 'Content-Type': 'image/png',\n 'Content-Length': img.length,\n });\n res.end(img);\n } else {\n return res.status(200).json({ status: req.client.status, message: 'QRCode is not available...' });\n }\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'Error retrieving QRCode', error: ex });\n }\n}\n\nexport async function killServiceWorker(req, res) {\n try {\n return res.status(200).json({ status: 'success', response: req.client.killServiceWorker() });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', message: 'The session is not active', error: ex });\n }\n}\n\nexport async function restartService(req, res) {\n try {\n return res.status(200).json({ status: 'success', response: req.client.restartService() });\n } catch (ex) {\n req.logger.error(ex);\n return res.status(500).json({ status: 'error', response: { message: 'The session is not active', error: ex } });\n }\n}\n\nexport async function subscribePresence(req, res) {\n try {\n const { phone, isGroup = false, all = false } = req.body;\n\n if (all) {\n let contacts;\n if (isGroup) {\n const groups = await req.client.getAllGroups(false);\n contacts = groups.map((p) => p.id._serialized);\n } else {\n const chats = await req.client.getAllContacts();\n contacts = chats.map((c) => c.id._serialized);\n }\n await req.client.subscribePresence(contacts);\n } else\n for (const contato of contactToArray(phone, isGroup)) {\n await req.client.subscribePresence(contato);\n }\n\n return await res.status(200).json({ status: 'success', response: { message: 'Subscribe presence executed' } });\n } catch (error) {\n return await res.status(500).json({ status: 'error', message: 'Error on subscribe presence', error: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gEAAoC,CAvBpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAWA,MAAMA,WAAW,GAAG,IAAIC,0BAAiB,EAAE,CAE3C,eAAeC,oBAAoB,CAACC,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAE,CAC3D,IAAI,CACF,MAAMC,MAAM,GAAG,MAAMF,MAAM,CAACG,WAAW,CAACJ,OAAO,CAAC,CAEhD,IAAIK,QAAQ,GAAI,wBAAuBL,OAAO,CAACM,CAAE,EAAC,CAClD,IAAI,CAACC,WAAE,CAACC,UAAU,CAACH,QAAQ,CAAC,EAAE,CAC5B,IAAII,MAAM,GAAG,EAAE,CACf,IAAIT,OAAO,CAACU,IAAI,KAAK,KAAK,EAAE,CAC1BD,MAAM,GAAI,GAAEJ,QAAS,MAAK,CAC5B,CAAC,MAAM,CACLI,MAAM,GAAI,GAAEJ,QAAS,IAAGM,kBAAI,CAACC,SAAS,CAACZ,OAAO,CAACa,QAAQ,CAAE,EAAC;MAC5D;;MAEA,MAAMN,WAAE,CAACO,SAAS,CAACL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,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAED,MAAM,EAAE,OAAO,EAAEtC,OAAO,EAAE,6BAA6B,EAAEgB,KAAK,EAAEA,KAAK,CAAC,CAAC,CAAC;EAC9G;AACF"}
@@ -21,7 +21,7 @@ async function convert(prefix, data, event) {
21
21
 
22
22
  async function config_event(prefix, event) {
23
23
  try {
24
- let { default: mappConf } = await Promise.resolve(`./${prefix}${event}.js`).then((s) => _interopRequireWildcard(require(s)));
24
+ let { default: mappConf } = await ((specifier) => new Promise((r) => r(specifier)).then((s) => _interopRequireWildcard(require(s))))(`./${prefix}${event}.js`);
25
25
  if (!mappConf) return undefined;
26
26
  return mappConf;
27
27
  } catch (e) {
@@ -31,7 +31,7 @@ async function config_event(prefix, event) {
31
31
 
32
32
  async function config_type(prefix, event, type) {
33
33
  try {
34
- let { default: mappConf } = await Promise.resolve(`./${prefix}${event}-${type}.js`).then((s) => _interopRequireWildcard(require(s)));
34
+ let { default: mappConf } = await ((specifier) => new Promise((r) => r(specifier)).then((s) => _interopRequireWildcard(require(s))))(`./${prefix}${event}-${type}.js`);
35
35
  if (!mappConf) return undefined;
36
36
  return mappConf;
37
37
  } catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["convert","prefix","data","event","indexOf","mappConfEvent","config_event","mappConfType","config_type","type","Object","assign","mapper","e","default","mappConf","undefined"],"sources":["../../src/mapper/index.js"],"sourcesContent":["import mapper from 'json-mapper-json';\n\nexport async function convert(prefix, data, event) {\n try {\n data.event = event || data.event;\n event = data.event.indexOf('message') >= 0 ? 'message' : data.event;\n\n let mappConfEvent = await config_event(prefix, event);\n let mappConfType = await config_type(prefix, event, data.type);\n\n Object.assign(mappConfEvent, mappConfType);\n\n // console.log('mappConfEvent', mappConfEvent);\n\n if (!mappConfEvent) return data;\n return await mapper(data, mappConfEvent);\n } catch (e) {\n return data;\n }\n}\n\nasync function config_event(prefix, event) {\n try {\n let { default: mappConf } = await import(`./${prefix}${event}.js`);\n if (!mappConf) return undefined;\n return mappConf;\n } catch (e) {\n return undefined;\n }\n}\n\nasync function config_type(prefix, event, type) {\n try {\n let { default: mappConf } = await import(`./${prefix}${event}-${type}.js`);\n if (!mappConf) return undefined;\n return mappConf;\n } catch (e) {\n return undefined;\n }\n}\n"],"mappings":"0LAAA,0EAAsC;;AAE/B,eAAeA,OAAO,CAACC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE;EACjD,IAAI;IACFD,IAAI,CAACC,KAAK,GAAGA,KAAK,IAAID,IAAI,CAACC,KAAK;IAChCA,KAAK,GAAGD,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,GAAGF,IAAI,CAACC,KAAK;;IAEnE,IAAIE,aAAa,GAAG,MAAMC,YAAY,CAACL,MAAM,EAAEE,KAAK,CAAC;IACrD,IAAII,YAAY,GAAG,MAAMC,WAAW,CAACP,MAAM,EAAEE,KAAK,EAAED,IAAI,CAACO,IAAI,CAAC;;IAE9DC,MAAM,CAACC,MAAM,CAACN,aAAa,EAAEE,YAAY,CAAC;;IAE1C;;IAEA,IAAI,CAACF,aAAa,EAAE,OAAOH,IAAI;IAC/B,OAAO,MAAM,IAAAU,uBAAM,EAACV,IAAI,EAAEG,aAAa,CAAC;EAC1C,CAAC,CAAC,OAAOQ,CAAC,EAAE;IACV,OAAOX,IAAI;EACb;AACF;;AAEA,eAAeI,YAAY,CAACL,MAAM,EAAEE,KAAK,EAAE;EACzC,IAAI;IACF,IAAI,EAAEW,OAAO,EAAEC,QAAQ,CAAC,CAAC,GAAG,sBAAc,KAAId,MAAO,GAAEE,KAAM,KAAI,kDAAC;IAClE,IAAI,CAACY,QAAQ,EAAE,OAAOC,SAAS;IAC/B,OAAOD,QAAQ;EACjB,CAAC,CAAC,OAAOF,CAAC,EAAE;IACV,OAAOG,SAAS;EAClB;AACF;;AAEA,eAAeR,WAAW,CAACP,MAAM,EAAEE,KAAK,EAAEM,IAAI,EAAE;EAC9C,IAAI;IACF,IAAI,EAAEK,OAAO,EAAEC,QAAQ,CAAC,CAAC,GAAG,sBAAc,KAAId,MAAO,GAAEE,KAAM,IAAGM,IAAK,KAAI,kDAAC;IAC1E,IAAI,CAACM,QAAQ,EAAE,OAAOC,SAAS;IAC/B,OAAOD,QAAQ;EACjB,CAAC,CAAC,OAAOF,CAAC,EAAE;IACV,OAAOG,SAAS;EAClB;AACF"}
1
+ {"version":3,"file":"index.js","names":["convert","prefix","data","event","indexOf","mappConfEvent","config_event","mappConfType","config_type","type","Object","assign","mapper","e","default","mappConf","undefined"],"sources":["../../src/mapper/index.js"],"sourcesContent":["import mapper from 'json-mapper-json';\n\nexport async function convert(prefix, data, event) {\n try {\n data.event = event || data.event;\n event = data.event.indexOf('message') >= 0 ? 'message' : data.event;\n\n let mappConfEvent = await config_event(prefix, event);\n let mappConfType = await config_type(prefix, event, data.type);\n\n Object.assign(mappConfEvent, mappConfType);\n\n // console.log('mappConfEvent', mappConfEvent);\n\n if (!mappConfEvent) return data;\n return await mapper(data, mappConfEvent);\n } catch (e) {\n return data;\n }\n}\n\nasync function config_event(prefix, event) {\n try {\n let { default: mappConf } = await import(`./${prefix}${event}.js`);\n if (!mappConf) return undefined;\n return mappConf;\n } catch (e) {\n return undefined;\n }\n}\n\nasync function config_type(prefix, event, type) {\n try {\n let { default: mappConf } = await import(`./${prefix}${event}-${type}.js`);\n if (!mappConf) return undefined;\n return mappConf;\n } catch (e) {\n return undefined;\n }\n}\n"],"mappings":"0LAAA,0EAAsC;;AAE/B,eAAeA,OAAO,CAACC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE;EACjD,IAAI;IACFD,IAAI,CAACC,KAAK,GAAGA,KAAK,IAAID,IAAI,CAACC,KAAK;IAChCA,KAAK,GAAGD,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,GAAGF,IAAI,CAACC,KAAK;;IAEnE,IAAIE,aAA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