-
Notifications
You must be signed in to change notification settings - Fork 2
/
samples.js
127 lines (114 loc) · 5.18 KB
/
samples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const TrezSMSClient = require("./Trez"); // Or simply `require("trez-sms-client")`, if you have installed from NPM
const username = "09398219817";
const password = "09398219817";
const client = new TrezSMSClient(username, password);
const sender = "30008632100000";
const receiver = "5000248889";
const groupId = client.getRandomGroupId();
// ========== OTP Mobile Authentication ============
// Send a random code automatically to a mobile number
// client.autoSendCode("09362884570", "Signiture Footer For Branding")
// .then((messageId) => {
// console.log("Sent Message ID: " + messageId);
// })
// .catch(error => console.log(error));
// Validate a code which was sent to a number by autoSendCode
// client.checkCode("09301234567", "595783")
// .then((isValid) => {
// if (isValid) {
// console.log("Code 595783 for this number 09301234567 is valid and verified.");
// }
// else {
// console.log("Provided code for that number is not valid!");
// }
// })
// .catch(error => console.log(error));
// // Send a code manually to a mobile number
// client.manualSendCode("09362884570", "595783")
// .then((messageId) => {
// console.log("Sent Message ID: " + messageId);
// })
// .catch(error => console.log(error));
// // ======== END OTP Method Examples ===========
// // Sending a message to a number or a list of numbers
// client.sendMessage(sender, ["09362884570"], "Hello World!", groupId)
// .then((receipt) => {
// console.log(groupId);
// console.log("Receipt: " + receipt);
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });
// // Sending corresponding (batch) message to a list of recipients
// // It sends a bunch of messages withing an API Call
const recipients = [
client.createRecipientObject("11445559", "09362884570", "This is a message"), // ID, Mobile Number, Message
client.createRecipientObject("99854750", "09309512717", "This is another message"),
];
client.sendBatchMessage("50002210003000", recipients, groupId)
.then((result) => {
console.log(result); // [{"Id":11445599,"Mobile":"09123456789","Result":2000}, {"Id":99854710,"Mobile":"09301234567","Result":2001}]
})
.catch((error) => {
// If there is an error, we'll catch that
console.log(error.isHttpException, error.code, error.message);
});
// // Getting the previously sent message status
// client.messageStatus("870832346")
// .then((result) => {
// console.log(result);
// // console.log(result.received, result.status, result.message, result.number);
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });
// // Getting the previously sent batch message status
// client.batchMessageStatus(["11445599", "99854710"]) // recipients' ID
// .then((result) => {
// console.log(result.received, result.status, result.message, result.number);
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });
// // Getting the list of received messages
// const from = 1557695398; // from date in timestamp
// const to = 1557868230; // till date in timestamp
// const page = 1;
// client.receivedMessages(receiver, from, to, page)
// .then((result) => {
// console.log(result.totalPages, result.currentPage, result.messages); // 10, 1, [{from: 09381234567, date: 1557695511, message: 'سلام'}]
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });
// // Getting the account credit
// client.accountCredit()
// .then((credit) => {
// console.log(credit + " Rials"); // 500000 Rials
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });
// // Getting the SMS prices (Fa and En)
// client.prices()
// .then((prices) => {
// console.log("Farsi: " + prices.fa + " Rials, English: " + prices.en + " Rials"); // Farsi: 129 Rials, English: 295 Rials
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });
// // Check white numbers (those are not in the Black List will be returned)
// client.checkBlackList([09123456789, 09301234567, 0911234567])
// .then((whiteNumbers) => {
// console.log(whiteNumbers); // [09123456789, 0911234567]
// })
// .catch((error) => {
// // If there is an error, we'll catch that
// console.log(error.isHttpException, error.code, error.message);
// });