@andrey4emk/npm-app-back-b24 0.6.0 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrey4emk/npm-app-back-b24",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Bitrix24 OAuth helpers for Node.js projects",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,9 +15,10 @@
15
15
  */
16
16
 
17
17
  export class Wappi {
18
- constructor(tokenParam, profileIdParam) {
19
- this.token = tokenParam;
20
- this.profile_id = profileIdParam;
18
+ constructor(maxAuth, telegaAuth, whatsAppAuth) {
19
+ this.maxAuth = maxAuth;
20
+ this.telegaAuth = telegaAuth;
21
+ this.whatsAppAuth = whatsAppAuth;
21
22
  }
22
23
 
23
24
  async sendMessageWappi(messangerType, messageData) {
@@ -30,6 +31,8 @@ export class Wappi {
30
31
  let phone = messageData.phone;
31
32
  let message = messageData.message;
32
33
  let url;
34
+ let token;
35
+ let profile_id;
33
36
  if (messangerType === "whatsApp") {
34
37
  url = ``;
35
38
  }
@@ -38,12 +41,14 @@ export class Wappi {
38
41
  }
39
42
  if (messangerType === "max") {
40
43
  url = `https://wappi.pro/maxapi/sync/message/send`;
44
+ token = this.maxAuth.token;
45
+ profile_id = this.maxAuth.profile_id;
41
46
  }
42
- let res = await fetch(url + `?profile_id=${this.profile_id}`, {
47
+ let res = await fetch(url + `?profile_id=${profile_id}`, {
43
48
  method: "POST",
44
49
  headers: {
45
50
  "Content-Type": "application/json",
46
- Authorization: this.token,
51
+ Authorization: token,
47
52
  },
48
53
 
49
54
  body: JSON.stringify({
@@ -71,6 +76,8 @@ export class Wappi {
71
76
  let fileUrl = messageData.fileUrl;
72
77
  let fileName = messageData.fileName;
73
78
  let url;
79
+ let token;
80
+ let profile_id;
74
81
  if (messangerType === "whatsApp") {
75
82
  url = ``;
76
83
  }
@@ -79,17 +86,19 @@ export class Wappi {
79
86
  }
80
87
  if (messangerType === "max") {
81
88
  url = `https://wappi.pro/maxapi/async/message/file/url/send`;
89
+ token = this.maxAuth.token;
90
+ profile_id = this.maxAuth.profile_id;
82
91
  }
83
92
 
84
93
  // Max при отправке pdf не прикрепляет сообщение caption: message, поэтому отправляем его отдельно
85
94
  if (fileName.includes(".pdf")) {
86
95
  await this.sendMessageWappi(messangerType, { phone: phone, message: message });
87
96
  }
88
- let res = await fetch(url + `?profile_id=${this.profile_id}`, {
97
+ let res = await fetch(url + `?profile_id=${profile_id}`, {
89
98
  method: "POST",
90
99
  headers: {
91
100
  "Content-Type": "application/json",
92
- Authorization: this.token,
101
+ Authorization: token,
93
102
  },
94
103
 
95
104
  body: JSON.stringify({
@@ -115,6 +124,8 @@ export class Wappi {
115
124
  return { error: true, message: "Отсутствует phone ", data: null };
116
125
  }
117
126
  let url;
127
+ let token;
128
+ let profile_id;
118
129
  if (messangerType === "whatsApp") {
119
130
  url = ``;
120
131
  }
@@ -141,13 +152,15 @@ export class Wappi {
141
152
  }
142
153
  }
143
154
  if (messangerType === "max") {
144
- url = `https://wappi.pro/maxapi/sync/contact/check?profile_id=${this.profile_id}&phone=${phone}`;
155
+ token = this.maxAuth.token;
156
+ profile_id = this.maxAuth.profile_id;
157
+ url = `https://wappi.pro/maxapi/sync/contact/check?profile_id=${profile_id}&phone=${phone}`;
145
158
  }
146
159
  let res = await fetch(url, {
147
160
  method: "GET",
148
161
  headers: {
149
162
  "Content-Type": "application/json",
150
- Authorization: this.token,
163
+ Authorization: token,
151
164
  },
152
165
  });
153
166
  let data = await res.json();
@@ -166,15 +179,16 @@ export class Wappi {
166
179
  if (!phone) {
167
180
  return { error: true, message: "Отсутствует phone", data: null };
168
181
  }
169
-
170
- let url = `https://wappi.pro/tapi/sync/contact/get?profile_id=${this.profile_id}&phone=${phone}`;
182
+ let token = this.telegaAuth.token;
183
+ let profile_id = this.telegaAuth.profile_id;
184
+ let url = `https://wappi.pro/tapi/sync/contact/get?profile_id=${profile_id}&phone=${phone}`;
171
185
 
172
186
  try {
173
187
  let res = await fetch(url, {
174
188
  method: "GET",
175
189
  headers: {
176
190
  "Content-Type": "application/json",
177
- Authorization: this.token,
191
+ Authorization: token,
178
192
  },
179
193
  });
180
194
 
@@ -202,14 +216,17 @@ export class Wappi {
202
216
  const randomString = Math.random().toString(36).substring(2, 6).toUpperCase();
203
217
  const contactName = `${phone}_${randomString}`;
204
218
 
205
- let url = `https://wappi.pro/tapi/sync/contact/add?profile_id=${this.profile_id}`;
219
+ let token = this.telegaAuth.token;
220
+ let profile_id = this.telegaAuth.profile_id;
221
+ let url = `https://wappi.pro/tapi/sync/contact/add`;
206
222
 
207
223
  try {
208
224
  let res = await fetch(url, {
209
225
  method: "POST",
210
226
  headers: {
211
227
  "Content-Type": "application/json",
212
- Authorization: this.token,
228
+ Authorization: token,
229
+ profile_id: profile_id,
213
230
  },
214
231
  body: JSON.stringify({
215
232
  phone: phone,