Created
September 11, 2020 14:20
-
-
Save jps1st/7f7e92e6ad1768b98a673ef28c552d13 to your computer and use it in GitHub Desktop.
Example https usage for sending an sms using semaphore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
export async function sendSMS(message: string, number: string) { | |
const data = JSON.stringify({ | |
apikey: 'apikey', | |
number, | |
message, | |
sendername: 'ADCCPH' | |
}); | |
const options = { | |
hostname: 'api.semaphore.co', | |
port: 443, | |
path: '/api/v4/messages', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'Content-Length': data.length | |
} | |
}; | |
const req = https.request(options, (res) => { | |
console.log(`statusCode: ${res.statusCode}`); | |
res.on('data', (d) => { | |
process.stdout.write(d) | |
}) | |
}); | |
req.on('error', (error) => { | |
console.error(error) | |
}); | |
req.write(data); | |
req.end() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment