-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (31 loc) · 1.05 KB
/
index.js
File metadata and controls
39 lines (31 loc) · 1.05 KB
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
//Require all the key dependencies that you will need for the app
const express = require("express");
const app = express();
//Define Africa's Talking stuff
const options = {
apiKey: 'YOUR_API_KEY_GOES_HERE', // use your sandbox app API key for development in the test environment
username: 'sandbox', // use 'sandbox' for development in the test environment
};
const AfricasTalking = require('africastalking')(options);
//Create the main express route that will be used
app.post("/", (req,res) => {
//Define the service needed (SMS)
const sms = AfricasTalking.SMS;
// all methods return a promise
const opts = {
to: '+2547XXXXXXXX',
from: 'YOUR_SHORT_CODE_GOES_HERE',
message: 'my reply',
}; //Configure options for message sending
sms.send(opts)
.then(function(success) {
console.log(success);
})
.catch(function(error) {
console.log(error);
}); //Actually send the message
});
//Start the server and have it listening on desired port
app.listen(3000, function() {
console.log("Started at localhost 3000");
});