@andrey4emk/npm-app-back-b24 0.5.1 → 0.5.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 +1 -1
- package/sendMessage/chatApp.js +0 -4
- package/sendMessage/smsgold.js +57 -58
package/package.json
CHANGED
package/sendMessage/chatApp.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import dotEnv from "dotenv";
|
|
2
2
|
dotEnv.config();
|
|
3
3
|
|
|
4
|
-
const APP_ENV = process.env.APP_ENV;
|
|
5
|
-
const CHATAPP_EMAIL = process.env.CHATAPP_EMAIL;
|
|
6
|
-
const CHATAPP_APP_ID = process.env.CHATAPP_APP_ID;
|
|
7
|
-
|
|
8
4
|
export class ChatApp {
|
|
9
5
|
constructor(makeParam, authParam, typeParam) {
|
|
10
6
|
/**
|
package/sendMessage/smsgold.js
CHANGED
|
@@ -1,65 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
// import dotEnv from "dotenv";
|
|
1
|
+
import dotEnv from "dotenv";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
dotEnv.config();
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
class Smsgold {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.user = process.env.SMSGOLD_USER;
|
|
8
|
+
this.pass = process.env.SMSGOLD_PASS;
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
async sendSms(messageData) {
|
|
12
|
+
const { phone, message } = messageData;
|
|
13
|
+
// Проверяем наличие необходимых данных
|
|
14
|
+
if (!this.user || !this.pass) {
|
|
15
|
+
return { error: true, message: "Отсутствуют учетные данные SMSGold", result: null };
|
|
16
|
+
}
|
|
17
|
+
if (!phone || !message) {
|
|
18
|
+
return { error: true, message: "Отсутствуют номер телефона или текст сообщения", result: null };
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
let body = new URLSearchParams({
|
|
22
|
+
user: this.user,
|
|
23
|
+
pass: this.pass,
|
|
24
|
+
action: "send",
|
|
25
|
+
text: message,
|
|
26
|
+
number: phone,
|
|
27
|
+
sender: "potolkiRepa",
|
|
28
|
+
}).toString();
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
let result = await fetch("https://web.smsgold.ru/http2/", {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
34
|
+
},
|
|
35
|
+
body: body,
|
|
36
|
+
});
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
const errorText = await result.text();
|
|
40
|
+
let messageErr = {
|
|
41
|
+
status: result.status,
|
|
42
|
+
statusText: result.statusText,
|
|
43
|
+
errorText: errorText,
|
|
44
|
+
};
|
|
45
|
+
return { error: true, message: `API ошибка: ${result.status}`, result: messageErr };
|
|
46
|
+
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
const responseData = await result.text();
|
|
49
|
+
return {
|
|
50
|
+
error: false,
|
|
51
|
+
message: "SMS отправлено успешно",
|
|
52
|
+
result: {
|
|
53
|
+
status: result.status,
|
|
54
|
+
statusText: result.statusText,
|
|
55
|
+
data: responseData,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return { error: true, message: error.message, result: null };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
export const smsgold = new Smsgold();
|