Skip to content

Instantly share code, notes, and snippets.

@jps1st
Created September 11, 2020 14:20
Show Gist options
  • Save jps1st/7f7e92e6ad1768b98a673ef28c552d13 to your computer and use it in GitHub Desktop.
Save jps1st/7f7e92e6ad1768b98a673ef28c552d13 to your computer and use it in GitHub Desktop.
Example https usage for sending an sms using semaphore
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