@andrey4emk/npm-app-back-b24 0.3.5 → 0.3.7
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/chatApp.js +31 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/chatApp.js
CHANGED
|
@@ -165,6 +165,37 @@ class ChatApp {
|
|
|
165
165
|
return { error: false, message: `Сообщение успешно отправлено в ChatApp через ${messangerType}`, data: null };
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
+
|
|
169
|
+
async phoneCheckChatApp(messangerType, phone) {
|
|
170
|
+
if (!["whatsApp"].includes(messangerType) && !["telegram"].includes(messangerType)) {
|
|
171
|
+
return { error: true, message: "Неверный тип мессенджера", data: null };
|
|
172
|
+
}
|
|
173
|
+
let check = await this.checkTokenChatApp();
|
|
174
|
+
if (check.error) {
|
|
175
|
+
return { error: true, message: `Ошибка с токеном ChatApp в функции phoneCheckChatApp класса ChatApp\n${check.message}`, data: null };
|
|
176
|
+
}
|
|
177
|
+
let url;
|
|
178
|
+
if (messangerType === "whatsApp") {
|
|
179
|
+
url = `https://api.chatapp.online/v1/licenses/${config.chatApp.type.whatsApp.licenseId}/messengers/${config.chatApp.type.whatsApp.messenger[0].type}/chats/${phone}/check`;
|
|
180
|
+
}
|
|
181
|
+
if (messangerType === "telegram") {
|
|
182
|
+
url = `https://api.chatapp.online/v1/licenses/${config.chatApp.type.telegram.licenseId}/messengers/${config.chatApp.type.telegram.messenger[0].type}/chats/${phone}/check`;
|
|
183
|
+
}
|
|
184
|
+
let res = await fetch(url, {
|
|
185
|
+
method: "GET",
|
|
186
|
+
headers: {
|
|
187
|
+
Lang: "en",
|
|
188
|
+
Accept: "application/json",
|
|
189
|
+
Authorization: this.accessToken,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
let data = await res.json();
|
|
193
|
+
if (!data.success) {
|
|
194
|
+
return { error: true, message: `Ошибка при проверке телефона в ChatApp через ${messangerType}`, data: null };
|
|
195
|
+
} else {
|
|
196
|
+
return { error: false, message: `Телефон успешно проверен в ChatApp через ${messangerType}`, data: data };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
168
199
|
}
|
|
169
200
|
|
|
170
201
|
export const chatApp = new ChatApp();
|
package/index.js
CHANGED