-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnexmo.js
31 lines (26 loc) · 816 Bytes
/
nexmo.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
require("dotenv").config();
const NEXMO_API_KEY = process.env.NEXMO_API_KEY;
const NEXMO_API_SECRET = process.env.NEXMO_API_SECRET;
const TO_NUMBER = process.env.NEXMO_TO_NUMBER;
const NEXMO_BRAND_NAME = process.env.NEXMO_BRAND_NAME;
const Nexmo = require("nexmo");
const nexmo = new Nexmo({
apiKey: NEXMO_API_KEY,
apiSecret: NEXMO_API_SECRET,
});
const from = NEXMO_BRAND_NAME;
const to = TO_NUMBER;
const text = "A text message sent using the Nexmo SMS API";
nexmo.message.sendSms(from, to, text, (err, responseData) => {
if (err) {
console.log(err);
} else {
if (responseData.messages[0]["status"] === "0") {
console.log("Message sent successfully.");
} else {
console.log(
`Message failed with error: ${responseData.messages[0]["error-text"]}`
);
}
}
});