@andrey4emk/npm-app-back-b24 0.6.10 → 0.6.12
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 +1 -1
- package/sendMessage/wappi.js +30 -9
package/package.json
CHANGED
package/sendMessage/wappi.js
CHANGED
|
@@ -21,6 +21,7 @@ export class Wappi {
|
|
|
21
21
|
this.whatsAppAuth = whatsAppAuth;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// bot_id=1 нужно чтобы сообщение отображалось в открытой линии Битрикс24
|
|
24
25
|
async sendMessageWappi(messangerType, messageData) {
|
|
25
26
|
if (!["whatsApp"].includes(messangerType) && !["telegram"].includes(messangerType) && !["max"].includes(messangerType)) {
|
|
26
27
|
return { error: true, message: "Неверный тип мессенджера", data: null };
|
|
@@ -34,17 +35,19 @@ export class Wappi {
|
|
|
34
35
|
let token;
|
|
35
36
|
let profile_id;
|
|
36
37
|
if (messangerType === "whatsApp") {
|
|
37
|
-
|
|
38
|
+
token = this.whatsAppAuth.token;
|
|
39
|
+
profile_id = this.whatsAppAuth.profile_id;
|
|
40
|
+
url = `https://wappi.pro/api/async/message/send?bot_id=1&profile_id=${profile_id}`;
|
|
38
41
|
}
|
|
39
42
|
if (messangerType === "telegram") {
|
|
40
43
|
token = this.telegaAuth.token;
|
|
41
44
|
profile_id = this.telegaAuth.profile_id;
|
|
42
|
-
url = `https://wappi.pro/tapi/sync/message/send?profile_id=${profile_id}`;
|
|
45
|
+
url = `https://wappi.pro/tapi/sync/message/send?bot_id=1&profile_id=${profile_id}`;
|
|
43
46
|
}
|
|
44
47
|
if (messangerType === "max") {
|
|
45
48
|
token = this.maxAuth.token;
|
|
46
49
|
profile_id = this.maxAuth.profile_id;
|
|
47
|
-
url = `https://wappi.pro/maxapi/sync/message/send?profile_id=${profile_id}`;
|
|
50
|
+
url = `https://wappi.pro/maxapi/sync/message/send?bot_id=1&profile_id=${profile_id}`;
|
|
48
51
|
}
|
|
49
52
|
let res = await fetch(url, {
|
|
50
53
|
method: "POST",
|
|
@@ -86,7 +89,23 @@ export class Wappi {
|
|
|
86
89
|
let base64;
|
|
87
90
|
|
|
88
91
|
if (messangerType === "whatsApp") {
|
|
89
|
-
|
|
92
|
+
token = this.whatsAppAuth.token;
|
|
93
|
+
profile_id = this.whatsAppAuth.profile_id;
|
|
94
|
+
// скачивам файл и конвертируем в base64
|
|
95
|
+
let resConvert = await this.convertToBase64(fileUrl);
|
|
96
|
+
if (resConvert.error) {
|
|
97
|
+
return { error: true, message: `Ошибка при конвертации файла в base64 для WhatsApp: ${resConvert.message}`, data: null };
|
|
98
|
+
} else {
|
|
99
|
+
base64 = resConvert.data;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (fileName.includes(".pdf")) {
|
|
103
|
+
url = `https://wappi.pro/api/async/message/document/send?bot_id=1&profile_id=${profile_id}`;
|
|
104
|
+
}
|
|
105
|
+
// Если отправили картинку .png, .jpg и т.д.
|
|
106
|
+
if (fileName.includes(".png") || fileName.includes(".jpg") || fileName.includes(".jpeg") || fileName.includes(".gif")) {
|
|
107
|
+
url = `https://wappi.pro/api/async/message/img/send?bot_id=1&profile_id=${profile_id}`;
|
|
108
|
+
}
|
|
90
109
|
}
|
|
91
110
|
if (messangerType === "telegram") {
|
|
92
111
|
token = this.telegaAuth.token;
|
|
@@ -100,17 +119,17 @@ export class Wappi {
|
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
if (fileName.includes(".pdf")) {
|
|
103
|
-
url = `https://wappi.pro/tapi/sync/message/document/send?profile_id=${profile_id}`;
|
|
122
|
+
url = `https://wappi.pro/tapi/sync/message/document/send?bot_id=1&profile_id=${profile_id}`;
|
|
104
123
|
}
|
|
105
124
|
// Если отправили картинку .png, .jpg и т.д.
|
|
106
|
-
if (fileName.includes(".png" || ".jpg" || ".jpeg" || ".gif")) {
|
|
107
|
-
url = `https://wappi.pro/tapi/sync/message/img/send?profile_id=${profile_id}`;
|
|
125
|
+
if (fileName.includes(".png") || fileName.includes(".jpg") || fileName.includes(".jpeg") || fileName.includes(".gif")) {
|
|
126
|
+
url = `https://wappi.pro/tapi/sync/message/img/send?bot_id=1&profile_id=${profile_id}`;
|
|
108
127
|
}
|
|
109
128
|
}
|
|
110
129
|
if (messangerType === "max") {
|
|
111
130
|
token = this.maxAuth.token;
|
|
112
131
|
profile_id = this.maxAuth.profile_id;
|
|
113
|
-
url = `https://wappi.pro/maxapi/async/message/file/url/send?profile_id=${profile_id}`;
|
|
132
|
+
url = `https://wappi.pro/maxapi/async/message/file/url/send?bot_id=1&profile_id=${profile_id}`;
|
|
114
133
|
}
|
|
115
134
|
|
|
116
135
|
// Max при отправке pdf не прикрепляет сообщение caption: message, поэтому отправляем его отдельно
|
|
@@ -152,7 +171,9 @@ export class Wappi {
|
|
|
152
171
|
let token;
|
|
153
172
|
let profile_id;
|
|
154
173
|
if (messangerType === "whatsApp") {
|
|
155
|
-
|
|
174
|
+
token = this.whatsAppAuth.token;
|
|
175
|
+
profile_id = this.whatsAppAuth.profile_id;
|
|
176
|
+
url = `https://wappi.pro/api/sync/contact/check?profile_id=${profile_id}&phone=${phone}`;
|
|
156
177
|
}
|
|
157
178
|
if (messangerType === "telegram") {
|
|
158
179
|
// 1 Проверяем существует контакт или нет.
|