aeremmiddleware 1.0.2 → 1.0.4
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/README.md +29 -0
- package/dist/Finance/idfy.d.ts +35 -35
- package/dist/Finance/idfy.js +201 -201
- package/dist/Finance/index.d.ts +4 -4
- package/dist/Finance/index.js +10 -10
- package/dist/Maps/index.js +1 -1
- package/dist/Socials/Whatsapp.types.d.ts +97 -97
- package/dist/Socials/Whatsapp.types.js +8 -8
- package/dist/Socials/index.d.ts +4 -4
- package/dist/Socials/index.js +10 -10
- package/dist/Socials/message.d.ts +26 -26
- package/dist/Socials/message.js +211 -211
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/package.json +20 -17
- package/src/Finance/Ingenico.types.ts +18 -0
- package/src/Finance/encrypt.ts +18 -0
- package/src/Finance/idfy.ts +528 -205
- package/src/Finance/index.ts +7 -5
- package/src/Finance/ingenico.ts +210 -0
- package/src/Finance/novel.ts +226 -0
- package/src/Finance/novel.types.ts +24 -0
- package/src/Socials/Sms.types.ts +9 -0
- package/src/Socials/SmsSender.ts +79 -0
- package/src/Socials/Whatsapp.types.ts +95 -98
- package/src/Socials/index.ts +6 -5
- package/src/Socials/{message.ts → whatsApp.ts} +188 -236
- package/src/index.ts +7 -7
- package/tsconfig.json +111 -111
package/src/Finance/index.ts
CHANGED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { createSHA512Hash } from "./encrypt";
|
|
3
|
+
|
|
4
|
+
class IngenicoApiWrapper {
|
|
5
|
+
private verificationUrl = "https://www.paynimo.com/api/paynimoV2.req";
|
|
6
|
+
private salt = "3970170229YUYEWB";
|
|
7
|
+
|
|
8
|
+
async startMandate(data: any): Promise<any> {
|
|
9
|
+
const obj = {
|
|
10
|
+
merchantId: "T656995", //data.merchantId
|
|
11
|
+
txnId: "16949471459696",
|
|
12
|
+
totalamount: "2",
|
|
13
|
+
accountNo: "203209528180",
|
|
14
|
+
consumerId: "c964635",
|
|
15
|
+
consumerMobileNo: "8823809696",
|
|
16
|
+
consumerEmailId: "saransh2196@gmail.com",
|
|
17
|
+
debitStartDate: "29-09-2023",
|
|
18
|
+
debitEndDate: "10-05-2025",
|
|
19
|
+
maxAmount: "20000",
|
|
20
|
+
amountType: "M",
|
|
21
|
+
frequency: "ADHO",
|
|
22
|
+
cardNumber: "",
|
|
23
|
+
expMonth: "",
|
|
24
|
+
expYear: "",
|
|
25
|
+
cvvCode: "",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const tokenId = createSHA512Hash(obj, this.salt);
|
|
29
|
+
console.log(tokenId);
|
|
30
|
+
return `<!DOCTYPE html>
|
|
31
|
+
<html>
|
|
32
|
+
<head>
|
|
33
|
+
<title>Checkout Demo</title>
|
|
34
|
+
<meta name="viewport" content="user-scalable=no, width=device-width,
|
|
35
|
+
initial-scale=1" / />
|
|
36
|
+
<script
|
|
37
|
+
src="https://www.paynimo.com/paynimocheckout/client/lib/jquery.min.js"
|
|
38
|
+
type="text/javascript"
|
|
39
|
+
></script>
|
|
40
|
+
</head>
|
|
41
|
+
|
|
42
|
+
<body>
|
|
43
|
+
<button id="btnSubmit">Register Now</button>
|
|
44
|
+
|
|
45
|
+
<script
|
|
46
|
+
type="text/javascript"
|
|
47
|
+
src="https://www.paynimo.com/paynimocheckout/server/lib/checkout.js"
|
|
48
|
+
></script>
|
|
49
|
+
|
|
50
|
+
<script type="text/javascript">
|
|
51
|
+
$(document).ready(function () {
|
|
52
|
+
function handleResponse(res) {
|
|
53
|
+
if (
|
|
54
|
+
typeof res != "undefined" &&
|
|
55
|
+
typeof res.paymentMethod != "undefined" &&
|
|
56
|
+
typeof res.paymentMethod.paymentTransaction != "undefined" &&
|
|
57
|
+
typeof res.paymentMethod.paymentTransaction.statusCode !=
|
|
58
|
+
"undefined" &&
|
|
59
|
+
res.paymentMethod.paymentTransaction.statusCode == "0300"
|
|
60
|
+
) {
|
|
61
|
+
// success block
|
|
62
|
+
console.log("success block",res);
|
|
63
|
+
} else if (
|
|
64
|
+
typeof res != "undefined" &&
|
|
65
|
+
typeof res.paymentMethod != "undefined" &&
|
|
66
|
+
typeof res.paymentMethod.paymentTransaction != "undefined" &&
|
|
67
|
+
typeof res.paymentMethod.paymentTransaction.statusCode !=
|
|
68
|
+
"undefined" &&
|
|
69
|
+
res.paymentMethod.paymentTransaction.statusCode == "0398"
|
|
70
|
+
) {
|
|
71
|
+
// initiated block
|
|
72
|
+
console.log("initiate block",res);
|
|
73
|
+
} else {
|
|
74
|
+
// error block
|
|
75
|
+
console.log("error block",res);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
$(document)
|
|
80
|
+
.off("click", "#btnSubmit")
|
|
81
|
+
.on("click", "#btnSubmit", function (e) {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
|
|
84
|
+
var reqJson = {
|
|
85
|
+
features: {
|
|
86
|
+
enableAbortResponse: true,
|
|
87
|
+
enableNewWindowFlow: true, //for hybrid applications please disable this by passing false
|
|
88
|
+
enableExpressPay: true,
|
|
89
|
+
enableMerTxnDetails: true,
|
|
90
|
+
siDetailsAtMerchantEnd: true,
|
|
91
|
+
enableSI: true,
|
|
92
|
+
},
|
|
93
|
+
consumerData: {
|
|
94
|
+
deviceId: "WEBSH2",
|
|
95
|
+
token:"${tokenId}",
|
|
96
|
+
returnUrl:
|
|
97
|
+
"https://aerem.co/", //merchant response page URL
|
|
98
|
+
responseHandler: handleResponse,
|
|
99
|
+
paymentMode: "netBanking",
|
|
100
|
+
merchantLogoUrl:
|
|
101
|
+
"https://www.paynimo.com/CompanyDocs/company-logo-vertical.png", //provided merchant logo will be displayed
|
|
102
|
+
merchantId: "T656995",
|
|
103
|
+
currency: "INR",
|
|
104
|
+
consumerId: "c964635", //Your unique consumer identifier to register a eMandate/eNACH
|
|
105
|
+
consumerMobileNo: "8823809696",
|
|
106
|
+
consumerEmailId: "saransh2196@gmail.com",
|
|
107
|
+
txnId: "16949471459696", //Unique merchant transaction ID
|
|
108
|
+
|
|
109
|
+
items: [
|
|
110
|
+
{
|
|
111
|
+
itemId: "FIRST",
|
|
112
|
+
amount: "2",
|
|
113
|
+
comAmt: "0",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
customStyle: {
|
|
117
|
+
PRIMARY_COLOR_CODE: "#45beaa", //merchant primary color code
|
|
118
|
+
SECONDARY_COLOR_CODE: "#FFFFFF", //provide merchant's suitable color code
|
|
119
|
+
BUTTON_COLOR_CODE_1: "#2d8c8c", //merchant's button background color code
|
|
120
|
+
BUTTON_COLOR_CODE_2: "#FFFFFF", //provide merchant's suitable color code for button text
|
|
121
|
+
},
|
|
122
|
+
accountNo: "203209528180", //Pass this if accountNo is captured at merchant side for eMandate/eNACH
|
|
123
|
+
|
|
124
|
+
ifscCode: "SBIN0000441", //Pass this if ifscCode is captured at merchant side.
|
|
125
|
+
accountType: "Saving", //Required for eNACH registration this is mandatory field
|
|
126
|
+
debitStartDate: "29-09-2023",
|
|
127
|
+
debitEndDate: "10-05-2025",
|
|
128
|
+
maxAmount: "20000",
|
|
129
|
+
amountType: "M",
|
|
130
|
+
frequency: "ADHO",
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
$.pnCheckout(reqJson);
|
|
135
|
+
if (reqJson.features.enableNewWindowFlow) {
|
|
136
|
+
pnCheckoutShared.openNewWindow();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
</script>
|
|
141
|
+
</body>
|
|
142
|
+
</html>
|
|
143
|
+
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public inputString =
|
|
148
|
+
"T656995|16949471459696|2|203209528180|c964635|8823809696|saransh2196@gmail.com|10-03-2019|10-05-2022|20000|M|ADHO|7412191510887498|09|2028|123|3970170229YUYEWB";
|
|
149
|
+
|
|
150
|
+
async dualVerification(inputString: any): Promise<any> {
|
|
151
|
+
const dataArray = inputString.split("|");
|
|
152
|
+
dataArray[dataArray.length - 1] = this.salt;
|
|
153
|
+
const modifiedString = dataArray.join("|");
|
|
154
|
+
|
|
155
|
+
if (inputString === modifiedString) {
|
|
156
|
+
return true;
|
|
157
|
+
} else {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async mandateVerification(requestData: any): Promise<any> {
|
|
163
|
+
try {
|
|
164
|
+
const response = await axios.post(this.verificationUrl, requestData, {
|
|
165
|
+
headers: {
|
|
166
|
+
"Content-Type": "application/json",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const responseData = response.data;
|
|
171
|
+
|
|
172
|
+
console.log(responseData);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("Error:", error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async transactionScheduling(requestData: any): Promise<any> {
|
|
179
|
+
try {
|
|
180
|
+
const response = await axios.post(this.verificationUrl, requestData, {
|
|
181
|
+
headers: {
|
|
182
|
+
"Content-Type": "application/json",
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const responseData = response.data;
|
|
187
|
+
|
|
188
|
+
console.log(responseData);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error("Error:", error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async transactionVerification(requestData: any): Promise<any> {
|
|
194
|
+
try {
|
|
195
|
+
const response = await axios.post(this.verificationUrl, requestData, {
|
|
196
|
+
headers: {
|
|
197
|
+
"Content-Type": "application/json",
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const responseData = response.data;
|
|
202
|
+
|
|
203
|
+
console.log(responseData);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error("Error:", error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default IngenicoApiWrapper;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import FormData from "form-data";
|
|
3
|
+
import { CustomerDetails, StatusType, ContentType } from "./novel.types";
|
|
4
|
+
|
|
5
|
+
class NovelApiWrapper {
|
|
6
|
+
private authToken: string;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.authToken = "API://nvsMy/H/ENzvot3m621Jz/a5modqxYm4RPOkFIwrIKM=";
|
|
10
|
+
}
|
|
11
|
+
private baseApiUrl = "https://cartbi.com/api/";
|
|
12
|
+
private uploadEndpoint = "upload";
|
|
13
|
+
private downloadExcelEndpoint = "downloadFileAsExcel";
|
|
14
|
+
private downloadJsonEndpoint = "downloadFile";
|
|
15
|
+
private autoFetchEndpoint = "generateNetBankingRequest";
|
|
16
|
+
|
|
17
|
+
async uploadDocument(
|
|
18
|
+
file: Buffer,
|
|
19
|
+
filename: string,
|
|
20
|
+
metadata: any,
|
|
21
|
+
documentDetails: any[]
|
|
22
|
+
) {
|
|
23
|
+
try {
|
|
24
|
+
const form = new FormData();
|
|
25
|
+
|
|
26
|
+
form.append("file", file, { filename });
|
|
27
|
+
|
|
28
|
+
form.append("metadata", metadata);
|
|
29
|
+
|
|
30
|
+
form.append("documentDetails", JSON.stringify(documentDetails));
|
|
31
|
+
|
|
32
|
+
const headers = {
|
|
33
|
+
...form.getHeaders(),
|
|
34
|
+
"auth-token": this.authToken,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const response = await axios.post(
|
|
38
|
+
this.baseApiUrl + this.uploadEndpoint,
|
|
39
|
+
form,
|
|
40
|
+
{
|
|
41
|
+
headers,
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
if (response.status === 200) {
|
|
45
|
+
console.log(response.data.docId, "Document uploaded successfully");
|
|
46
|
+
console.log("Response:", response.data);
|
|
47
|
+
} else {
|
|
48
|
+
console.error("Failed to upload document");
|
|
49
|
+
console.error("Response:", response.data);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return response.data;
|
|
53
|
+
} catch (error: any) {
|
|
54
|
+
console.error("Error:", error.message);
|
|
55
|
+
return error.message;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
private async downloadAsExcel(docId: string): Promise<Buffer> {
|
|
59
|
+
try {
|
|
60
|
+
const headers = {
|
|
61
|
+
"auth-token": this.authToken,
|
|
62
|
+
"Content-Type": ContentType.TEXT,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const response = await axios.post(
|
|
66
|
+
this.baseApiUrl + this.downloadExcelEndpoint,
|
|
67
|
+
docId,
|
|
68
|
+
{ headers, responseType: "arraybuffer" }
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (response.status === 200) {
|
|
72
|
+
console.log("File downloaded successfully");
|
|
73
|
+
return Buffer.from(response.data, "binary");
|
|
74
|
+
} else {
|
|
75
|
+
console.error("Failed to download file");
|
|
76
|
+
return Buffer.from([]);
|
|
77
|
+
}
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
console.error("Error:", error.message);
|
|
80
|
+
return Buffer.from([]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private async downloadAsJSON(docId: string): Promise<any> {
|
|
85
|
+
try {
|
|
86
|
+
const headers = {
|
|
87
|
+
"auth-token": this.authToken,
|
|
88
|
+
"Content-Type": ContentType.TEXT,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const response = await axios.post(
|
|
92
|
+
this.baseApiUrl + this.downloadJsonEndpoint,
|
|
93
|
+
docId,
|
|
94
|
+
{ headers }
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
if (response.data.error == false) {
|
|
98
|
+
console.log("File downloaded successfully");
|
|
99
|
+
console.log(response.data);
|
|
100
|
+
return response.data;
|
|
101
|
+
} else {
|
|
102
|
+
console.error("Failed to download file");
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
} catch (error: any) {
|
|
106
|
+
console.error("Error:", error.message);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
private async generateAutoFetchURL(obj: CustomerDetails): Promise<any> {
|
|
111
|
+
try {
|
|
112
|
+
const headers = {
|
|
113
|
+
"auth-token": this.authToken,
|
|
114
|
+
"Content-Type": ContentType.JSON,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const response = await axios.post(
|
|
118
|
+
this.baseApiUrl + this.autoFetchEndpoint,
|
|
119
|
+
obj,
|
|
120
|
+
{ headers }
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (response.status == 200) {
|
|
124
|
+
console.log("File downloaded successfully");
|
|
125
|
+
console.log(response.data);
|
|
126
|
+
return response.data;
|
|
127
|
+
} else {
|
|
128
|
+
console.error("Failed to download file");
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
} catch (error: any) {
|
|
132
|
+
console.error("Error:", error.message);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async novelPatternCallback(status: StatusType) {
|
|
138
|
+
return this.downloadAsJSON(status.docId);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async uploadBankStatement(
|
|
142
|
+
file: Buffer,
|
|
143
|
+
filename: string,
|
|
144
|
+
metadata: any,
|
|
145
|
+
documentDetails: any[]
|
|
146
|
+
): Promise<any> {
|
|
147
|
+
return this.uploadDocument(file, filename, metadata, documentDetails);
|
|
148
|
+
}
|
|
149
|
+
async uploadItr(
|
|
150
|
+
file: Buffer,
|
|
151
|
+
filename: string,
|
|
152
|
+
metadata: any,
|
|
153
|
+
documentDetails: any[]
|
|
154
|
+
): Promise<any> {
|
|
155
|
+
return this.uploadDocument(file, filename, metadata, documentDetails);
|
|
156
|
+
}
|
|
157
|
+
async uploadPnL(
|
|
158
|
+
file: Buffer,
|
|
159
|
+
filename: string,
|
|
160
|
+
metadata: any,
|
|
161
|
+
documentDetails: any[]
|
|
162
|
+
): Promise<any> {
|
|
163
|
+
return this.uploadDocument(file, filename, metadata, documentDetails);
|
|
164
|
+
}
|
|
165
|
+
async uploadGSTr(
|
|
166
|
+
file: Buffer,
|
|
167
|
+
filename: string,
|
|
168
|
+
metadata: any,
|
|
169
|
+
documentDetails: any[]
|
|
170
|
+
): Promise<any> {
|
|
171
|
+
return this.uploadDocument(file, filename, metadata, documentDetails);
|
|
172
|
+
}
|
|
173
|
+
async uploadGST3b(
|
|
174
|
+
file: Buffer,
|
|
175
|
+
filename: string,
|
|
176
|
+
metadata: any,
|
|
177
|
+
documentDetails: any[]
|
|
178
|
+
): Promise<any> {
|
|
179
|
+
return this.uploadDocument(file, filename, metadata, documentDetails);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async downloadItrAsJson(docId: string): Promise<any> {
|
|
183
|
+
return this.downloadAsJSON(docId);
|
|
184
|
+
}
|
|
185
|
+
async downloadBankStatementAsJson(docId: string): Promise<any> {
|
|
186
|
+
return this.downloadAsJSON(docId);
|
|
187
|
+
}
|
|
188
|
+
async downloadPnLAsJson(docId: string): Promise<any> {
|
|
189
|
+
return this.downloadAsJSON(docId);
|
|
190
|
+
}
|
|
191
|
+
async downloadGSTrAsJson(docId: string): Promise<any> {
|
|
192
|
+
return this.downloadAsJSON(docId);
|
|
193
|
+
}
|
|
194
|
+
async downloadGst3bAsJson(docId: string): Promise<any> {
|
|
195
|
+
return this.downloadAsJSON(docId);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async downloadItrAsExcel(docId: string): Promise<any> {
|
|
199
|
+
return this.downloadAsExcel(docId);
|
|
200
|
+
}
|
|
201
|
+
async downloadBankStatementAsExcel(docId: string): Promise<any> {
|
|
202
|
+
return this.downloadAsExcel(docId);
|
|
203
|
+
}
|
|
204
|
+
async downloadGst3bAsExcel(docId: string): Promise<any> {
|
|
205
|
+
return this.downloadAsExcel(docId);
|
|
206
|
+
}
|
|
207
|
+
async downloadPnLAsExcel(docId: string): Promise<any> {
|
|
208
|
+
return this.downloadAsExcel(docId);
|
|
209
|
+
}
|
|
210
|
+
async downloadGSTrAsExcel(docId: string): Promise<any> {
|
|
211
|
+
return this.downloadAsExcel(docId);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async getGstrDetailsAutoFetch(obj: CustomerDetails): Promise<any> {
|
|
215
|
+
return this.generateAutoFetchURL(obj);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async getItrvDetailsAutoFetch(obj: CustomerDetails): Promise<any> {
|
|
219
|
+
return this.generateAutoFetchURL(obj);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async getBankDetailsAutoFetch(obj: CustomerDetails): Promise<any> {
|
|
223
|
+
return this.generateAutoFetchURL(obj);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export default NovelApiWrapper;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface CustomerDetails {
|
|
2
|
+
fileNo?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
contactNo: string;
|
|
5
|
+
organizationName?: string;
|
|
6
|
+
bank?: string;
|
|
7
|
+
accountType: string;
|
|
8
|
+
defaultScreen?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface StatusType {
|
|
11
|
+
docId: string;
|
|
12
|
+
requestId: string;
|
|
13
|
+
status: string;
|
|
14
|
+
reportFileName: string;
|
|
15
|
+
endTime: string;
|
|
16
|
+
message: string;
|
|
17
|
+
fileNo: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum ContentType {
|
|
21
|
+
TEXT = "text/plain",
|
|
22
|
+
FORM = "multipart/form-data",
|
|
23
|
+
JSON = "application/json",
|
|
24
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { DemoBody, Provider } from "./Sms.types";
|
|
3
|
+
|
|
4
|
+
class SmsSender {
|
|
5
|
+
private exotelSid: string;
|
|
6
|
+
private exotelToken: string;
|
|
7
|
+
private exotelApiKey: string;
|
|
8
|
+
private smsUrl!: string;
|
|
9
|
+
private provider: string;
|
|
10
|
+
|
|
11
|
+
constructor(payload: {
|
|
12
|
+
exotelSid: string;
|
|
13
|
+
exotelToken: string;
|
|
14
|
+
exotelApiKey: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
}) {
|
|
17
|
+
const { exotelSid, exotelToken, exotelApiKey, provider } = payload;
|
|
18
|
+
this.exotelSid = exotelSid;
|
|
19
|
+
this.exotelToken = exotelToken;
|
|
20
|
+
this.exotelApiKey = exotelApiKey;
|
|
21
|
+
this.provider = provider;
|
|
22
|
+
|
|
23
|
+
if (this.provider === Provider.EXOTEL) {
|
|
24
|
+
this.smsUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v1/Accounts/${exotelSid}/Sms/send`;
|
|
25
|
+
} else if (this.provider === Provider.GUPSHUP) {
|
|
26
|
+
// Define the URL for Gupshup API
|
|
27
|
+
// this.gupshupApiUrl = ...;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private async sendOtpMessage(messageData: DemoBody): Promise<boolean> {
|
|
32
|
+
|
|
33
|
+
if(messageData.To && messageData.Body ){
|
|
34
|
+
|
|
35
|
+
if(messageData.Body.length != 6){
|
|
36
|
+
throw new Error("Please enter 6 digit number")
|
|
37
|
+
}
|
|
38
|
+
} else throw new Error("All input data not found")
|
|
39
|
+
|
|
40
|
+
const bodyFormData=new FormData();
|
|
41
|
+
|
|
42
|
+
const smsTemplateMsg="Your OTP for AEREMS login is %d. This %d will expire in 10 minutes."
|
|
43
|
+
|
|
44
|
+
bodyFormData.append("To",messageData.To)
|
|
45
|
+
bodyFormData.append("From","AEREM")
|
|
46
|
+
bodyFormData.append("Body",smsTemplateMsg.replace(/%d/g,messageData.Body))
|
|
47
|
+
bodyFormData.append("EncodingType","plain")
|
|
48
|
+
bodyFormData.append("DltEntityId","1301164059765333889")
|
|
49
|
+
bodyFormData.append("DltTemplateId","1307164663997173809")
|
|
50
|
+
bodyFormData.append("SmsType","transactional")
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
let config = {
|
|
54
|
+
method: "post",
|
|
55
|
+
maxBodyLength: Infinity,
|
|
56
|
+
url: this.smsUrl,
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "multipart/form-data",
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
data: bodyFormData,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
await axios.request(config);
|
|
65
|
+
return true;
|
|
66
|
+
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Error sending sms:", error);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async sendOtpSms(obj: DemoBody): Promise<boolean> {
|
|
74
|
+
return this.sendOtpMessage(obj);
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
export default SmsSender;
|