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